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.