mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
!status and !game possible? [Twitch help] #245801 08/05/14 03:32 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
So, with "Nightbot" on twitch it is possible to do:

!status TEXT HERE
and
!game Game Name Here

in chat to change the title of your stream and the game you are playing. I was just curious if this is possible to do with a custom bot and where I might find some info on how to do this? As always, I'm not asking you to write something for me. Just to point me in the right direction and help me out a bit? I'm not exactly sure what to search for in /help so even that little bit could help. Thanks in advance.

Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245802 08/05/14 03:41 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
I've got a script to change the status (I call it !topic), changing the game uses the same call and can easily be added to the script. I've posted the link to the full script and pieces of it all around the forum.

http://forums.mirc.com/ubbthreads.php/topics/245699/Re:_follow_a_channel/getting_s

http://forums.mirc.com/ubbthreads.php/topics/245708/Re:_Twitch_Subscriber-only_com

https://github.com/justintv/twitch-api

Re: !status and !game possible? [Twitch help] [Re: Loki12583] #245807 08/05/14 08:43 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Thanks a lot Loki, this should give me something to do over the next day or so smile Appreciate the guidance.

Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245920 14/05/14 03:29 AM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Alright... I finally got time to work at this a bit, and I still can't seem to get it right. I've done everything in the correct order (or at least, I believe) and with all of the correct information and I still can't seem to get it working.

Here's what I've done so far (note: this was all done using my bot account first, and THEN my main account just to make sure that wasn't the problem.)
-Registered my application via: twitch.tv/settings/connections
-Got my oauth token
-Downloaded the $json script ( http://www.mircscripts.org/comments.php?cid=4407 )
[side note, wasn't sure what to do with this... maybe that's the problem? I placed it in my mIRC folder though... hopefully that's what I was supposed to do]
-Fixed up the script to fit my information.
-Authorized to run app from my account.



Script I'm using (thanks to Loki)
Code:
alias -l twitch.token {
  if ($1 == My_Bot) return Bot_AccessToken
}

on @*:text:!topic*:#:{
  if ($2 != $null) {
    if ($nick isop #) twitch.topic # $2-
  }
  else {
    twitch.topic #
  }
}

alias twitch.topic {
  var %chan = $1, %topic = $2-
  var %sockname = twitch.topic. $+ $ticks
  hfree -w %sockname | hmake %sockname
  hadd %sockname headerfile %sockname $+ .header.txt
  hadd %sockname datafile %sockname $+ .data.txt
  hadd %sockname params %chan
  hadd %sockname oath.token $twitch.token($mid(%chan,2-))
  hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-)
  if (%topic != $null) {
    hadd %sockname method PUT
    hadd %sockname data channel[status]= $+ $urlencode(%topic)
    hadd %sockname signal topic.set
  }
  else {
    hadd %sockname method GET
    hadd %sockname signal topic.get
  }
  sockopen -e %sockname api.twitch.tv 443
}

on *:signal:topic.get:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%header,1)) msg %chan Status: $json(%data,status)
  else msg %chan Could not get status.

  hfree -w %sockname
  .remove %header | .remove %data
}

on *:signal:topic.set:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%header,1)) msg %chan Status set: $json(%data,status)
  else msg %chan Could not set status.

  hfree -w %sockname
  .remove %header | .remove %data
}

on *:sockopen:twitch.*:{
  var %a = sockwrite -n $sockname
  %a $hget($sockname,method) $hget($sockname,request) HTTP/1.1
  %a Host: api.twitch.tv
  %a Connection: close
  %a Accept: application/vnd.twitchtv.v2+json
  if ($hget($sockname,oath.token) != $null) %a Authorization: OAuth $v1
  if ($hget($sockname,data) != $null) {
    %a Content-Type: application/x-www-form-urlencoded
    %a Content-Length: $len($v1)
  }
  %a $+($crlf,$hget($sockname,data))
}

