mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2015
Posts: 5
Y
YeyoSsj Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Dec 2015
Posts: 5
Hello friends!
i have a problem with a perfect uptime script from the user Nillen

Code:
on *:text:!uptimeee*:#:{
  if ((%flooduptime) || ($($+(%,flooduptime.,$nick),2))) { return }
  set -u15 %flooduptime On
  set -u20 %flooduptime. $+ $nick On
  set %target $iif($2,$2,$mid(#,2-))
  set %channel #
  uptime
}

alias uptime {
  sockclose uptime
  sockopen uptime nightdev.com 80
}

on *:sockopen:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %target HTTP/1.1
  sockwrite -n $sockname Host: www.nightdev.com 
  sockwrite -n $sockname $crlf
}

on *:sockread:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1- }
  elseif (%data == The channel is not live.) msg %channel %target is currently not online.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}


The problem is that nightdev added text like this:



There will be a way to change the text of nightdev to another page? like this:
https://decapi.me/twitch/uptime.php?channel=yeyossj

Sorry for my bad english!! XD Thanks for help!

Joined: Feb 2015
Posts: 19
Y
Pikka bird
Offline
Pikka bird
Y
Joined: Feb 2015
Posts: 19
I can better help you via our IRC network.
Although I still miss a part of the script, you can simply edit the output of the socket.
And instead of nightdev.com, you can use your own IP or DNS.

Joined: Dec 2015
Posts: 5
Y
YeyoSsj Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Y
Joined: Dec 2015
Posts: 5
what are your irc network?
i try this but not respond..
Code:
on *:text:!uptimeee*:#:{
  if ((%flooduptime) || ($($+(%,flooduptime.,$nick),2))) { return }
  set -u15 %flooduptime On
  set -u20 %flooduptime. $+ $nick On
  set %target $iif($2,$2,$mid(#,2-))
  set %channel #
  uptime
}

alias uptime {
  sockclose uptime
  sockopen uptime decapi.me 80
}

on *:sockopen:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /twitch/uptime.php?channel= $+ %target HTTP/1.1
  sockwrite -n $sockname Host: decapi.me
  sockwrite -n $sockname $crlf
}

on *:sockread:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1- }
  elseif (%data == The channel is not live.) msg %channel %target is currently not online.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
} 


somethig wrong? D:

Last edited by YeyoSsj; 06/01/16 06:02 AM.
Joined: Apr 2014
Posts: 24
T
Ameglian cow
Offline
Ameglian cow
T
Joined: Apr 2014
Posts: 24
This works for me:

Code:
on *:sockread:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1 $2 $3 $4 }
  elseif (%data == The channel is not live. - Oh hey, you're using an API meant for Nightbot, not for whatever you're using. Maybe you'd want to try out the new Nightbot beta: https://beta.nightbot.tv) msg %channel %target is currently not online.
}

Joined: Feb 2015
Posts: 243
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Feb 2015
Posts: 243
Hey! I just noticed that decapi.me is https.
You need to:
Code:
sockopen -e uptime decapi.me 443

Everything else seems fine!

Last edited by OrFeAsGr; 06/01/16 08:48 PM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
If you make use of my JSON for mIRC script (found in my signature) this is quite easy, using twitch's own API:

Code:
on *:TEXT:!uptime*:#: {
  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
  if ($JSONError) {
    msg # Unable to retrieve the state of %stream
  }
  elseif ($regex($JSON(%json, streams, 0, created_at), /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/)) {
    %time = $calc($ctime($+($gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec, $regml(2), 32) $ord($base($regml(3), 10, 10)), $chr(44) $regml(1) $regml(4), :, $regml(5), :, $regml(6))) + ( $time(z) * 3600))
    msg # %stream has been online for $duration(%time)
  }
  else {
    msg # %stream is currently not online.
  }
}


I am SReject
My Stuff
Joined: Mar 2016
Posts: 1
_
Mostly harmless
Offline
Mostly harmless
_
Joined: Mar 2016
Posts: 1
Originally Posted By: FroggieDaFrog
If you make use of my JSON for mIRC script (found in my signature) this is quite easy, using twitch's own API:

Code:
on *:TEXT:!uptime*:#: {
  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
  if ($JSONError) {
    msg # Unable to retrieve the state of %stream
  }
  elseif ($regex($JSON(%json, streams, 0, created_at), /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/)) {
    %time = $calc($ctime($+($gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec, $regml(2), 32) $ord($base($regml(3), 10, 10)), $chr(44) $regml(1) $regml(4), :, $regml(5), :, $regml(6))) + ( $time(z) * 3600))
    msg # %stream has been online for $duration(%time)
  }
  else {
    msg # %stream is currently not online.
  }
}


Sorry, but that's not right ... xxx has been online for 2412wks 1day 10hrs 44mins 11secs ... nope smile

Joined: May 2015
Posts: 133
K
Vogon poet
Offline
Vogon poet
K
Joined: May 2015
Posts: 133
Yeah code isn't working right.


