mIRC Homepage
Posted By: Wolfstorm Uptime Script [Decapi] [Twitch] - 18/09/16 04:41 PM
Hey has anyone got an uptime script that would be compatable with the Decapi.me API's.

The issue that I am having currently is that on mIRC 6.3.5, the !uptime script that I use is currently brokenand I cant seem to get it updated even to work with client ID's, the error appears to be in the /bread where its getting insufficient parameters on line 86:

Code:
on *:text:!uptime *:#: {
  if (!$2) tokenize 32 - $mid($2,2-)
  if ($mysocket(twitchuptime,https://api.twitch.tv/kraken/streams?channel= $+ $2 $+ &client_id=[client id here])) {
    hadd $v1 channel #
    hadd $v1 stream $2
  }
}

alias twitchuptime {
  if ($2 == error) msg $hget($1,channel) An error occurred, please try again.
  else {
    if ($bfind(&mysocket,1,"_total":0).text) msg $hget($1,channel) $qt($hget($1,stream)) is not live currently.
    elseif ($bfind(&mysocket,1,created_at).text) msg $hget($1,channel) $qt($hget($1,stream)) has been live for $duration($calc($gmt -$ctime($replacex($gettok($bvar(&mysocket,$v1,100).text,3,34),T,$chr(32)))))
  }
}

alias mysocket {
  if (www.?*.??* iswm $2) tokenize 32 $1 http:// $+ $2
  if (http://?*.??* iswm $2) || (https://?*.??* iswm $2) {
    var %e = $iif($gettok($2,1,47) == https:,-e),%a $gettok($2,2,47),%p $iif($gettok(%a,2,58) isnum 60-65535,$v1,$iif(%e,443,80)),%a $gettok(%a,1,58),%s $sha1($2,0) $+ .mysocket
    mysocket.k %s
    hmake %s
    hadd %s command $1
    hadd %s full $2
    hadd %s port %p
    hadd %s host %a
    hadd %s path $iif($gettok($2,3-,47),/ $+ $v1 $+ $iif($right($2,1) == /,/),/)
    hadd %s limit 2097152
    hadd %s r 0
    sockopen %e %s %a %p
    .timermysocket. $+ %s -io 0 30 mysocket.t %s
    if ($isid) return %s
  }
  else $iif($isid,return,echo -a Invalid input, us as: /mysocket <command> <link>)
}

alias -l mysocket.t if ($sock($1).lr > 30) { $hget($1,command) $1 error open Connection timeout | mysocket.k $1 }

alias -l mysocket.k hfree -w $1 | sockclose $1 | .timermysocket. $+ $1 off | .remove $1 | unset %c.t

on *:sockopen:*.mysocket: {
  tokenize 32 $sockname
  if ($sockerr) mysocket.e $1 open
  else {
    sockwrite -tn $1 GET $hget($1,path) HTTP/1.1
    sockwrite -tn $1 Host: $hget($1,host)
    sockwrite -tn $1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:44.0) Gecko/20100101 Firefox/45.0
    sockwrite -tn $1 Accept: text/html
    sockwrite -tn $1 Connection: close
    sockwrite -t $1 $crlf
  }
}

on *:sockread:*.mysocket: {
  tokenize 32 $sockname
  if ($sockerr) mysocket.e $1 read
  elseif ($hget($1,r)) mysocket.r $1
  else {
    sockread -f %c.t
    while ($sockbr > 2) { hadd $1 %c.t | sockread -f %c.t }
    if ($sockbr) { hadd $1 r $calc($sock($1).rcvd +$iif($hget($1,Content-Length:) <= $hget($1,limit),$v1,$v2)) | if ($sock($1).rq) mysocket.r $1 }
  }
}

on *:sockclose:*.mysocket:mysocket.d $sockname

alias -l mysocket.r sockread $sock($1).rq &b | bwrite $1 -1 &b | if ($sock($1).rcvd >= $hget($1,r)) mysocket.d $1

alias -l mysocket.e $hget($1,command) $1 error $2 $sockerr $sock($1).wsmsg | mysocket.k $1