on *:sockread:twitch.*:{
  var %header
  var %headerfile = $hget($sockname,headerfile)
  var %datafile = $hget($sockname,datafile)

  if (!$hget($sockname,header.complete)) {
    sockread %header
    while (%header != $null) {
      write %headerfile %header
      sockread %header
    }
    if ($sockbr) hadd $sockname header.complete $true
  }
  if ($hget($sockname,header.complete)) {
    sockread &read
    while ($sockbr) {
      bwrite %datafile -1 -1 &read
      sockread &read
    }
  }
}

on *:sockclose:twitch.*:{
  var %header = $hget($sockname,headerfile)
  var %data = $hget($sockname,datafile)
  var %signal = $hget($sockname,signal)
  var %params = $hget($sockname,params)

  if (%signal) .signal %signal 0 $sockname %header %data %params
  else {
    hfree -w $sockname
    .remove %header | .remove %data
  }
}

alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))



I feel like I'm probably overlooking the smallest detail someplace and it's making me get the "Can't set status" error message. Again, and as always, ANY help is appreciated. Thank you for the help you've already given me. I just can't figure this out. I've worked at it a bit over the last few days and today I put nearly all my focus onto it. I even tried googling a few things before posting again about it, but alas... Here I am. Sorry, and thanks again.

Last edited by Bramzee; 14/05/14 03:35 AM.
Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245930 14/05/14 11:27 AM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
You're using a separate bot to run your commands? You need to give permission to your bot from your main user. The access token is associated with your main user, so in the twitch.token alias you should be checking for your main user, not the bot.

To see what the real error is you can comment out the lines that remove the response: ;.remove %header | .remove %data and check those files (in your mircdir).

You need to load the json script, you can use the /load -rs script command or just paste the contents into a new file in the remote editor.

Re: !status and !game possible? [Twitch help] [Re: Loki12583] #245934 14/05/14 01:02 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
I appreciate the help Loki. However, I'm going to have to bookmark this page and come back to it later when I have more experience with stuff... I've spent as much time as my head can handle on this right now ha. Again, thank you. Gonna look more into some help files and stuff and search around the internet, rather than keep bothering the forums with twitch problems :P I just... don't understand I guess.

Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245943 15/05/14 05:23 AM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
nvm, got it working somehow... idk how because I've been drinking and just started doing stuff. But it works. Now to get !game to work smile

Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245970 16/05/14 05:45 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Sorry for the double (possibly triple) post, but I didn't feel like it would be appropriate to make another topic for basically the same problem. And editing my other post wouldn't have helped get this noticed. Anyway, on with the question...

Alright, so I got my !topic working right. I've spent the last 2 days trying to get !game working (to edit what game I'm playing obviously) But I can't seem to get it going... I was told that I could edit the !topic script to fit the new command. I went through and edited "header" and "topic" so that it's not editing the status of the channel. This is what I have so far... Hopefully someone can point out my mistakes and give me an idea of what I need to fix. I've spent a lot of time on github and looking through the twitchAPI files and stuff but still don't see where I could have gone wrong.

Code:
on @*:text:!game*:#:{
  if ($2 != $null) {
    if ($nick isop #) twitch.game # $2-
  }
  else {
    twitch.game #
  }
}

alias twitch.game {
  var %chan = $1, %game = $2-
  var %sockname = twitch.game. $+ $ticks
  hfree -w %sockname | hmake %sockname
  hadd %sockname gamefile %sockname $+ .game.txt
  hadd %sockname datafile %sockname $+ .data.txt
  hadd %sockname params %chan
  hadd %sockname oath.token $twitch.token($mid(%chan,2-))
  hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-)
  if (%game != $null) {
    hadd %sockname method PUT
    hadd %sockname data channel[game]= $+ $urlencode(%topic)
    hadd %sockname signal game.set
  }
  else {
    hadd %sockname method GET
    hadd %sockname signal game.get
  }
  sockopen -e %sockname api.twitch.tv 443
}

on *:signal:game.get:{
  var %err = $1, %sockname = $2, %game = $3, %data = $4, %chan = $5

  hfree -w %sockname
  .remove %game | .remove %data
}

