mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
I am trying to make a chat bot for a channel, and i already have simple on-text commands, caps block, and link block. I want to get into writing sockets that the bot can use for stuff like following someone that says !follow or change the current game using the kraken API.
I have no experience with sockets or how to use them. I would like to start with the follow a user thing. I wonder how i would use this:
Code:
 curl -H 'Accept: application/vnd.twitchtv.v3+json' -H 'Authorization: OAuth <access_token>' \
-X PUT https://api.twitch.tv/kraken/users/ [ my bot ] /follows/channels/ [ who it should follow ] 

Thanks for help.


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
If you have not done so already, register an application here: http://www.twitch.tv/settings/connections, for your redirect url use http://localhost/, you will need your client id to request an oath token (which this script can retrieve by itself). Utilize the right click menu (from your channel) to input the client id of your application and then to request the token. If you have a separate account running a bot you should register the application under your bot, and then login as your normal user in order to request the token.

Dependencies:
$json: http://www.mircscripts.org/comments.php?cid=4407
SSL: http://www.mirc.com/ssl.html

Source: https://gist.github.com/memnochxx/5676bef5707a8019f0ca

In general you'll create an alias to open the socket and a signal to handle the response. I've just created these to allow you to follow a channel. Changing the current game uses the same call as the topic, so check that section out to use as a template.

You may come across scopes that the script currently does not request. Just add it to scope_request in twitch.ini and request/renew your token.

Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
i just set up the application under my bot using the client ID it auto-filled (i suspect this is the bot's ID). I installed the SSL library but what do i do with the json4407?

EDIT: ran the file with mirc and i suspect it's loaded. So would copying this from the snipped allow me to !follow? (adding a on:text command for !follow)
Code:
alias twitch.follow {
  var %user = $1, %user.chan = #$1, %target = $2, %chan = $3
  var %sockname = twitch.follow. $+ $ticks
 
  hfree -w %sockname | hmake %sockname
  hadd %sockname oath.token $twitch(%user.chan).token
  hadd %sockname request /kraken/users/ $+ %user $+ /follows/channels/ $+ %target
  hadd %sockname method PUT
  hadd %sockname data
  hadd %sockname chan %chan
  hadd %sockname target %target
  hadd %sockname signal twitch.follow
  sockopen -e %sockname api.twitch.tv 443
}


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
bump... How would i do a !follow command in chat after i have the application set up and both dependencies?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Maybe like this. Untested.
Code:
on *:TEXT:!follow *:#:{
  if $nick == YOURNICKHERE && $2 != $null {
    twitch.follow YOURNICKHERE $2 #
  }
}

Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
by yournickhere (on the twitch.follow line) do you mean the bot's name?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
The name of the user that's going to follow the target.

Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
here is the script i have so far:
Code:
on *:TEXT:!follow *:#:{
  if $nick == theyoungergamer && $2 != $null {
    twitch.follow paintballbot $2 #
  }
}
alias twitch.follow {
  var %user = $1, %user.chan = #$1, %target = $2, %chan = $3
  var %sockname = twitch.follow. $+ $ticks

  hfree -w %sockname | hmake %sockname
  hadd %sockname oath.token $twitch(%user.chan).token
  hadd %sockname request /kraken/users/ $+ %user $+ /follows/channels/ $+ %target
  hadd %sockname method PUT
  hadd %sockname data
  hadd %sockname chan %chan
  hadd %sockname target %target
  hadd %sockname signal twitch.follow
  sockopen -e %sockname api.twitch.tv 443
}

It doesn't follow the target.


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Do you even get the "Could not follow" error? Just stating that "it doesn't work" isn't very helpful. You need to start looking into the code yourself to find out where it's not working. Obviously if you want a response in the channel you also need the signal to parse the response, and nearly the entirety of the rest of the script if you want it to work at all.

You want your bot to follow the target and not yourself to follow the target? Did you retrieve an oauth token for paintballbot? (At least) these items need to be present in twitch.ini:

Code:
[#paintballbot]
client_id=xxxxxxxxxx
token=yyyyyyyyyy

[#paintballbot.scope]
user_follows_edit=1

Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
I'm a bit confused. here's what i've done so far.
1. installed the 2 dependencies as shown before
2. registered a twitch API application
What do i do now?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Read and understand the topics in the help files, tutorials, and numerous replies I've made explaining what to do such that you don't need to ask that question.

Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
Just a quick question, I have recently been getting the "could not follow" error for twitch.follow, but it was working a few days ago...

Rather than asking about every error on the forums, is there a script that can log anything that goes on, even in JSON so i can try and troubleshoot myself?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball

Link Copied to Clipboard