alias -l mysocket.d {
  if ($hget($1,Transfer-Encoding:) == chunked) {
    var %y = 1
    bread $1 0 $file($1).size &f
    while ($bfind(&f,%y,$crlf).text) {
      var %v = $v1,%h $bvar(&f,%y,$calc(%v -%y)).text,%r $base(%h,16,10),%y $calc(%v +4+%r)
      if (%r == 0) break
      else bcopy &mysocket $calc(1+$bvar(&mysocket,0)) &f $calc(2+%v) %r
    }
  }
  else bread $1 0 $file($1).size &mysocket
  if ($hget($1,HTTP/1.1) != 200 OK) $hget($1,command) $1 error status $v1
  else $hget($1,command) $1 $iif($bvar(&mysocket,0),done,error read No data received.)
  mysocket.k $1
  :error
  if ($error) mysocket.k $1
}
Posted By: zapdos26 Re: Uptime Script [Decapi] [Twitch] - 18/09/16 05:32 PM
Try this:
Code:
on *:text:!uptime*:#: {
  var %uptimetarget $remove($chan,$chr(35))
  set %uptimechannel #
  if ($mysocket(twitchuptime,https://api.twitch.tv/kraken/streams?channel= $+ %uptimetarget $+ &client_id=[place client id here])) {
    hadd $v1 channel #
    hadd $v1 stream $1
  }
}
alias twitchuptime {
  if ($2 == error) msg %uptimechannel An error occurred, please try again.
  else {
    if ($bfind(&mysocket,1,"_total":0).text)  { msg %uptimechannel [Channel] is currently not live now.}
    elseif ($bfind(&mysocket,1,created_at).text) { 
      var %uptime $duration($calc($calc($gmt -$ctime($replacex($gettok($bvar(&mysocket,$v1,100).text,3,34),T,$chr(32))))))
      msg %uptimechannel [Channel] has been online for %uptime
      unset %uptimechannel
    }
  }
}

alias mysocket {
  if (www.?*.??* iswm $2) tokenize 32 $1 http:// $+ $2
  if (http://?*.??* iswm $2) || (https://?*.??* iswm $2) {
    var %e = $iif($gettok($2,1,47) == https:,-e),%a $gettok($2,2,47),%p $iif($gettok(%a,2,58) isnum 60-65535,$v1,$iif(%e,443,80)),%a $gettok(%a,1,58),%s $sha1($2,0) $+ .mysocket
    mysocket.k %s
    hmake %s
    hadd %s command $1
    hadd %s full $2
    hadd %s port %p
    hadd %s host %a
    hadd %s path $iif($gettok($2,3-,47),/ $+ $v1 $+ $iif($right($2,1) == /,/),/)
    hadd %s limit 2097152
    hadd %s r 0
    sockopen %e %s %a %p
    .timermysocket. $+ %s -io 0 30 mysocket.t %s
    if ($isid) return %s
  }
  else $iif($isid,return,echo -a Invalid input, us as: /mysocket <command> <link>)
}

alias -l mysocket.t if ($sock($1).lr > 30) { $hget($1,command) $1 error open Connection timeout | mysocket.k $1 }

alias -l mysocket.k hfree -w $1 | sockclose $1 | .timermysocket. $+ $1 off | .remove $1 | unset %c.t

on *:sockopen:*.mysocket: {
  tokenize 32 $sockname
  if ($sockerr) mysocket.e $1 open
  else {
    sockwrite -tn $1 GET $hget($1,path) HTTP/1.1
    sockwrite -tn $1 Host: $hget($1,host)
    sockwrite -tn $1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:44.0) Gecko/20100101 Firefox/45.0
    sockwrite -tn $1 Accept: text/html
    sockwrite -tn $1 Connection: close
    sockwrite -t $1 $crlf
  }
}