on *:signal:game.set:{
  var %err = $1, %sockname = $2, %game = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%game,1)) 
  else msg %chan Could not set game.

  hfree -w %sockname
  .remove %game | .remove %data
}

on *:sockopen:twitch.*:{
  var %a = sockwrite -n $sockname
  %a $hget($sockname,method) $hget($sockname,request) HTTP/1.1
  %a Host: api.twitch.tv
  %a Connection: close
  %a Accept: application/vnd.twitchtv.v2+json
  if ($hget($sockname,oath.token) != $null) %a Authorization: OAuth $v1
  if ($hget($sockname,data) != $null) {
    %a Content-Type: application/x-www-form-urlencoded
    %a Content-Length: $len($v1)
  }
  %a $+($crlf,$hget($sockname,data))
}

on *:sockread:twitch.*:{
  var %game
  var %gamefile = $hget($sockname,gamefile)
  var %datafile = $hget($sockname,datafile)

  if (!$hget($sockname,game.complete)) {
    sockread %game
    while (%game != $null) {
      write %gamefile %game
      sockread %game
    }
    if ($sockbr) hadd $sockname game.complete $true
  }
  if ($hget($sockname,game.complete)) {
    sockread &read
    while ($sockbr) {
      bwrite %datafile -1 -1 &read
      sockread &read
    }
  }
}

on *:sockclose:twitch.*:{
  var %game = $hget($sockname,gamefile)
  var %data = $hget($sockname,datafile)
  var %signal = $hget($sockname,signal)
  var %params = $hget($sockname,params)

  if (%signal) .signal %signal 0 $sockname %game %data %params
  else {
    hfree -w $sockname
    .remove %game | .remove %data
  }
}

Last edited by Bramzee; 16/05/14 05:45 PM.
Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245976 16/05/14 10:32 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
I see two things wrong, you changed a variable to %game but did not change the $urlencode(%topic)

Code:
  if (* 200 OK iswm $read(%game,1)) 
  else msg %chan Could not set game.


This is a syntax error

And you didn't need to change all references of "header" to "game"

Re: !status and !game possible? [Twitch help] [Re: Loki12583] #245978 17/05/14 12:49 AM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Thanks Loki. You're very helpful to me and a LOT of other "noobs" with mIRC. I appreciate it man. I'll try it out now smile

EDIT:


Still getting the "Could not set status/game." error.

I had it working before, but I had been drinking when I did whatever it was I did lol. So I don't remember. I feel like I removed something from the script. I'll get it eventually. Thanks again loki smile At least now it's acknowledging that I want to set the game title.

Last edited by Bramzee; 17/05/14 01:14 AM.
Re: !status and !game possible? [Twitch help] [Re: Bramzee] #245981 17/05/14 07:37 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
I do like the way Loki coded this. It is very neat and easy to be modified.
I believe you only need to modify this parts.
note: [...code...] is loki's original code
Code:

[..code...]

on $@*:text:/^!(topic|game)/iS:#:{
  var %switch $iif($1 == !topic,status,game)
  if ($2 != $null) {
    if ($nick isop #) twitch.topic # %switch $2-
  }
  else {
    twitch.topic # %switch
  }
}

alias twitch.topic {
  var %chan = $1, %switch = $2, %topic = $3-

  [...code...]

  hadd %sockname params %chan %switch

  [...code...]

    hadd %sockname data channel[ $+ %switch $+ ]= $+ $urlencode(%topic)

  [...code...]

}

on *:signal:topic.get:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5, %switch = $6

  if (* 200 OK iswm $read(%header,1)) msg %chan Status: $json(%data,%switch)

  [...code...]

}

on *:signal:topic.set:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5, %switch = $6

  if (* 200 OK iswm $read(%header,1)) msg %chan Status set: $json(%data,%switch)

  [...code...]

}

[...rest of code...]

This is untested.
I dont have twitch account wink

Re: !status and !game possible? [Twitch help] [Re: blessing] #245984 17/05/14 03:21 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
I'm pretty sure it works. I'm having a rough time getting it to authenticate though. The access token doesn't seem to be working or something. I'll try adding a different scope to it maybe it'll switch it up a bit and that'll help... Thanks blessing smile

