Guest User

Twitch.tv Stream Channel Status Checker

a guest
Oct 19th, 2014
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 16.83 KB | None | 0 0
  1. ON !*:TEXT:*:#: {
  2.   tokenize 32 $strip($1-,burci)
  3.   if ($1 == !cstream) {
  4.     if (!$2) { .msg $chan [ $+ $nick $+ ]: Error, Not enough parameteres, try again and enter the stream channel to search! | return }
  5.     .ignore -cu6 $nick
  6.     twitch_stream_chan $nick $chan $2
  7.   }
  8. }
  9.  
  10. alias twitch_stream_chan {
  11.   if (!$1-) { return }
  12.   if ($me !ison $2) { return }
  13.   if ($1 !ison $2) { return }
  14.   var %u = https://api.twitch.tv/kraken/streams/ $+ $3
  15.   var %v = twc_ $+ $ticks
  16.   JSONOpen -ud %v %u
  17.   if (%JSONError) { .msg $2 [ $+ $1 $+ ]: Error, There was an problem while trying to connect to the twitch server, try again later! | goto end | return }
  18.   var %id = $json(%v,stream,_id)
  19.   var %viewers = $bytes($json(%v,stream,viewers),bd)
  20.   var %crdate = $replace($remove($json(%v,stream,created_at),$chr(122)),$chr(116),$chr(32))
  21.   var %ctime = $ctime(%crdate)
  22.   var %game = $json(%v,stream,channel,game)
  23.   var %name = $json(%v,stream,channel,display_name)
  24.   if (!%name) { var %name = $json(%v,stream,channel,name) }
  25.   var %status = $json(%v,stream,channel,status)
  26.   if ($len(%status) >= 80) { var %status = $left(%status,80) $+ ... }
  27.   var %followers = $json(%v,stream,channel,followers)
  28.   var %views = $json(%v,stream,channel,views)
  29.   var %updated = $replace($remove($json(%v,stream,channel,updated_at),$chr(122)),$chr(116),$chr(32))
  30.   var %ctime2 = $ctime(%updated)
  31.   if (%ctime2) { var %timeago_updated = $timeago($calc($ctime - %ctime2)).all | var %updated = $date(%ctime2,ddd ddoo mmm yyyy HH:nn:ss) }
  32.   if (%ctime) { var %timeago = $timeago($calc($ctime - %ctime)).all | var %crdate = $date(%ctime,ddd ddoo mmm yyyy HH:nn:ss) }
  33.   if (!%id) { .msg $2 [ $+ $1 $+ ]: The $qt($3) stream channel is currently OFFLINE. }
  34.   elseif (%id) {
  35.     .msg $2 [ $+ $1 $+ ]: Stream: $3 -=- Stream Status: Online -=- Stream Viewer(s): $iif(%viewers,$bytes($v1,bd),N/A) -=- Created on: $iif(%crdate,$v1,N/A) ( $+ $iif(%timeago,$v1,N/A) $+ )
  36.     .msg $2 [ $+ $1 $+ ]: Channel Name: $iif(%name,$v1,N/A) -=- Game: $iif(%game,$v1,N/A) -=- Channel Status: $iif(%status,$v1,N/A) -=- Follower(s): $iif(%followers,$bytes($v1,bd),0) -=- Viewer(s): $iif(%views,$bytes($v1,bd),0) -=- Updated on: $iif(%updated,$v1,N/A) ( $+ $iif(%timeago_updated,$v1,N/A) $+ )
  37.   }
  38.   :end
  39.   JSONClose %v
  40. }
  41.  
  42. alias timeago {
  43.   if (!$1) { return 0 }
  44.   if ($1) && ($1 !isnum) { return 0 }
  45.   if ($prop == all) {
  46.     var %s = $nduration($1)
  47.     var %s = $replacex(%s,wks,$chr(32) weeks.,wk,$chr(32) week.)
  48.     var %s = $replacex(%s,days,$chr(32) days.,day,$chr(32) day.)
  49.     if (*min* iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours.,hr,$chr(32) hour.) }
  50.     if (*min* !iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours,hr,$chr(32) hour) }
  51.     if (*sec* iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes.,min,$chr(32) minute.) }
  52.     if (*sec* !iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes,min,$chr(32) minute) }
  53.     var %s = $replacex(%s,secs,$chr(32) seconds,sec,$chr(32) second)
  54.     var %s = $replace(%s,$chr(46),$chr(44))
  55.     return $iif(%s,%s ago,0)
  56.   }
  57.   if ($1 <= 59) { return $1 $iif($1 == 1,second,seconds) ago }
  58.   if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) $iif($floor($calc($1 / 60)) == 1,minute,minutes) ago }
  59.   if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) $iif($round($calc($1 / 3600),0) == 1,hour,hours) ago }
  60.   if (($1 <= 2592000) && ($1 > 86399)) { return $floor($calc($1 / 86400)) $iif($floor($calc($1 / 86400)) > 1,days,day) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 86400))*86400)) / 3600),0) $iif($round($calc($calc($1 - $calc($floor($calc($1 / 86400))*86400)) / 3600),0) > 1,hours,hour) ago }
  61.   if (($1 <= 31540000) && ($1 > 2592000)) { return $floor($calc($1 / 2592000)) $iif($floor($calc($1 / 2592000)) > 1,months,month) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 2592000))*2592000)) / 86400),0) $iif($round($calc($calc($1 - $calc($floor($calc($1 / 2592000))*2592000)) / 86400),0) > 1,days,day) ago }
  62.   if ($1 > 31104000) { return $floor($calc($1 / 31104000)) $iif($floor($calc($1 / 31104000)) > 1,years,year) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 31104000))*31104000)) / 2592000),0) $iif($round($calc($calc($1 - $calc($floor($calc($1 / 31104000))*31104000)) / 2592000),0) > 1,months,month) ago }
  63. }
  64.  
  65.  
  66. alias JSONOpen {
  67.   var %switches = -
  68.   if (-* iswm $1) {
  69.     %switches = $1
  70.     tokenize 32 $2-
  71.   }
  72.   var %com = JSONHandler:: $+ $1, %error, %file, %rem
  73.   var %init = function init(a,b){errortext="";data="";url=b ? b : "";method="GET";headers=[];parsedJSON={};status=a;fso=new ActiveXObject("Scripting.FileSystemObject")}
  74.   var %read = function readFile(filename){var ado=new ActiveXObject("ADODB.Stream");ado.CharSet="utf-8";ado.Open();ado.LoadFromFile(filename);if(!ado.EOF){data=ado.ReadText();}ado.close()}
  75.   var %json = "object"!==typeof JSON&&(JSON={});(function(){function m(a){return 10>a?"0"+a:a}function t(a){p.lastIndex=0;return p.test(a)?'"'+a.replace(p,function(a){var c=u[a];return"string"===typeof c?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function q(a,l){var c,d,h,r,g=e,f,b=l[a];b&&"object"===typeof b&&"function"===typeof b.toJSON&&(b=b.toJSON(a));"function"===typeof k&&(b=k.call(l,a,b));switch(typeof b){case "string":return t(b);case "number":return isFinite(b)?String(b):"null";case "boolean":case "null":return String(b);case "object":if(!b)return"null";e+=n;f=[];if("[object Array]"===Object.prototype.toString.apply(b)){r=b.length;for(c=0;c<r;c+=1)f[c]=q(c,b)||"null";h=0===f.length?"[]":e?"[\n"+e+f.join(",\n"+e)+"\n"+g+"]":"["+f.join(",")+"]";e=g;return h}if(k&&"object"===typeof k)for(r=k.length,c=0;c<r;c+=1)"string"===typeof k[c]&&(d=k[c],(h=q(d,b))&&f.push(t(d)+(e?": ":":")+h));else for(d in b)Object.prototype.hasOwnProperty.call(b,d)&&(h=q(d,b))&&f.push(t(d)+(e?": ":":")+h);h=0===f.length?"{}":e?"{\n"+e+f.join(",\n"+e)+"\n"+g+"}":"{"+f.join(",")+"}";e=g;return h}}"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+m(this.getUTCMonth()+1)+"-"+m(this.getUTCDate())+"T"+m(this.getUTCHours())+":"+m(this.getUTCMinutes())+":"+m(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var s,p,e,n,u,k;"function"!==typeof JSON.stringify&&(p=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,u={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,l,c){var d;n=e="";if("number"===typeof c)for(d=0;d<c;d+=1)n+=" ";else"string"===typeof c&&(n=c);if((k=l)&&"function"!==typeof l&&("object"!==typeof l||"number"!==typeof l.length))throw Error("JSON.stringify");return q("",{"":a})});"function"!==typeof JSON.parse&&(s=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(a,e){function c(a,d){var g,f,b=a[d];if(b&&"object"===typeof b)for(g in b)Object.prototype.hasOwnProperty.call(b,g)&&(f=c(b,g),void 0!==f?b[g]=f:delete b[g]);return e.call(a,d,b)}var d;a=String(a);s.lastIndex=0;s.test(a)&&(a=a.replace(s,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return d=eval("("+a+")"),"function"===typeof e?c({"":d},""):d;throw new SyntaxError("JSON.parse");})})();
  76.   var %xhr = function xhr(){var a,b=['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'],c;for(a=0;a<b.length;a++){try{c=new ActiveXObject(b[a]);break}catch(e){}}if(typeof c==="undefined"){errortext = "Unable to locate an XMLHTTP object for use"}else{c.open(method,url,false);for(a=0;a<headers.length;a++){c.setRequestHeader(headers[a][0],headers[a][1])}c.send(data);if(c.status!==200){errortext="Unable to retrieve data - Server Error: " + c.status}else{status="Parsed";try{parsedJSON=JSON.parse(c.responseText)}catch(ee){errortext="Unable to parse Retrieved Data"}}}}
  77.   if (!$regex(%switches, /^-[ufbwd]*$/)) { %error = Invalid switches specified }
  78.   elseif ($regex(%switches, /([ufbwd])\1/)) { %error = Duplicate switch specified ( $+ $regml(1) $+ ) }
  79.   elseif ($regex(%switches, /([ufb])/g) > 1) { %error = Conflicting switches specified (- $+ $regml(1) $+ , - $+ $regml(2) $+ $iif($regml(3), $chr(44) - $+ $v1) $+ ) }
  80.   elseif (w isin %switches && u !isin %switches) { %error = Invalid switch (-w is only for use with -u) }
  81.   elseif ($0 < 2) { %error = Required parameters missing }
  82.   elseif (!$regex($1,/^[a-z\d_.-]+$/i)) { %error = Invalid name specified (Can only contant letters, numbers, _, ., and -) }
  83.   elseif ($com(%com)) { %error = Specified name in use }
  84.   elseif (u isin %switches && $0 > 2) { %error = Invalid URL specified. (Contains Spaces: $2-) }
  85.   elseif (f isin %switches && !$isfile($2-)) { %error = File not found: $2- }
  86.   elseif (b isin %switches && &* !iswm $2) { %error = Invalid binary variable specified (No '&' Prefix) }
  87.   elseif (b isin %switches && $0 > 2) { %error = Invalid binary variable specified (Contains Spaces: $2-) }
  88.   elseif (b isin %switches && $bvar($2, 0) < 1) { %error = Invalid binary variable specified (No content) }
  89.   elseif (!$JSON::ComOpen(%com, MSScriptControl.ScriptControl) || $comerr) { %error = Unable to create an instance of MSScriptControl.ScriptControl }
  90.   elseif (!$com(%com, language, 4, bstr, jscript) || $comerr) { %error = Unable to set ScriptControl's language to Javascript }
  91.   elseif (!$com(%com, addcode, 1, bstr, %init) || $comerr) { %error = Unable to add init() to ScriptControl }
  92.   elseif (!$com(%com, addcode, 1, bstr, %xhr) || $comerr) { %error = Unable to add xhr() to ScriptControl }
  93.   elseif (!$com(%com, addcode, 1, bstr, %read) || $comerr) { %error = Unable to add readFile() to ScriptControl }
  94.   elseif (!$com(%com, ExecuteStatement, 1, bstr, %JSON) || $comerr) { %error = Unable to Initalize the JSON parser object }
  95.   elseif (!$com(%com, ExecuteStatement, 1, bstr, $iif(u isin %switches, $+(init,$chr(40), "XHR", $chr(44), $qt($JSON::Escape($2)),$chr(41)), $+(init,$chr(40), "Parsed", $chr(44), "", $chr(41)))) || $comerr) { %error = Unable to initalize variables for ScriptControl }
  96.   else {
  97.     if (u isin %switches) {
  98.       if (w !isin %switches) {
  99.         var %i = $com(%com, ExecuteStatement, 1, bstr, $+(xhr,$chr(40),$chr(41)))
  100.         if (!%i || $comerr) { %error = Unable to retrieve data from $2 :: $com(%com).error :: $com(%com).errortext }
  101.         elseif (!$com(%com, eval, 1, bstr, errortext) || $com(%com).result) { %error = Unable to retrieve data $+ $iif($v1,: $v1,) }
  102.       }
  103.     }
  104.     else {
  105.       %file = $JSON::File($1)
  106.       if (f isin %switches) {
  107.         %file = $longfn($2)
  108.       }
  109.       elseif (b isin %switches) {
  110.         bwrite $qt(%file) 0 -1 $2
  111.         %rem = $true
  112.       }
  113.       else {
  114.         write -n $qt(%file) $2-
  115.         %rem = $true
  116.       }
  117.       if (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(readFile, $qt($JSON::Escape(%file)))) || $comerr) { %error = Unable to read contents of data-passing file }
  118.       elseif (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(parsedJSON=JSON.parse,data)) || $comerr) { %error = Unable to parse data into valid JSON }
  119.     }
  120.     if (d isin %switches) { $+(.timer,%com) 1 0 JSONClose $1 }
  121.   }
  122.   :error
  123.   %error = $iif($error, $v1, %error)
  124.   if (%rem && %file && $isfile(%file)) { .remove $qt(%file) }
  125.   if (%error) {
  126.     if ($timer(%com)) { $+(.timer,%com) off }
  127.     if ($com(%com)) {
  128.       set -eu0 $+(%,%com,::error) %error
  129.       .comclose $v1
  130.     }
  131.     else { set -eu0 %JSONError %error }
  132.   }
  133. }
  134. alias JSONURLOption {
  135.   var %com = JSONHandler:: $+ $1, %error, %head, %value, %x = 2
  136.  
  137.   if (!$com(%com)) { return }
  138.   unset % [ $+ [ %com ] $+ ] ::error
  139.   if ($0 < 3) { %error = Missing parameters }
  140.   elseif (!$com(%com, eval, 1, bstr, status) || $com(%com).result != XHR) { %error = HTTP Request already completed or wasn't specified }
  141.   elseif ($2 == method) {
  142.     if (!$regex($3-, /^(?:GET|POST|PUT|DELETE)$/i)) { %error = Invalid HTTP Request method Specified: $3- }
  143.     elseif (!$com(%com, ExecuteStatement, 1, bstr, method=" $+ $3 $+ ") || $comerr) { %error = Unable to set HTTP Request method }
  144.   }
  145.   else {
  146.     if (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(headers.push,[ $+ $qt($JSON::Escape($2)), $qt($JSON::Escape($3-)) $+ ])) || $comerr) { %error = Unable to set HTTP Header: %head $+ : $+ %value }
  147.   }
  148.   :error
  149.   %error = $iif($error, $v1, %error)
  150.   if (%error) {
  151.     reseterror
  152.     set -e $+(%,%com,::Error) %error
  153.   }
  154. }
  155. alias JSONGet {
  156.   var %switches -
  157.   if (-* iswm $1) {
  158.     %switches = $1
  159.     tokenize 32 $2-
  160.   }
  161.   var %com = JSONHandler:: $+ $1
  162.   var %file = $JSON::File($1)
  163.   var %error
  164.   var %rem
  165.   if ($com(%com)) {
  166.     if ($com(%com, eval, 1, bstr, status) && $com(%com).result !== XHR) { %error = HTTP Request already completed or wasn't specified }
  167.     elseif (!$regex(%switches, /^-[bf]*$/)) { %error = Invalid switches specified }
  168.     elseif ($regex(%switches, /([bf])\1/)) { %error = Duplicate switch specified ( $+ $regml(1) $+ ) }
  169.     elseif ($regex(%switches, /([bf])/g) > 1) { %error = Conflicting switches specified (- $+ $regml(1) $+ , - $+ $regml(2) $+ ) }
  170.     elseif (b isin %switches && &* !iswm $2) { %error = Invalid binary variable specified (No '&' Prefix) }
  171.     elseif (b isin %switches && $0 > 2) { %error = Invalid binary variable specified (Contains Spaces: $2-) }
  172.     elseif (f isin %switches && !$isfile($2-)) { %error = File not found: $2- }
  173.     else {
  174.       if (b isin %switches && $bvar($2,0)) {
  175.         bwrite $qt(%file) 0 -1 $2
  176.         %rem = $true
  177.       }
  178.       elseif (f isin %switches) { %file = $2- }      
  179.       elseif ($2-) {
  180.         write -n $qt(%file) $2-
  181.         %rem = $true
  182.       }
  183.       %file = $longfn(%file)
  184.       if ($isfile(%file) && (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(readFile,$qt($JSON::Escape(%file)))) || $comerr)) { %error = Unable to pass data to JSON Handler }
  185.       elseif (!$com(%com, ExecuteStatement, 1, bstr, xhr $+ $chr(40) $+ $chr(41)) || $comerr) { %error = Unable to retrieve data from specified URL :: $com(%com).error :: $com(%com).errortext }
  186.       elseif (!$com(%com, eval, 1, bstr, errortext) || $com(%com).result) { %error = $v1 }
  187.       if (%rem && $isfile(%file)) { .remove %file }
  188.     }
  189.   }
  190.   :error
  191.   %error = $iif($error, $v1, %error)
  192.   if (%error) {
  193.     reseterror
  194.     set -eu0 $+(%,%com,::Error) %error
  195.   }
  196. }
  197. alias JSON {
  198.   var %com, %x = 1, %i = 0, %get = parsedJSON, %tok, %res
  199.   if ($regex($1,/^\d+$/) && $0 === 1) {
  200.     while ($com(%x)) {
  201.       if (JSONHandler::* iswm $v1) {
  202.         %com = $v2
  203.         inc %i
  204.         if (%i === $1) { return %com }
  205.       }
  206.       inc %x
  207.     }
  208.     return $iif($1 == 0, %i)
  209.   }
  210.   elseif ($regex($1, /^JSONHandler::CHILD::([^:]+)::(.*)$/)) {
  211.     %com = $regml(1)
  212.     %get = $regml(2)
  213.   }
  214.   else { %com = JSONHandler:: $+ $1 }
  215.   if ($com(%com)) {
  216.     if ($0 == 1) {
  217.       if ($prop == isChild) { return $iif($regex($1, /^JSONHandler::CHILD::([^:]+)::(.*)$/), $true, $false) }
  218.       elseif ($prop == error) { return $iif($(,$+(%,%com,::error)), $true,$false) }
  219.       elseif ($prop == errortext) { return $(,$+(%,%com,::error)) }
  220.       elseif ($com($1)) { return $1 }
  221.     }
  222.     elseif (!$com(%com, eval, 1, bstr, status) || $com(%com).result != parsed) { set -eu0 $+(%,%com,::error) JSON Handler waiting for HTTP Request }
  223.     else {
  224.       %x = 2
  225.       while (%x <= $0) {
  226.         %tok = $(,$ $+ %x)
  227.         if (!$regex(%tok, /^\d+$/)) {
  228.           %tok = $qt($replace(%tok,\,\\,",\"))
  229.         }
  230.         %get = $+(%get,[,%tok,])
  231.         inc %x
  232.       }
  233.       if (!$com(%com, eval, 1, bstr, %get) || $comerr) { set -e $+(%,%com,::error) Invalid Item|index specified }
  234.       else {
  235.         %res = $com(%com).result
  236.         if (%res == [object]) { return JSONHandler::CHILD:: $+ $1 $+ :: $+ %get }
  237.         else { return %res }
  238.       }
  239.     }
  240.   }
  241. }
  242. alias JSONClose {
  243.   var %com = JSONHandler:: $+ $1
  244.   unset % [ $+ [ %com ] $+ ] ::*
  245.   if ($com(%com)) { .comclose $v1 }
  246.   if ($timer(%com)) { $+(.timer,%com) off }
  247. }
  248. alias JSONList {
  249.   var %x = 1, %i = 0
  250.   while ($com(%x)) {
  251.     if (JSONHandler::* iswm $v1) {
  252.       inc %i
  253.       echo $color(info text) -a * # $+ %i : $regsubex($v2, /^JSONHandler::/,)
  254.     }
  255.     inc %x
  256.   }
  257.   if (!%i) { echo $color(info text) -a * No active JSON handlers }  
  258. }
  259. alias JSON::ComOpen { .comopen $1- | if ($com($1) && !$comerr) { return $true } | :error | reseterror | if ($com($1)) { .comclose $1 } }
  260. alias JSON::Escape { return $replace($1,\,\\,",\") }
  261. alias JSON::File { var %a = 1 | while ($isfile(JSON $+ $1 $+ %a $+ .json)) { inc %a } | return $+(JSON, $1, %a, .json) }
  262. alias JSON::Funct { var %a = $1 $+ $chr(40), %i = 1 | while (%i < $0) { inc %i | %a = $+(%a,$iif(%i > 2,$chr(44)),$(, $ $+ %i)) } | return %a $+ $chr(41) }
Add Comment
Please, Sign In to add comment