twitter @keyeslol
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Here's a version that uses a "socket platform," which does the hard work. The code is overly complicated and longer than it would need to be, but it also doesn't require much to make it work or keep working.

All you need to worry about is the "twitchuptime" alias. If the script breaks or something changes, it's the one you need to change/fix/update.
Code:
on *:text:!uptime *:#: {
  if ($mysocket(twitchuptime,https://decapi.me/twitch/uptime.php?channel= $+ $2)) {
    hadd $v1 channel #
    hadd $v1 stream $2
  }
}

alias twitchuptime {
  if ($2 == error) msg $hget($1,channel) An error occurred, please try again.
  else {
    tokenize 32 $1 $bvar(&mysocket,1,300).text
    if ($2- = Channel is not live.) msg $hget($1,channel) $qt($hget($1,stream)) is not live currently.
    elseif ($2- == Channel does not exist.) msg $hget($1,channel) $qt($hget($1,stream)) doesn't exist.
    else msg $hget($1,channel) $qt($hget($1,stream)) has been live for $2-
  }
}

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
    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 r 0
    sockopen %e %s %a %p
    .timermysocket. $+ %s -io 1 60 mysocket.t %s
    if ($isid) return %s
  }
  else $iif($isid,return,echo -a Invalid input, us as: /mysocket <command> <link>)
}

alias -l mysocket.t $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:) <= 2097152,$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
  $hget($1,command) $1 $iif($bvar(&mysocket,0),done,error read No data received.)
  mysocket.k $1
}


And just to be safe, here's the closest thing to the "mysocket" documentation that's available: https://forums.mirc.com/ubbthreads.php/topics/256954/Re:_Brain_frazzled_would_love_#Post256954

Joined: May 2015
Posts: 133
K
Vogon poet
Offline
Vogon poet
K
Joined: May 2015
Posts: 133
there's working code above as well, the math is wrong on froggies code.


twitter @keyeslol
Joined: Sep 2014
Posts: 52
Babel fish
Offline
Babel fish
Joined: Sep 2014
Posts: 52
Tested and working. Not sure why people are still trying to use the nightdev api.
Code:
on *:TEXT:!uptime*:#: {
  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
  if ($JSONError) {
    msg # Unable to retrieve the state of %stream
  }
  elseif ($JSON(%json, streams, 0, created_at)) {
    %time = $ctime($remove($replace($v1,T,$chr(32)),Z))
    msg # %stream has been online for $duration($calc($gmt - %time))
  }
  else {
    msg # %stream is currently not online.
  }
}

Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
The earlier code had a little brain fart in it, and didn't use Twitch's own API, so here's an update:
Code:
on *:text:!uptime *:#: {
  if ($mysocket(twitchuptime,https://api.twitch.tv/kraken/streams?channel= $+ $2)) {
    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 r 0
    sockopen %e %s %a %p
    .timermysocket. $+ %s -io 1 60 mysocket.t %s
    if ($isid) return %s
  }
  else $iif($isid,return,echo -a Invalid input, us as: /mysocket <command> <link>)
}

alias -l mysocket.t $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:) <= 2097152,$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
  $hget($1,command) $1 $iif($bvar(&mysocket,0),done,error read No data received.)
  mysocket.k $1
}

Last edited by Dazuz; 14/03/16 04:34 AM. Reason: Another brain fart.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Me neither... me... neither. Sorry about the math error; I just write the tools people use >.>


I am SReject
My Stuff
Joined: Jun 2014
Posts: 77
K
Babel fish
Offline
Babel fish
K
Joined: Jun 2014
Posts: 77
Hi @Dazuz,

If or if have to be used with "!uptime channel name" or also can be used by just putting "!uptime"? From already thank you very much.

Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
In it's current from you will have to have something after "!uptime" for it to trigger. As in "!uptime helloworld" will trigger it, but "!uptime" will not.

Here's a version that will trigger with just "!uptime".
Code:
on *:text:!uptime*:#: {
  if (!$2) msg # Invalid input!
  elseif ($mysocket(twitchuptime,https://api.twitch.tv/kraken/streams?channel= $+ $2)) {
    hadd $v1 channel #
    hadd $v1 stream $2
  }
}



EDIT:
If you want it to automatically check some specific channel's uptime, without having to specify the channel, use this one and replace "YOURCHANNELHERE" with the channel name.
Code:
on *:text:!uptime*:#: {
  tokenize 1 $iif($2,$2,YOURCHANNELHERE)
  if ($mysocket(twitchuptime,https://api.twitch.tv/kraken/streams?channel= $+ $1)) {
    hadd $v1 channel #
    hadd $v1 stream $1
  }
}

Last edited by Dazuz; 15/03/16 07:25 PM.
Joined: Jun 2014
Posts: 77
K
Babel fish
Offline
Babel fish
K
Joined: Jun 2014
Posts: 77
Thanks @Dazuz


Link Copied to Clipboard