Re: !status and !game possible? [Twitch help] [Re: Bramzee] #255953 07/12/15 08:01 PM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
Originally Posted By: Bramzee


Script I'm using (thanks to Loki)
Code:
alias -l twitch.token {
  if ($1 == My_Bot) return Bot_AccessToken
}

on @*:text:!topic*:#:{
  if ($2 != $null) {
    if ($nick isop #) twitch.topic # $2-
  }
  else {
    twitch.topic #
  }
}

alias twitch.topic {
  var %chan = $1, %topic = $2-
  var %sockname = twitch.topic. $+ $ticks
  hfree -w %sockname | hmake %sockname
  hadd %sockname headerfile %sockname $+ .header.txt
  hadd %sockname datafile %sockname $+ .data.txt
  hadd %sockname params %chan
  hadd %sockname oath.token $twitch.token($mid(%chan,2-))
  hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-)
  if (%topic != $null) {
    hadd %sockname method PUT
    hadd %sockname data channel[status]= $+ $urlencode(%topic)
    hadd %sockname signal topic.set
  }
  else {
    hadd %sockname method GET
    hadd %sockname signal topic.get
  }
  sockopen -e %sockname api.twitch.tv 443
}

on *:signal:topic.get:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%header,1)) msg %chan Status: $json(%data,status)
  else msg %chan Could not get status.

  hfree -w %sockname
  .remove %header | .remove %data
}

on *:signal:topic.set:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%header,1)) msg %chan Status set: $json(%data,status)
  else msg %chan Could not set status.

  hfree -w %sockname
  .remove %header | .remove %data
}

on *:sockopen:twitch.*:{
  var %a = sockwrite -n $sockname
  %a $hget($sockname,method) $hget($sockname,request) HTTP/1.1
  %a Host: api.twitch.tv
  %a Connection: close
  %a Accept: application/vnd.twitchtv.v2+json
  if ($hget($sockname,oath.token) != $null) %a Authorization: OAuth $v1
  if ($hget($sockname,data) != $null) {
    %a Content-Type: application/x-www-form-urlencoded
    %a Content-Length: $len($v1)
  }
  %a $+($crlf,$hget($sockname,data))
}

on *:sockread:twitch.*:{
  var %header
  var %headerfile = $hget($sockname,headerfile)
  var %datafile = $hget($sockname,datafile)

  if (!$hget($sockname,header.complete)) {
    sockread %header
    while (%header != $null) {
      write %headerfile %header
      sockread %header
    }
    if ($sockbr) hadd $sockname header.complete $true
  }
  if ($hget($sockname,header.complete)) {
    sockread &read
    while ($sockbr) {
      bwrite %datafile -1 -1 &read
      sockread &read
    }
  }
}

on *:sockclose:twitch.*:{
  var %header = $hget($sockname,headerfile)
  var %data = $hget($sockname,datafile)
  var %signal = $hget($sockname,signal)
  var %params = $hget($sockname,params)

  if (%signal) .signal %signal 0 $sockname %header %data %params
  else {
    hfree -w $sockname
    .remove %header | .remove %data
  }
}

alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))




is it still working? i don't get it working...can i copy this script ? and as loki said, "my_bot" -> name of the user WHO writes "!status" ? and "bot_accesstoken" -> the real oauthtoken? IF so, i guess the token of the bot?

Re: !status and !game possible? [Twitch help] [Re: Karotte] #256058 15/12/15 12:14 AM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
bump

Re: !status and !game possible? [Twitch help] [Re: Karotte] #256236 31/12/15 04:37 PM
Joined: May 2015
Posts: 133
K
keyeslol Offline
Vogon poet
Offline
Vogon poet
K
Joined: May 2015
Posts: 133
This still works with some modification. my_bot is the channel itself.

So if the channel was keyes, it would be if $1 == keyes. You will run into an issue with this code not displaying the current status or game, it will just return a blank value. You will have to perform a work around.


