mIRC Home    About    Download    Register    News    Help

Print Thread
#251196 11/02/15 08:27 PM
Joined: Feb 2015
Posts: 2
O
Bowl of petunias
OP Offline
Bowl of petunias
O
Joined: Feb 2015
Posts: 2
hi, I use this code to change my twitch channel topic but did not working, I've add the application to developer all the settings are correct when i execute the !topic <text> it says that has been changed but on twitch channel did not, any help will be appreciated!

Code:
alias -l twitch.token {
  if ($1 == MY-TWITCH-CHANEL) return MY-CLIENTID
}

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 json {
  if ($isid) {
    ;name of the com interface declared so I don't have to type it over and over again :D
    var %c = jsonidentifier,%x = 2,%str,%p,%v,%addr

    ;filter out some characters in $1 (address)
    if ($isfile($1)) { %addr = $qt($replace($1,\,\\,;,\u003b,",\u0022)) }
    else { %addr = $qt($replace($1,;,\u003b,",\u0022)) }

    ;if the interface hasnt been open and initialized, do it.
    json.comcheck
    if (!$timer(jsonclearcache)) { .timerjsonclearcache -o 0 300 jsonclearcache }

    ;get the list of parameters
    while (%x <= $0) {
      %p = $($+($,%x),2)
      if (%p == $null) { noop }
      elseif (%p isnum || $qt($noqt(%p)) == %p) { %str = $+(%str,[,%p,]) }
      else { %str = $+(%str,[",%p,"]) }
      inc %x
    }
    if ($prop == count) { %str = %str $+ .length }

    ;check to see if source is file
    if ($isfile($1)) {
      if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),filejson,$chr(40),%addr,$chr(41),$chr(41),%str))) { return $com(%c).result }
    }
    ;check to see if source is url
    elseif (http://* iswm $1 || https://* iswm $1) {
      ;if url is in cache, used cached data
      if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
      ;otherwise, get data
      elseif ($com(%c,eval,1,bstr,$+(urlcache[,%addr,]) = $+(httpjson,$chr(40),$qt($1),$chr(41)))) {
        if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
      }
    }
    ;get data from inputted json
    elseif ($com(%c,eval,1,bstr,$+(x=,%addr,;,x,%str,;))) { return $com(%c).result }
  }
}
alias jsonclearcache {
  if ($com(jsonidentifier)) {
    if (!$1) { noop $com(jsonidentifier,executestatement,1,bstr,urlcache = {}) }
    else { echo -a $com(jsonidentifier,executestatement,1,bstr,urlcache[" $+ $1 $+ "] = "") }
  }
}
alias json.enc {
  json.comcheck
  if ($com(jsonidentifier,eval,1,bstr,encodeURI(" $+ $1- $+ "))) { return $com(jsonidentifier).result }
}
alias json.enccomponent {
  json.comcheck
  if ($com(jsonidentifier,eval,1,bstr,encodeURIComponent(" $+ $1- $+ "))) { return $com(jsonidentifier).result }
}
alias -l json.comcheck {
  var %c = jsonidentifier
  if (!$com(%c)) {
    .comopen %c MSScriptControl.ScriptControl
    ;add two javascript functions for getting json from urls and files
    noop $com(%c,language,4,bstr,jscript) $com(%c,addcode,1,bstr,function httpjson(url) $({,0) y=new ActiveXObject("Microsoft.XMLHTTP");y.open("GET",url,false);y.send();return y.responseText; $(},0))
    noop $com(%c,addcode,1,bstr,function filejson (file) $({,0) x = new ActiveXObject("Scripting.FileSystemObject"); txt1 = x.OpenTextFile(file,1); txt2 = txt1.ReadAll(); txt1.Close(); return txt2; $(},0))
    ;add function to securely evaluate json
    noop $com(%c,addcode,1,bstr,function str2json (json) $({,0) return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(json.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + json + ')'); $(},0))
    ;add a cache for urls
    noop $com(%c,addcode,1,bstr,urlcache = {})
  }
}

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

Joined: Mar 2014
Posts: 42
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
if you're having the issue RIGHT NOW its because the twitch API is taking a dump. Moocat just tweeted about moobot not being able to update titles.

Last edited by Sjoepele; 11/02/15 08:58 PM.
Joined: Feb 2015
Posts: 2
O
Bowl of petunias
OP Offline
Bowl of petunias
O
Joined: Feb 2015
Posts: 2
oh thanks can you please give me his/her twitter page so i can get info about it? thanks for answer

Joined: Mar 2014
Posts: 42
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
https://twitter.com/TwitchTVMoobot

normally you can find stuff on @twitchsupport as well but this time they haven't tweeted anything


Link Copied to Clipboard