on *:sockread:*.mysocket: {
  tokenize 32 $sockname
  if ($sockerr) mysocket.e $1 read
  elseif ($hget($1,r)) mysocket.r $1
  else {
    sockread -f %c.t
    while ($sockbr > 2) { hadd $1 %c.t | sockread -f %c.t }
    if ($sockbr) { hadd $1 r $calc($sock($1).rcvd +$iif($hget($1,Content-Length:) <= $hget($1,limit),$v1,$v2)) | if ($sock($1).rq) mysocket.r $1 }
  }
}

on *:sockclose:*.mysocket:mysocket.d $sockname

alias -l mysocket.r sockread $sock($1).rq &b | bwrite $1 -1 &b | if ($sock($1).rcvd >= $hget($1,r)) mysocket.d $1

alias -l mysocket.e $hget($1,command) $1 error $2 $sockerr $sock($1).wsmsg | mysocket.k $1

alias -l mysocket.d {
  if ($hget($1,Transfer-Encoding:) == chunked) {
    var %y = 1
    bread $1 0 $file($1).size &f
    while ($bfind(&f,%y,$crlf).text) {
      var %v = $v1,%h $bvar(&f,%y,$calc(%v -%y)).text,%r $base(%h,16,10),%y $calc(%v +4+%r)
      if (%r == 0) break
      else bcopy &mysocket $calc(1+$bvar(&mysocket,0)) &f $calc(2+%v) %r
    }
  }
  else bread $1 0 $file($1).size &mysocket
  if ($hget($1,HTTP/1.1) != 200 OK) $hget($1,command) $1 error status $v1
  else $hget($1,command) $1 $iif($bvar(&mysocket,0),done,error read No data received.)
  mysocket.k $1
  :error
  if ($error) mysocket.k $1
Posted By: Blas Re: Uptime Script [Decapi] [Twitch] - 19/09/16 09:44 PM
By having SReject's JSON script for mIRC installed in your copy of mIRC, a simple !uptime command is pretty basic compared to using sockets.

Code:
ON $*:TEXT:/^!uptime(\s\w+)?$/iS:#: {
  VAR %chan $IIF($2,$2,$remove($chan,$chr(35)))
  JSONOpen -uw uptime https://api.twitch.tv/kraken/streams/ $+ %chan $+ ?nocache= $+ $ticks
  JSONUrlHeader uptime Client-ID avm4vi7zv0xpjkpi3d4x0qzk8xbrdw8
  JSONUrlGet uptime
  MSG $chan %chan $IIF($JSON(uptime, stream, created_at),has been live for $duration($calc($ctime - $TwitchTime($JSON(uptime, stream, created_at))),2) $+ .,is not live at the moment.)
  JSONClose uptime
}

alias TwitchTime {
  if ($regex($1-, /^(\d\d(?:\d\d)?)-(\d\d)-(\d\d)T(\d\d)\:(\d\d)\:(\d\d)(?:(?:Z$)|(?:([+-])(\d\d)\:(\d+)))?$/i)) {
    var %m = $Gettok(January February March April May June July August September October November December, $regml(2), 32), %d = $ord($base($regml(3),10,10)), %o = +0, %t
    if ($regml(0) > 6) %o = $regml(7) $+ $calc($regml(8) * 3600 + $regml(9))
    %t = $calc($ctime(%m %d $regml(1) $regml(4) $+ : $+ $regml(5) $+ : $+ $regml(6)) - %o)
    if ($asctime(zz) !== 0 && $regex($v1, /^([+-])(\d\d)(\d+)$/)) {
      %o = $regml(1) $+ $calc($regml(2) * 3600 + $regml(3))
      %t = $calc(%t + %o )
    }
    return %t
  }
}


With this you can simply use !uptime by itself to get your channels current uptime, or you can specify a channel after the !uptime command to get the uptime of that channel.

Note that I did not write the TwitchTime alias, I found that on these forums somewhere.
Posted By: FroggieDaFrog Re: Uptime Script [Decapi] [Twitch] - 20/09/16 12:23 PM
I wrote the TwitchTime script, then others fixed small issues with it laugh
Posted By: powerade661 Re: Uptime Script [Decapi] [Twitch] - 18/10/16 09:10 PM
Can't seem to get this to work for some reason. It just keeps giving me the "This channel is not live at the moment even though the channel is live..