twitter @keyeslol
Re: !status and !game possible? [Twitch help] [Re: keyeslol] #256287 06/01/16 11:48 AM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
i don't get it working...i put the json script in a new remote file, replaced "my_bot" with "kar0ttenp0wer" and replaced "bot_accesstoken" with "oauth:4e....."

i replaced "!topic" with "!status", do i need to change anything in script then aswell?

if i write "!status" the bot messages "Status:"

if i expand "!status put_in_anything" the bot messages "Could not set status"

what am i doing wrong?

Last edited by Karotte; 06/01/16 11:49 AM.
Re: !status and !game possible? [Twitch help] [Re: Karotte] #256301 07/01/16 09:28 PM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
First: Timi's json parser is showing its age, probably biased but I recommend using mine(found in signature)

Second: Your bot will need an OAUTH token for each channel/stream you wish to change the title/game for.

For just your stream(or streams of accounts you own) I have a script found under mtwitch that will give you a full-access OAUTH token, that can then be used to alter such.



Code:
alias -l OAUTH {
  goto $iif(#* iswm $1, $mid($1, 2-), $1)
  
  /* EDITS START HERE; REMOVE UNNEEDED LINES */
  
  :acount1 | return Account 1's oauth here
  :acount2 | return Account 2's oauth here
  :acount3 | return Account 3's oauth here
  
  /* EDITS END */
  
  :error
  reseterror
}

on $*:TEXT:/^!(status|game)(\s|$):#:{
  var %n = $lower($regml(1))
  var %json = TwitchStreamUpdate
  var %data

    if ($0 == 1) {
        JSONOpen -du %json https://api.twitch.tv/kraken/channels/ $+ $lower($mid(#, 2-))
        if ($JSONError) {
            msg # Unable to retrieve $lower(%n $+ .)
        }
        elseif ($json(%json, %n)) {
            msg # Current %n $+ : $v1
        }
        else {
          msg # Unable to retrieve $lower(%n $+ .)
        }
    }
    elseif ($nick != $mid(#,2-)) {
      return
    }
    elseif (!$OAUTH(#)) {
      return
    }
    else {
        var %data, %json = TwitchStreamUpdate
        if (%n == status) {
            %data = {"channel":{"status":" $+ $escape($2-) $+ "}}
        }
        else {
            %data = {"channel":{"game":" $+ $escape($2-) $+ "}}
        }
        

        JSONOpen -duw %json https://api.twitch.tv/kraken/channels/ $+ $lower($mid(#, 2-))
        JSONUrlMethod %json POST
        JSONUrlHeader %json Connection close
        JSONUrlHeader %json Accept application/vnd.twitchtv.v3+json
        JSONUrlHeader %json Content-type application/json
        JSONUrlHeader %json Content-length $len(%data)
        JSONUrlHeader %json Authorization OAuth $OAUTH(#)
        JSONUrlGet %json %data

        if ($jsonerror) {
            msg # Unable to update $lower(%n $+ .)
        }
        elseif ($JSON(%json, %n)) {
            msg # Updated $lower($1) $+ : $v1
        }
        else {
            msg # Unable to update $lower(%n $+ .)
        }
    }
}

alias -l escape return $regsubex($1-, /([^a-z\d_-\.])/gi, \ $+ \t)




Last edited by FroggieDaFrog; 07/01/16 09:48 PM.

I am SReject
My Stuff
Re: !status and !game possible? [Twitch help] [Re: FroggieDaFrog] #256304 08/01/16 12:06 PM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
Thanks for your help, i was using your JSON already.

The code you listed below is the script you found under mtwitch?

And what especially do i replace for the oauth token?

":acount1 | return oauth:2vn..." like this?

Thanks

Re: !status and !game possible? [Twitch help] [Re: Karotte] #256863 23/02/16 10:33 PM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
bump

Re: !status and !game possible? [Twitch help] [Re: Karotte] #257031 09/03/16 01:26 AM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
bump

Page 1 of 2 1 2