Code:
ON $*:TEXT:/^!uptime(\s\w+)?$/iS:#: {
  VAR %chan $IIF($2,$2,$remove($chan,$chr(35)))
  JSONOpen -uw uptime https://api.twitch.tv/kraken/streams/ $+ %chan $+ ?nocache= $+ $ticks
  JSONUrlHeader uptime Client-ID: clientIDhere
  JSONUrlGet uptime
  MSG $chan %chan $IIF($JSON(uptime, stream, created_at),has been live for $duration($calc($ctime - $TwitchTime($JSON(uptime, stream, created_at))),2) $+ .,is not live at the moment.)
  JSONClose uptime
}

alias TwitchTime {
  if ($regex($1-, /^(\d\d(?:\d\d)?)-(\d\d)-(\d\d)T(\d\d)\:(\d\d)\:(\d\d)(?:(?:Z$)|(?:([+-])(\d\d)\:(\d+)))?$/i)) {
    var %m = $Gettok(January February March April May June July August September October November December, $regml(2), 32), %d = $ord($base($regml(3),10,10)), %o = +0, %t
    if ($regml(0) > 6) %o = $regml(7) $+ $calc($regml(8) * 3600 + $regml(9))
    %t = $calc($ctime(%m %d $regml(1) $regml(4) $+ : $+ $regml(5) $+ : $+ $regml(6)) - %o)
    if ($asctime(zz) !== 0 && $regex($v1, /^([+-])(\d\d)(\d+)$/)) {
      %o = $regml(1) $+ $calc($regml(2) * 3600 + $regml(3))
      %t = $calc(%t + %o )
    }
    return %t
  }
}
Posted By: FroggieDaFrog Re: Uptime Script [Decapi] [Twitch] - 19/10/16 01:40 AM
See this line:
Code:
JSONUrlHeader uptime Client-ID: clientIDhere


First, the colon(:) isn't needed and should be omitted.
You'll need to change clientIdHere to an actual app id created here
Posted By: powerade661 Re: Uptime Script [Decapi] [Twitch] - 19/10/16 02:26 AM
I didn't have your updated JSON parser. I got it working now. But this works every now and then and then stops and then works again. Not sure if it's rate limiting or what. Here it is though. I believe you helped me with this script. I did include the client id. The uptime script works great. smile This script does not frown


Code:

on *:text:!recent:#:{
  var %stream = $mid(#,2-), %url = https://api.twitch.tv/kraken/streams/ $+ %stream $+ /follows?limit=6&nocache= $+ $ticks
  jsonopen -uw server %url
  JSONUrlHeader server Client-ID 
  JSONUrlGet server
  var %list, %i = 0, %count = $json(server,follows,length)
  while (%i < %count) {
    var %display_name = $json(server,follows,%i,user,display_name)

    %list = $addtok(%list,%display_name,32)
    inc %i
  }

  msg # Recent followers are: %list
  JSONClose server %url
}








Posted By: FroggieDaFrog Re: Uptime Script [Decapi] [Twitch] - 19/10/16 02:49 AM
-snip-

Try:
Code:
on *:text:!recent:#:{
  var %stream = $mid($chan, 2-)
  var %url = https://api.twitch.tv/kraken/streams/ $+ %stream $+ /follows?limit=6&nocache= $+ $ticks
  var %i = 0, %count, %follower, %list

  JSONUrlOpen -duw followers %url
  JSONUrlHeader followers Client-ID _clientid_here_
  JSONUrlGet followers
  
  if ($JSONError) {
    msg # Error: $v1
  }
  elseif ($JSON(followers, error)) {
    msg # Error: $JSON(followers, message)
  }
  elseif ($JSON(followers, follows, length)) {
    %count = $v1
    while (%i < %count) {
      %follower = $json(followers, follows, %i, user, display_name)

      %list = $addtok(%list, %follower, 32)
      inc %i
    }
    msg # Recent followers are: %list
  }
  else {
    msg # No recent followers
  }
}
© mIRC Discussion Forums