mIRC Home    About    Download    Register    News    Help

Topic Options
#259030 - 28/09/16 10:26 AM [Twitch]follower script help
x3pos Offline
Babel fish

Registered: 17/01/16
Posts: 79
this is script doesnt work what is wrong?

Code:
ON *:PART:#: {
  if ($nick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:KICK:#: {
  if ($knick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:JOIN:#: {
  if ($nick == $me) && (%stream_chan_ [ $+ [ $chan ] ]) && (%stream_auto_ [ $+ [ $chan ] ]) { .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ] }
}

ON !*:TEXT:!*:#: {
  if ($1 == !autofollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, try again and use ON or OFF options! | return }
    var %opt = $2
    if (%opt !== ON) && (%opt !== OFF) { .msg $chan ( $+ $nick $+ ): Error, Incorrect parameters, try again and use ONLY the options ON or OFF. | return }
    if (%opt == ON) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already running! }
      else {
        set %stream_auto_ [ $+ [ $chan ] ] $ctime
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been enabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
    if (%opt == OFF) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (!%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already NOT running! }
      else {
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] off
        unset %stream_auto_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been disabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
  }
  if ($1 == !setstreamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the Twitch Channel correctly! | return }
    if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, You must first disable the AUTO-FOLLOW-MESSAGE module and then change the stream channel! | return }
    set %stream_chan_ [ $+ [ $chan ] ] $2
    .msg $chan ( $+ $nick $+ ): The Twitch Channel has been set, now use !AutoFollow command to enable/disable the AUTO-FOLLOW-WELCOME module.
  }
  if ($1 == !streamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any Twitch Channel has been set! | return }
    .msg $chan ( $+ $nick $+ ): The $chan Twitch Stream Channel is now:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ 
  }
  if ($1 == !followed) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the nickname correctly! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hfind(%h,$2)) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The $qt( $+ $2 $+ ) nickname is NOT on my database! | return }
    var %fl = $hget(%h,$2)
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The $qt( $+ $2 $+ ) nickname followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
  if ($1 == !lastfollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_last_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hget(%h,1).item) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The last followed nickname cannot be found on my database! | return }
    var %fl = $hget(%h,1).data
    var %fln = $hget(%h,1).item
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The last follower nickname is $qt( $+ %fln $+ ) followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
}

alias twitch_check_new {
  if (!$1-) { return }
  if (!%stream_auto_ [ $+ [ $1 ] ]) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  if ($me !ison $1) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  var %u = https://api.twitch.tv/kraken/channels/ $+ $2 $+ /follows?limit=1&nocache= $+ $ticks
  var %v = twc_ $+ $ticks
  JSONOpen -ud %v %u
  if (%JSONError) { goto end | return }
  var %followed = $json(%v,follows,0,created_at)
  if (%followed) {
    var %followed = $replace($remove(%followed,$chr(122)),$chr(116),$chr(32))
    var %ctime = $ctime(%followed)
    var %followed = $date(%ctime,ddd ddoo mmm yyyy HH:nn:ss)
    var %followed_ago = $_timeago($calc($ctime - %ctime)).all
  }
  var %type = $json(%v,follows,0,user,type)
  var %name = $json(%v,follows,0,user,display_name)
  if (!%name) { var %name = $json(%v,follows,0,user,name) }
  if (!%name) { goto end | return }
  var %uu = https://api.twitch.tv/kraken/streams/ $+ $2
  var %vv = twl_ $+ $ticks
  JSONOpen -ud %vv %uu
  if (%JSONError) { goto end | return }
  if (!$hget(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hmake ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] 500 }
  if ($hfind(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ],%name)) { goto end | return }
  hadd -m ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  if ($hget(ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hfree $v1 }
  hadd -m ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  .msg $1  $+ %name $+  Kanalı takip ediyor.Aramıza Hoşgeldin bakiyim!
  :end
  JSONClose %v
  JSONClose %vv
}

alias _timeago {
  if (!$1) { return 0 }
  if ($1) && ($1 !isnum) { return 0 }
  if ($prop == all) {
    var %s = $nduration($1)
    var %s = $replacex(%s,wks,$chr(32) weeks.,wk,$chr(32) week.)
    var %s = $replacex(%s,days,$chr(32) days.,day,$chr(32) day.)
    if (*min* iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours.,hr,$chr(32) hour.) }
    if (*min* !iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours,hr,$chr(32) hour) }
    if (*sec* iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes.,min,$chr(32) minute.) }
    if (*sec* !iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes,min,$chr(32) minute) }
    var %s = $replacex(%s,secs,$chr(32) seconds,sec,$chr(32) second)
    var %s = $replace(%s,$chr(46),$chr(44))
    return $iif(%s,%s ago,0)
  }
  if ($1 <= 59) { return $1 $iif($1 == 1,second,seconds) ago }
  if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) $iif($floor($calc($1 / 60)) == 1,minute,minutes) ago }
  if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) $iif($round($calc($1 / 3600),0) == 1,hour,hours) ago }
  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 }
  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 }
  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 }
}

alias JSONOpen {
  var %init = function init(a,b){errortext="";data="";url=b ? b : "";method="GET";headers=[];parsedJSON={};status=a;fso=new ActiveXObject("Scripting.FileSystemObject")}
  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()}
  var %json = "object"!==typeof JSON&&(JSON={});(function(){if(!JSON.hasOwnProperty("parse")||!JSON.parse)JSON.parse=function(t){if(/^[\],:{}\s]*$/.test((t=(String(t)).replace(/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})).replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){return eval('('+t+')')}throw new SyntaxError('parse')}}())
  var %xhr = function xhr(){var a,b=['MSXML2.SERVERXMLHTTP.6.0','MSXML2.SERVERXMLHTTP.3.0','MSXML2.SERVERXMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'],c;for(a=0;a<b.length;a++){try{c=xhrObj=new ActiveXObject(b[a]);break}catch(e){}}if(typeof c==="undefined"){status="error";errortext="Unable to locate an XMLHTTP object for use"}else{c.open(method,url,false);for(a=0;a<headers.length;a++){try{c.setRequestHeader(headers[a][0],headers[a][1])}catch(ee){status="error";errortext=ee.message; return}}c.send(data);if(c.status!==200){status="error";errortext="Unable to retrieve data - Server Error: " + c.status}else{status="Parsed";try{parsedJSON=JSON.parse(c.responseText)}catch(ee){status="error";errortext="Unable to parse Retrieved Data"}}}}
  var %switches = -
  var %com
  var %error
  var %close = $false
  var %file
  var %rem
  var %i

  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  var %com = JSONHandler:: $+ $1

  if (!$regex(%switches, /^-[ufbwd]*$/)) {
    %error = Invalid switches specified
  }
  elseif ($regex(%switches, /([ufbwd])\1/)) {
    %error = Duplicate switch specified ( $+ $regml(1) $+ )
  }
  elseif ($regex(%switches, /([ufb])/g) > 1) {
    %error = Conflicting switches specified (- $+ $regml(1) $+ , - $+ $regml(2) $+ $iif($regml(3), $chr(44) - $+ $v1) $+ )
  }
  elseif (w isin %switches && u !isin %switches) {
    %error = Invalid switch (-w is only for use with -u)
  }
  elseif ($0 < 2) {
    %error = Required parameters missing
  }
  elseif (!$regex($1,/^[a-z\d_.-]+$/i)) {
    %error = Invalid name specified (Can only contant letters, numbers, _, ., and -)
  }
  elseif ($com(%com)) {
    %error = Specified name in use
  }
  elseif (u isin %switches && $0 > 2) {
    %error = Invalid URL specified. (Contains Spaces: $2-)
  }
  elseif (f isin %switches && !$isfile($2-)) {
    %error = File not found: $2-
  }
  elseif (b isin %switches && &* !iswm $2) {
    %error = Invalid binary variable specified (No '&' Prefix)
  }
  elseif (b isin %switches && $0 > 2) {
    %error = Invalid binary variable specified (Contains Spaces: $2-)
  }
  elseif (b isin %switches && $bvar($2, 0) < 1) {
    %error = Invalid binary variable specified (No content)
  }
  else {
    %close = $true
    if (!$JSON::ComOpen(%com, MSScriptControl.ScriptControl) || $comerr) {
      %error = Unable to create an instance of MSScriptControl.ScriptControl
    }
    elseif (!$com(%com, language, 4, bstr, jscript) || $comerr) {
      %error = Unable to set ScriptControl's language to Javascript
    } 
    elseif (!$com(%com, addcode, 1, bstr, %init) || $comerr) {
      %error = Unable to add init() to ScriptControl
    }
    elseif (!$com(%com, addcode, 1, bstr, %xhr) || $comerr) {
      %error = Unable to add xhr() to ScriptControl
    }
    elseif (!$com(%com, addcode, 1, bstr, %read) || $comerr) {
      %error = Unable to add readFile() to ScriptControl
    }
    elseif (!$com(%com, ExecuteStatement, 1, bstr, %JSON) || $comerr) {
      %error = Unable to Initalize the JSON parser object
    }
    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
    }
    elseif (u !isin %switches) {
      %file = $JSON::File($1)
      %rem = $true
      if (f isin %switches) {
        %file = $longfn($2)
        %rem = $false
      }
      elseif (b isin %switches) {
        bwrite $qt(%file) 0 -1 $2
      }
      else {
        write -n $qt(%file) $2-
      }
      if (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(readFile, $qt($JSON::Escape(%file)))) || $comerr) {
        %error = Unable to read contents of data-passing file
      }
      elseif (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(parsedJSON=JSON.parse, data)) || $comerr) {
        %error = Unable to parse data into valid JSON
      }
    }
    elseif (w !isin %switches) {
      if (!$com(%com, ExecuteStatement, 1, bstr, $+(xhr,$chr(40),$chr(41))) || $comerr) {
        %error = Unable to start the web request for $2
      }
      elseif (!$com(%com, eval, 1, bstr, errortext) || $com(%com).result) {
        %error = Unable to retrieve data $+ $iif($v1,: $v1,)
      }
    }
    if (d isin %switches) {
      $+(.timer,%com) 1 0 JSONClose $1
    }
  }
  :error
  set -eu0 %JSONError $iif($error, $v1, %error)
  if (%rem && %file && $isfile(%file)) {
    .remove $qt(%file)
  }
  if (%JSONError && %close && $com(%com)) { 
    set -eu0 $+(%,%com,::error) %JSONError
    .comclose %com
  }
}
alias JSONError {
  return %JSONError
}

alias JSONURLOption {
  var %com = JSONHandler:: $+ $1
  var %error
  var %head
  var %value
  var %x = 2

  if (!$com(%com)) {
    return
  }
  unset % [ $+ [ %com ] $+ ] ::error
  if ($0 < 3) {
    %error = Missing parameters
  }
  elseif (!$com(%com, eval, 1, bstr, status) || $com(%com).result != XHR) {
    %error = HTTP Request already completed or wasn't specified
  }
  elseif ($2 == method) {
    if (!$regex($3-, /^(?:GET|POST|PUT|DELETE)$/i)) {
      %error = Invalid HTTP Request method Specified: $3-
    }
    elseif (!$com(%com, ExecuteStatement, 1, bstr, method=" $+ $upper($3) $+ ") || $comerr) {
      %error = Unable to set HTTP Request method
    }
  }
  else {
    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
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  if (%error) {
    reseterror
    set -e $+(%,%com,::Error) %error
  }
}
alias JSONGet { 
  var %switches -
  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  var %com = JSONHandler:: $+ $1
  var %file = $JSON::File($1)
  var %error
  var %rem = $true
  if ($com(%com)) {
    if ($com(%com, eval, 1, bstr, status) && $com(%com).result !== XHR) {
      %error = HTTP Request already completed or wasn't specified
    }
    elseif (!$regex(%switches, /^-[bf]*$/)) {
      %error = Invalid switches specified
    }
    elseif ($regex(%switches, /([bf])\1/)) {
      %error = Duplicate switch specified ( $+ $regml(1) $+ )
    }
    elseif ($regex(%switches, /([bf])/g) > 1) {
      %error = Conflicting switches specified (- $+ $regml(1) $+ , - $+ $regml(2) $+ )
    }
    elseif (b isin %switches && &* !iswm $2) {
      %error = Invalid binary variable specified (No '&' Prefix)
    }
    elseif (b isin %switches && $0 > 2) {
      %error = Invalid binary variable specified (Contains Spaces: $2-)
    }
    elseif (f isin %switches && !$isfile($2-)) {
      %error = File not found: $2-
    }
    else {
      if (b isin %switches && $bvar($2,0)) {
        bwrite $qt(%file) 0 -1 $2
      }
      elseif (f isin %switches) {
        %file = $longfn($2-)
        %rem = false
      }      
      elseif ($2-) {
        write -n $qt(%file) $2-
      }
      %file = $longfn(%file)
      if ($isfile(%file) && (!$com(%com, ExecuteStatement, 1, bstr, $JSON::Funct(readFile,$qt($JSON::Escape(%file)))) || $comerr)) {
        %error = Unable to pass data to JSON Handler
      }
      elseif (!$com(%com, ExecuteStatement, 1, bstr, xhr $+ $chr(40) $+ $chr(41)) || $comerr) {
        %error = Unable to retrieve data from specified URL 
      }
      elseif (!$com(%com, eval, 1, bstr, errortext) || $com(%com).result) {
        %error = $v1
      }
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  reseterror
  if (%rem && $isfile(%file)) { 
    .remove %file 
  }
  if (%error) {
    set -eu0 $+(%,%com,::Error) %error
  }
}
alias JSON {
  var %com
  var %x = 1
  var %i = 0
  var %get = parsedJSON
  var %tok
  var %res
  var %LTLError
  if ($regex($1,/^\d+$/) && $0 === 1) {
    while ($com(%x)) {
      if (JSONHandler::* iswm $v1) {
        %com = $v2
        inc %i
        if (%i === $1) { 
          return $mid(%com,14-)
        }
      }
      inc %x
    }
    return $iif($1 == 0, %i)
  }
  elseif ($regex($1, /^JSONHandler::CHILD::([^:]+)::(.*)$/)) {
    %com = $regml(1)
    %get = $regml(2)
  }
  else {
    %com = JSONHandler:: $+ $1
  }
  if ($com(%com)) {
    if ($0 == 1) {
      if ($prop == isChild) {
        return $iif($regex($1, /^JSONHandler::CHILD::([^:]+)::(.*)$/), $true, $false)
      }
      elseif ($prop == error || $prop === errormsg) {
        return $(,$+(%,%com,::error))
      }
      elseif ($com($1)) {
        return $1
      }
    }
    elseif (!$com(%com, eval, 1, bstr, status)) {
      set -eu0 $+(%,%com,::error) Unable to get status of JSON handler
    }
    elseif ($com(%com).result == error) {
      noop $com(%com, eval, 1, bstr, errortext)
      set -eu0 $+(%, %com, ::error) $com(%com).result
    }
    elseif (!$com(%com, eval, 1, bstr, status) || $com(%com).result != parsed) {
      set -eu0 $+(%,%com,::error) JSON Handler waiting for HTTP Request
    }
    else {
      %x = 2
      while (%x <= $0) {
        %tok = $(,$ $+ %x)
        if (!$regex(%tok, /^\d+$/)) {
          %tok = $qt($replace(%tok,\,\\,",\"))
        }
        %get = $+(%get,[,%tok,])
        inc %x
      }
      if (!$com(%com, eval, 1, bstr, %get) || $comerr) {
        set -eu0 $+(%,%com,::error) Invalid Item|index specified
      }
      else {
        %LTLError = $true
        %res = $com(%com).result
        %LTLError = $false
        if (%res == [object]) {
          return JSONHandler::CHILD:: $+ $1 $+ :: $+ %get
        }
        else {
          return %res
        }
      }
    }
  }
  return
  :error
  set -eu0 $+(%,%com,::error) $iif(%LTLError, Line to Long; truncated at 4000 bytes, $error)
  reseterror
  if (%LTLError) {
    %res = $left($com(%com).result, 4000)
  }
}
alias JSONClose {
  var %com = JSONHandler:: $+ $1
  unset % [ $+ [ %com ] $+ ] ::*
  if ($com(%com)) { 
    .comclose $v1 
  }
  if ($timer(%com)) { 
    $+(.timer,%com) off 
  }
}
alias JSONList {
  var %x = 1, %i = 0
  while ($com(%x)) {
    if (JSONHandler::* iswm $v1) {
      inc %i
      echo $color(info text) -a * # $+ %i : $regsubex($v2, /^JSONHandler::/,)
    }
    inc %x
  }
  if (!%i) {
    echo $color(info text) -a * No active JSON handlers
  }   
}
on *:Start:{
  unset %JSONHandler::*
}
alias -l JSON::ComOpen { 
  .comopen $1- 
  if ($com($1) && !$comerr) { 
    return $true
  } 
  :error 
  reseterror 
  if ($com($1)) { 
    .comclose $1 
  }
}
alias -l JSON::Escape { 
  return $replace($1,\,\\,",\") 
}
alias -l JSON::File { 
  var %a = 1 
  while ($isfile($scriptdirJSON $+ $1 $+ %a $+ .json)) { inc %a } 
  return $+($scriptdirJSON, $1, %a, .json) 
}
alias -l JSON::Funct {
  var %a, %i = 1
  while (%i < $0) {
    inc %i 
    %a = $addtok(%a, $(, $ $+ %i), 44)
  } 
  return $1 $+ ( $+ %a $+ )
}

Top
#259032 - 28/09/16 03:38 PM Re: [Twitch]follower script help [Re: x3pos]
FroggieDaFrog Offline
Hoopy frood

Registered: 16/04/10
Posts: 910
Loc: USA
First, this script includes my JSON parser and it should not. Instead, load my JSON parser as a separate script from HERE

Second, twitch now requires a Client-ID header to be sent with requests to their APIs:

Code:
ON *:PART:#: {
  if ($nick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:KICK:#: {
  if ($knick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:JOIN:#: {
  if ($nick == $me) && (%stream_chan_ [ $+ [ $chan ] ]) && (%stream_auto_ [ $+ [ $chan ] ]) { .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ] }
}

ON !*:TEXT:!*:#: {
  if ($1 == !autofollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, try again and use ON or OFF options! | return }
    var %opt = $2
    if (%opt !== ON) && (%opt !== OFF) { .msg $chan ( $+ $nick $+ ): Error, Incorrect parameters, try again and use ONLY the options ON or OFF. | return }
    if (%opt == ON) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already running! }
      else {
        set %stream_auto_ [ $+ [ $chan ] ] $ctime
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been enabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
    if (%opt == OFF) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (!%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already NOT running! }
      else {
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] off
        unset %stream_auto_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been disabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
  }
  if ($1 == !setstreamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the Twitch Channel correctly! | return }
    if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, You must first disable the AUTO-FOLLOW-MESSAGE module and then change the stream channel! | return }
    set %stream_chan_ [ $+ [ $chan ] ] $2
    .msg $chan ( $+ $nick $+ ): The Twitch Channel has been set, now use !AutoFollow command to enable/disable the AUTO-FOLLOW-WELCOME module.
  }
  if ($1 == !streamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any Twitch Channel has been set! | return }
    .msg $chan ( $+ $nick $+ ): The $chan Twitch Stream Channel is now:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ 
  }
  if ($1 == !followed) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the nickname correctly! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hfind(%h,$2)) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The $qt( $+ $2 $+ ) nickname is NOT on my database! | return }
    var %fl = $hget(%h,$2)
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The $qt( $+ $2 $+ ) nickname followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
  if ($1 == !lastfollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_last_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hget(%h,1).item) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The last followed nickname cannot be found on my database! | return }
    var %fl = $hget(%h,1).data
    var %fln = $hget(%h,1).item
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The last follower nickname is $qt( $+ %fln $+ ) followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
}

alias twitch_check_new {
  if (!$1-) { return }
  if (!%stream_auto_ [ $+ [ $1 ] ]) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  if ($me !ison $1) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  var %u = https://api.twitch.tv/kraken/channels/ $+ $2 $+ /follows?limit=1&nocache= $+ $ticks
  var %v = twc_ $+ $ticks
  JSONOpen -uwd %v %u
  JSONUrlHeader %v Client-ID e8e68mu4x2sxsewuw6w82wpfuyprrdx
  JSONUrlGet %v
  if (%JSONError) { goto end | return }
  var %followed = $json(%v,follows,0,created_at)
  if (%followed) {
    var %followed = $replace($remove(%followed,$chr(122)),$chr(116),$chr(32))
    var %ctime = $ctime(%followed)
    var %followed = $date(%ctime,ddd ddoo mmm yyyy HH:nn:ss)
    var %followed_ago = $_timeago($calc($ctime - %ctime)).all
  }
  var %type = $json(%v,follows,0,user,type)
  var %name = $json(%v,follows,0,user,display_name)
  if (!%name) { var %name = $json(%v,follows,0,user,name) }
  if (!%name) { goto end | return }

  var %uu = https://api.twitch.tv/kraken/streams/ $+ $2
  var %vv = twl_ $+ $ticks
  JSONOpen -uwd %vv %uu
  JSONUrlHeader %vv Client-ID e8e68mu4x2sxsewuw6w82wpfuyprrdx
  JSONUrlGet %vv
  if (%JSONError) { goto end | return }
  if (!$hget(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hmake ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] 500 }
  if ($hfind(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ],%name)) { goto end | return }
  hadd -m ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  if ($hget(ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hfree $v1 }
  hadd -m ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  .msg $1  $+ %name $+  Kanal&#305; takip ediyor.Aram&#305;za Ho&#351;geldin bakiyim!
  :end
  JSONClose %v
  JSONClose %vv
}

alias _timeago {
  if (!$1) { return 0 }
  if ($1) && ($1 !isnum) { return 0 }
  if ($prop == all) {
    var %s = $nduration($1)
    var %s = $replacex(%s,wks,$chr(32) weeks.,wk,$chr(32) week.)
    var %s = $replacex(%s,days,$chr(32) days.,day,$chr(32) day.)
    if (*min* iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours.,hr,$chr(32) hour.) }
    if (*min* !iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours,hr,$chr(32) hour) }
    if (*sec* iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes.,min,$chr(32) minute.) }
    if (*sec* !iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes,min,$chr(32) minute) }
    var %s = $replacex(%s,secs,$chr(32) seconds,sec,$chr(32) second)
    var %s = $replace(%s,$chr(46),$chr(44))
    return $iif(%s,%s ago,0)
  }
  if ($1 <= 59) { return $1 $iif($1 == 1,second,seconds) ago }
  if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) $iif($floor($calc($1 / 60)) == 1,minute,minutes) ago }
  if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) $iif($round($calc($1 / 3600),0) == 1,hour,hours) ago }
  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 }
  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 }
  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 }
}


Edited by FroggieDaFrog (28/09/16 03:39 PM)
_________________________
I am SReject
My Stuff

Top
#259055 - 30/09/16 08:00 PM Re: [Twitch]follower script help [Re: x3pos]
x3pos Offline
Babel fish

Registered: 17/01/16
Posts: 79
how to find my cliend id

Top
#259056 - 30/09/16 08:44 PM Re: [Twitch]follower script help [Re: x3pos]
FroggieDaFrog Offline
Hoopy frood

Registered: 16/04/10
Posts: 910
Loc: USA
Create a new twitch-app or just use the one I gave in the above post
_________________________
I am SReject
My Stuff

Top
#259057 - 30/09/16 09:33 PM Re: [Twitch]follower script help [Re: x3pos]
x3pos Offline
Babel fish

Registered: 17/01/16
Posts: 79
Code:
ON *:PART:#: {
  if ($nick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:KICK:#: {
  if ($knick == $me) { unset %stream_auto_ [ $+ [ $chan ] ] | .timer[FOLLOWERS_CHECK_ [ $+ [ $chan ] ] off }
}

ON *:JOIN:#: {
  if ($nick == $me) && (%stream_chan_ [ $+ [ $chan ] ]) && (%stream_auto_ [ $+ [ $chan ] ]) { .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ] }
}

ON !*:TEXT:!*:#: {
  if ($1 == !autofollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, try again and use ON or OFF options! | return }
    var %opt = $2
    if (%opt !== ON) && (%opt !== OFF) { .msg $chan ( $+ $nick $+ ): Error, Incorrect parameters, try again and use ONLY the options ON or OFF. | return }
    if (%opt == ON) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already running! }
      else {
        set %stream_auto_ [ $+ [ $chan ] ] $ctime
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] 0 5 twitch_check_new $chan %stream_chan_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been enabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
    if (%opt == OFF) {
      if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any $qt(Stream Channel) set, Please use the !SetStreamChan command to set one! | return }
      if (!%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, The AUTO-FOLLOW-WELCOME module is already NOT running! }
      else {
        .timer[FOLLOWERS_CHECK_ $+ $chan $+ ] off
        unset %stream_auto_ [ $+ [ $chan ] ]
        .msg $chan ( $+ $nick $+ ): The AUTO-FOLLOW-WELCOME module has been disabled. - (Twitch Channel:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ )
      }
    }
  }
  if ($1 == !setstreamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the Twitch Channel correctly! | return }
    if (%stream_auto_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, You must first disable the AUTO-FOLLOW-MESSAGE module and then change the stream channel! | return }
    set %stream_chan_ [ $+ [ $chan ] ] $2
    .msg $chan ( $+ $nick $+ ): The Twitch Channel has been set, now use !AutoFollow command to enable/disable the AUTO-FOLLOW-WELCOME module.
  }
  if ($1 == !streamchan) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!%stream_chan_ [ $+ [ $chan ] ]) { .msg $chan ( $+ $nick $+ ): Error, There is NOT any Twitch Channel has been set! | return }
    .msg $chan ( $+ $nick $+ ): The $chan Twitch Stream Channel is now:  $+ %stream_chan_ [ $+ [ $chan ] ] $+ 
  }
  if ($1 == !followed) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    if (!$2) { .msg $chan ( $+ $nick $+ ): Error, Not enough parameters, try again and enter the nickname correctly! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hfind(%h,$2)) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The $qt( $+ $2 $+ ) nickname is NOT on my database! | return }
    var %fl = $hget(%h,$2)
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The $qt( $+ $2 $+ ) nickname followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
  if ($1 == !lastfollow) {
    if ($nick !isop $chan) { .msg $chan ( $+ $nick $+ ): Error, You are NOT an channel operator! | return }
    var %stc = %stream_chan_ [ $+ [ $chan ] ]
    var %h = ls_followers_last_ [ $+ [ %stc ] $+ ] _ [ $+ [ $chan ] ]
    if (!$hget(%h)) { .msg $chan ( $+ $nick $+ ): There is NOT any nickname yet on my database! | return }
    if (!$hget(%h,1).item) { .msg $chan ( $+ $nick $+ ): Error, Cannot find, The last followed nickname cannot be found on my database! | return }
    var %fl = $hget(%h,1).data
    var %fln = $hget(%h,1).item
    var %timeago = $_timeago($calc($ctime - %fl)).all
    .msg $chan ( $+ $nick $+ ): The last follower nickname is $qt( $+ %fln $+ ) followed the Twitch Channel on  $+ $date(%fl,ddd ddoo mmm yyyy HH:nn:ss) $+  $iif(%timeago,( $+ $v1 $+ ))
  }
}

alias twitch_check_new {
  if (!$1-) { return }
  if (!%stream_auto_ [ $+ [ $1 ] ]) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  if ($me !ison $1) { .timer[FOLLOWERS_CHECK_ $+ $1 $+ ] off | return }
  var %u = https://api.twitch.tv/kraken/channels/ $+ $2 $+ /follows?limit=1&nocache= $+ $ticks
  var %v = twc_ $+ $ticks
  JSONOpen -uwd %v %u
  JSONUrlHeader %v Client-ID lfc6xxxxxxxxxxxxxxxxxxxxx
  JSONUrlGet %v
  if (%JSONError) { goto end | return }
  var %followed = $json(%v,follows,0,created_at)
  if (%followed) {
    var %followed = $replace($remove(%followed,$chr(122)),$chr(116),$chr(32))
    var %ctime = $ctime(%followed)
    var %followed = $date(%ctime,ddd ddoo mmm yyyy HH:nn:ss)
    var %followed_ago = $_timeago($calc($ctime - %ctime)).all
  }
  var %type = $json(%v,follows,0,user,type)
  var %name = $json(%v,follows,0,user,display_name)
  if (!%name) { var %name = $json(%v,follows,0,user,name) }
  if (!%name) { goto end | return }

  var %uu = https://api.twitch.tv/kraken/streams/ $+ $2
  var %vv = twl_ $+ $ticks
  JSONOpen -uwd %vv %uu
  JSONUrlHeader %vv Client-ID lfc6xxxxxxxxxxxxxxxxxxxxxxxxxx
  JSONUrlGet %vv
  if (%JSONError) { goto end | return }
  if (!$hget(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hmake ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] 500 }
  if ($hfind(ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ],%name)) { goto end | return }
  hadd -m ls_followers_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  if ($hget(ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ])) { hfree $v1 }
  hadd -m ls_followers_last_ [ $+ [ $2 ] $+ ] _ [ $+ [ $1 ] ] %name $ctime(%followed)
  .msg $1  $+ %name $+  Kanal&#305; takip ediyor.Aram&#305;za Ho&#351;geldin bakiyim!
  :end
  JSONClose %v
  JSONClose %vv
}

alias _timeago {
  if (!$1) { return 0 }
  if ($1) && ($1 !isnum) { return 0 }
  if ($prop == all) {
    var %s = $nduration($1)
    var %s = $replacex(%s,wks,$chr(32) weeks.,wk,$chr(32) week.)
    var %s = $replacex(%s,days,$chr(32) days.,day,$chr(32) day.)
    if (*min* iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours.,hr,$chr(32) hour.) }
    if (*min* !iswm %s) { var %s = $replacex(%s,hrs,$chr(32) hours,hr,$chr(32) hour) }
    if (*sec* iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes.,min,$chr(32) minute.) }
    if (*sec* !iswm %s) { var %s = $replacex(%s,mins,$chr(32) minutes,min,$chr(32) minute) }
    var %s = $replacex(%s,secs,$chr(32) seconds,sec,$chr(32) second)
    var %s = $replace(%s,$chr(46),$chr(44))
    return $iif(%s,%s ago,0)
  }
  if ($1 <= 59) { return $1 $iif($1 == 1,second,seconds) ago }
  if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) $iif($floor($calc($1 / 60)) == 1,minute,minutes) ago }
  if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) $iif($round($calc($1 / 3600),0) == 1,hour,hours) ago }
  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 }
  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 }
  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 }
}




Code:
alias JSONVersion {
  if ($isid) {
    return $iif($1 != short,JSONForMirc v,v) $+ 0.2.41
  }
}
alias JSONError {
  if ($isid) {
    return %JSONError 
  }
}
alias -l COMOpenTry {
  if (!$len($com($1))) {
    if ($len($~adiircexe) && $appbits == 64) {
      .comopen $1 ScriptControl
    }
    else {
      .comopen $1 MSScriptControl.ScriptControl
    }
    if ($com($1) && !$comerr) {
      return $true
    }
  }
}
alias JSONOpen {
  if ($isid) return
  unset %JSONError
  debugger -i 0 Calling /JSONOpen $1-
  var %switches = -, %error, %com, %file
  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  if ($regex(%switches, ([^dbfuw\-]))) {
    %error = Invalid switches specified: $regml(1)
  }
  elseif ($regex(%switches, ([dbfuw]).*?\1)) {
    %error = Duplicate switch specified: $regml(1)
  }
  elseif ($regex(%switches, /([bfu])/g) > 1) {
    %error = Conflicting switches: $regml(1) $+ , $regml(2)
  }
  elseif (u !isin %switches && w isin %switches) {
    %error = -w switch can only be used with -u
  }
  elseif ($0 < 2) {
    %error = Missing Parameters
  }
  elseif (!$regex($1, /^[a-z][a-z\d_.-]+$/i)) {
    %error = Invalid handler name: Must start with a letter and contain only letters numbers _ . and -
  }
  elseif ($com(JSONHandler:: $+ $1)) {
    %error = Name in use
  }
  elseif (b isin %switches && $0 != 2) {
    %error = Invalid parameter: Binary variable names cannot contain spaces
  }
  elseif (b isin %switches && &* !iswm $2) {
    %error = Invalid parameters: Binary variable names start with &
  }
  elseif (b isin %switches && !$bvar($2, 0)) {
    %error = Invalid parameters: Binary variable is empty
  }
  elseif (f isin %switches && !$isfile($2-)) {
    %error = Invalid parameters: File doesn't exist
  }
  elseif (f isin %switches && !$file($2-).size) {
    %error = Invalid parameters: File is empty
  }
  elseif (u isin %switches && $0 != 2) {
    %error = Invalid parameters: URLs cannot contain spaces
  }
  else {
    if (!$COMOpenTry(JSONHandler:: $+ $1)) {
      %error = Unable to create an instance of MSScriptControl.ScriptControl
    }
    else {
      %com = JSONHandler:: $+ $1
      if (!$com(%com, language, 4, bstr, jscript) || $comerr) {
        %error = Unable to set ScriptControl's language to Javascript
      }
      elseif (!$com(%com, timeout, 4, bstr, 60000) || $comerr) {
        %error = Unable to set ScriptControl's timeout to 60seconds
      }
      elseif (!$com(%com, ExecuteStatement, 1, bstr, $JScript) || $comerr) {
        %error = Unable to add required javascript to the ScriptControl instance
      }
      elseif (u isincs %switches) {
        if (1 OK != $jstry(%com, $jscript(urlInit), $escape($2-).quote)) {
          %error = $gettok($v2, 2-, 32)
        }
        elseif (w !isincs %switches && 0 ?* iswm $jsTry(%com, $jscript(urlParse), status="error").withError) {
          %error = $gettok($v2, 2-, 32)
        }
      }
      elseif (f isincs %switches) {
        if (1 OK != $jstry(%com, $jscript(fileParse), $escape($longfn($2-)).quote)) {
          %error = $gettok($v2, 2-, 32)
        }
      }
      elseif (b isincs %switches) {
        %file = $tempfile
        bwrite $qt(%file) -1 -1 $2
        debugger %com Wrote $2 to $qt(%file)
        if (0 ?* iswm $jstry(%com, $jscript(fileParse), $escape(%file).quote)) {
          %error = $gettok($v2, 2-, 32)
        }
      }
      else {
        %file = $tempfile
        write -n $qt(%file) $2-
        debugger %com Wrote $2- to $qt(%file)
        if (0 ?* iswm $jstry(%com, $jscript(fileParse), $escape(%file).quote)) {
          %error = $gettok($v2, 2-, 32)
        }
      }
      if (!%error) {
        if (d isin %switches) {
          $+(.timer, %com) -o 1 0 JSONClose $1
        }
        Debugger -s %com Successfully created
      }
    }
  }
  :error
  %error = $iif($error, $error, %error)
  reseterror
  if (%file && $isfile(%file)) {
    .remove $qt(%file)
    debugger %com Removed $qt(%file)
  }
  if (%error) {
    if (%com && $com(%com)) {
      .comclose %com
    }
    set -eu0 %JSONError %error
    Debugger -e 0 /JSONOpen %switches $1- --RAISED-- %error
  }
}
alias JSONUrlMethod {
  if ($isid) return
  unset %JSONError
  debugger -i 0 Calling /JSONUrlMethod $1-
  var %error, %com
  if ($0 < 2) {
    %error = Missing parameters
  }
  elseif ($0 > 2) {
    %error = Too many parameters specified
  }
  elseif (!$regex($1, /^[a-z][a-z\d_.\-]+$/i)) {
    %error = Invalid handler name: Must start with a letter and contain only letters numbers _ . and -
  }
  elseif (!$com(JSONHandler:: $+ $1)) {
    %error = Invalid handler name: JSON handler does not exist
  }
  elseif (!$regex($2, /^(?:GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/i)) {
    %error = Invalid request method: Must be GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS
  }
  else {
    var %com = JSONHandler:: $+ $1
    if (1 OK != $jsTry(%com, $JScript(UrlMethod), status="error", $qt($upper($2))).withError) {
      %error = $gettok($v2, 2-, 32)
    }
    else {
      Debugger -s $+(%com,>JSONUrlMethod) Method set to $upper($2)
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  reseterror
  if (%error) {
    set -eu0 %JSONError %error
    if (%com) {
      set -eu0 % [ $+ [ %com ] $+ ] ::Error %error
    }
    Debugger -e $iif(%com, $v1, 0) /JSONUrlMethod %switches $1- --RAISED-- %error
  }
}
alias JSONUrlHeader {
  if ($isid) return
  unset %JSONError
  debugger -i 0 Calling /JSONUrlHeader $1-
  var %error, %com
  if ($0 < 3) {
    %error = Missing parameters
  }
  elseif (!$regex($1, /^[a-z][a-z\d_.\-]+$/i)) {
    %error = Invalid handler name: Must start with a letter and contain only letters numbers _ . and -
  }
  elseif (!$com(JSONHandler:: $+ $1)) {
    %error = Invalid handler name: JSON handler does not exist
  }
  elseif (!$regex($2, /^[a-z_-]+:?$/i)) {
    %error = Invalid header name: Header names can only contain letters, _ and -
  }
  else {
    %com = JSONHandler:: $+ $1
    if (1 OK !== $jsTry(%com, $JScript(UrlHeader), status="error", $escape($regsubex($2, :+$, )).quote, $escape($3-).quote).withError) {
      %error = $gettok($v2, 2-, 32)
    }
    else {
      Debugger -s $+(%com,>JSONUrlHeader) Header $+(',$2,') set to $3-
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  reseterror
  if (%error) {
    set -eu0 %JSONError %error
    if (%com) set -eu0 % [ $+ [ %com ] $+ ] ::Error %error
    Debugger -e $iif(%com, $v1, 0) /JSONUrlMethod %switches $1- --RAISED-- %error
  }
}
alias JSONUrlOption {
  if ($isid) return
  unset %JSONError
  Debugger -i 0 /JSONUrlOption is depreciated and will be removed. Please use /JSONUrlMethod and /JSONUrlHeader
  if ($2 == method) {
    JSONUrlMethod $1 $3-
  }
  else {
    JSONUrlHeader $1-
  }
}
alias JSONUrlGet {
  if ($isid) return
  unset %JSONError
  Debugger -i 0 Calling /JSONUrlGet $1-
  var %switches = -, %error, %com, %file
  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  if (!$0 || (%switches != - && $0 < 2)) {
    %error = Missing parameters
  }
  elseif (!$regex(%switches, ^-[bf]?$)) {
    %error = Invalid switch(es) specified
  }
  elseif (!$regex($1, /^[a-z][a-z\d_.\-]+$/i)) {
    %error = Invalid handler name: Must start with a letter and contain only letters numbers _ . and -
  }
  elseif (!$com(JSONHandler:: $+ $1)) {
    %error = Specified handler does not exist
  }
  elseif (b isincs %switches && &* !iswm $2) {
    %error = Invalid bvar name: bvars start with &
  }
  elseif (b isincs %switches && $0 > 2) {
    %error = Invalid bvar name: Contains spaces: $2-
  }
  elseif (f isincs %switches && !$isfile($2-)) {
    %error = Specified file does not exist: $longfn($2-)
  }
  else {
    %com = JSONHandler:: $+ $1
    if ($0 > 1) {
      if (f isincs %switches) {
        if (0 ?* iswm $jsTry(%com, $JScript(UrlData), status="error", $escape($longfn($2-)).quote).withError) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          Debugger -s $+(%com,>JSONUrlGet) Stored $longfn($2-) as data to send with HTTP Request
        }
      }
      else {
        %file = $tempfile
        if (b isincs %switches) {
          bwrite $qt(%file) -1 -1 $2
        }
        else {
          write -n $qt(%file) $2-
        }
        Debugger -s $+(%com,>JSONUrlGet) Wrote specified data to %file
        if (0 ?* iswm $jsTry(%com, $JScript(UrlData), status="error", $escape(%file).quote).withError) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          Debugger -s $+(%Com,>JSONUrlGet) Stored $2- as data to send with HTTP Request
        }
        .remove $qt(%file)
      }
    }
    if (!%error) {
      if (0 ?* iswm $jsTry(%com, $JScript(URLParse), status="error").withError) {
        %error = $gettok($v2, 2-, 32)
      }
      else {
        Debugger -s $+(%com,>JSONUrlGet) Request finished
      }
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  reseterror
  if (%error) {
    set -eu0 %JSONError %error
    if (%com) set -eu0 % [ $+ [ %com ] $+ ] ::Error %error
    Debugger -e $iif(%com, $v1, 0) /JSONUrlGet %switches $1- --RAISED-- %error
  }
}
alias JSONGet {
  if ($isid) return
  unset %JSONError
  debugger -i 0 /JSONGet is depreciated and will be removed. Please use /JSONUrlGet
  JSONUrlGet $1-
}
alias JSONClose {
  if ($isid) return
  unset %JSONError
  Debugger -i 0 /JSONClose $1-
  var %switches = -, %error, %com, %x
  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  if ($0 < 1) {
    %error = Missing parameters
  }
  elseif ($0 > 1) {
    %error = Too many parameters specified.
  }
  elseif (%switches !== - && %switches != -w) {
    %error = Unknown switches specified
  }
  elseif (%switches == -) {
    %com = JSONHandler:: $+ $1
    if ($com(%com)) { .comclose %com }
    if ($timer(%com)) { $+(.timer,%com) off }
    unset % [ $+ [ %com ] $+ ] ::Error
    Debugger -i %com Closed
  }
  else {
    %com = JSONHandler:: $+ $1
    %x = 1
    while (%x <= $com(0)) {
      if (%com iswm $com(%x)) {
        .comclose $v1
        $+(.timer,$v1) off
        unset % [ $+ [ $v1 ] $+ ] ::*
        Debugger -i %com Closed
      }
      else {
        inc %x
      }
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  reseterror
  if (%error) {
    set -eu0 %JSONError %error
  }
}
alias JSONList {
  if ($isid) return
  Debugger -i 0 Calling /JSONList $1-
  var %x = 1, %i = 0
  while ($com(%x)) {
    if (JSONHandler::* iswm $v1) {
      inc %i
      echo $color(info) -a * # $+ %i : $regsubex($v2, /^JSONHandler::/, )
    }
    inc %x
  }
  if (!%i) {
    echo $color(info) -a * No active JSON handlers
  }
}
alias JSON {
  if (!$isid) {
    return
  }
  var %x, %calling, %i = 0, %com, %get = json, %ref = $false, %error, %file
  if ($JSONDebug) {
    %x = 0
    while (%x < $0) {
      inc %x
      %calling = %calling $+ $iif(%calling,$chr(44)) $($ $+ %x,2)
    }
    debugger -i 0 Calling $!JSON( $+ %calling $+ $chr(41) $+ $iif($prop,. $+ $prop)
  }
  if (!$0) {
    return
  }
  if ($regex($1, ^\d+$)) {
    %x = 1
    while ($com(%x)) {
      if (JSONHandler::* iswm $v1) {
        inc %i
        if (%i == $1) {
          %com = $com(%x)
          break
        }
      }
      inc %x
    }
    if ($0 == 1 && $1 == 0) {
      return %i
    }
  }
  elseif ($regex($1, /^[a-z][a-z\d_.-]+$/i)) {
    %com = JSONHandler:: $+ $1
  }
  elseif ($regex($1, /^(JSONHandler::[a-z][a-z\d_.-]+)::(.+)$/i)) {
    %com = $regml(1)
    %get = json $+ $regml(2)
    %ref = $true
  }
  if (!%com) {
    %error = Invalid name specified
  }
  elseif (!$com(%com)) {
    %error = Handler doesn't exist
  }
  elseif (!$regex($prop, /^(?:Status|IsRef|IsChild|Error|Data|UrlStatus|UrlStatusText|UrlHeader|Fuzzy|FuzzyPath|Type|Length|ToBvar|IsParent)?$/i)) {
    %error = Unknown prop specified
  }
  elseif ($0 == 1) {
    if ($prop == isRef) {
      return %ref
    }
    elseif ($prop == isChild) {
      Debugger -i 0 $!JSON().isChild is depreciated use $!JSON().isRef
      return %ref
    }
    elseif ($prop == status) {
      if ($com(%com, eval, 1, bstr, status) && !$comerr) {
        return $com(%com).result
      }
      else {
        %error = Unable to determine status
      }
    }
    elseif ($prop == error) {
      if ($eval($+(%,%com,::Error),2)) {
        return $v1
      }
      elseif ($com(%com, eval, 1, bstr, error) && !$comerr) {
        return $com(%com).result
      }
      else {
        %error = Unable to determine if there is an error
      }
    }
    elseif ($prop == UrlStatus || $prop == UrlStatusText) {
      if (0 ?* iswm $jsTry(%com, $JScript($prop))) {
        %error = $gettok($v2, 2-, 32)
      }
      else {
        return $v2
      }
    }
    elseif (!$prop) {
      return $regsubex(%com,/^JSONHandler::/,)
    }
  }
  elseif (!$regex($prop, /^(?:fuzzy|fuzzyPath|data|type|length|toBvar|isParent)?$/i)) {
    %error = $+(',$prop,') cannot be used when referencing items
  }
  elseif ($prop == toBvar && $chr(38) !== $left($2, 1) ) {
    %error = Invalid bvar specified: bvar names must start with &
  }
  elseif ($prop == UrlHeader) {
    if ($0 != 2) {
      %error = Missing or excessive header parameter specified
    }
    elseif (0 ?* iswm $jsTry(%com, $JScript(UrlHeader), $escape($2).quote)) {
      %error = $gettok($v2, 2-, 32)
    }
    else {
      return $gettok($v2, 2-, 32)
    }
  }
  elseif (fuzzy* iswm $prop) {
    if ($0 < 2) {
      %error = Missing parameters
    }
    else {
      var %x = 2, %path, %res
      while (%x <= $0) {
        %path = %path $+ $escape($($ $+ %x, 2)).quote $+ $chr(44)
        inc %x
      }
      %res = $jsTry(%com, $JScript(fuzzy), %get, $left(%path, -1))
      if (0 ? iswm %res) {
        %error = $gettok(%res, 2-, 32)
      }
      elseif ($prop == fuzzy) {
        %get = %get $+ $gettok(%res, 2-, 32)
      }
      else {
        return $regsubex(%get, ^json, ) $+ $gettok(%res, 2-, 32)
      }
    }
  }
  if (!%error) {
    if (fuzzy* !iswm $prop) {
      %x = $iif($prop == toBvar, 3, 2)
      while (%x <= $0) {
        %i = $($ $+ %x, 2)
        if ($len(%i)) {
          %get = $+(%get, [", $escape(%i), "])
          inc %x
        }
        else {
          %error = Empty index|item passed.
          break
        }
      }
    }
    if (!%error) {
      if ($prop == type) {
        if (0 ?* iswm $jsTry(%com, $JScript(typeof), %get)) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          return $gettok($v2, 2-, 32)
        }
      }
      elseif ($prop == length) {
        if (0 ?* iswm $jsTry(%com, $JScript(length), %get)) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          return $gettok($v2, 2-, 32)
        }
      }
      elseif ($prop == isParent) {
        if (0 ?* iswm $jsTry(%com, $JScript(isparent), %get)) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          return $iif($gettok($v2, 2-, 32), $true, $false)
        }
      }
      elseif ($prop == toBvar) {
        %file = $tempfile
        if (0 ?* iswm $jsTry(%com, $JScript(tofile), $escape(%file).quote, %get)) {
          %error = $gettok($v2, 2-, 32)
        }
        else {
          bread $qt(%file) 0 $file(%file) $2
        }
        if ($isfile(%file)) { .remove $qt(%file) }
      }
      elseif (0 ?* iswm $jsTry(%com, $JScript(get), %get)) {
        %error = $gettok($v2, 2-, 32)
        if (%error == Object or Array referenced) {
          %error = $null
          Debugger -s $+(%com,>$JSON) Result is an Object or Array; returning reference
          return %com $+ :: $+ $regsubex(%get, /^json/, )
        }
      }
      else {
        var %res = $gettok($v2, 2-, 32)
        Debugger -s $+(%com,>$JSON) %get references %res
        return %res
      }
    }
  }
  :error
  %error = $iif($error, $v1, %error)
  if (%error) {
    set -eu0 %JSONError
    if (%com && $com(%com)) {
      set -eu0 $+(%,%com,::Error) %error
    }
    var %r
    %x = 0
    while (%x < $0) {
      inc %x
      %r = $addtok(%r, $chr(32) $+ $ [ $+ [ %x ] ] , 44)
    }
    debugger -e $iif(%com && $com(%com),%com,0) $!JSON( $+ %r $+ ) $+ $+ $iif($prop,. $+ $prop) --RAISED-- %error
  }
}
alias JSONDebug {
  if ($isid) {
    return $iif($group(#JSONForMircDebug) == on, $true, $false)
  }
  elseif ($0) {
    tokenize 32 $iif($group(#JSONForMircDebug) == on, off, on)
  }
  if ($regex($1-,/^(?:on|enable)$/i)) {
    .enable #JSONForMircDebug
    debugger -i Debugger Now Enabled
  }
  elseif ($regex($1-, /^(?:off|disable)$/i)) {
    .disable #JSONForMircDebug
    if ($window(@JSONForMircDebug)) {
      close -@ @JSONForMircDebug
    }
  }
}
#JSONForMircDebug off
alias -l Debugger {
  if ($isid) return
  if (!$window(@JSONForMircDebug)) {
    window -zk0 @JSONForMircDebug
  }
  var %switches = -, %c
  if (-* iswm $1) {
    %switches = $1
    tokenize 32 $2-
  }
  if (e isincs %switches) {
    %c = 04
  }
  elseif (s isincs %switches) {
    %c = 12
  }
  else {
    %c = 03
  }
  var %n = $iif($1, $1, JSONForMirc)
  %n = $regsubex(%n, /^JSONHandler::, )
  aline -p @JSONForMircDebug $+($chr(3),%c,[,%n,],$chr(15)) $2-
}
#JSONForMircDebug end
alias -l Debugger return
menu @JSONForMircDebug {
  .Clear: clear -@ @JsonForMircDebug
  .Disable and Close: JSONDebug off
}
alias -l tempfile {
  var %n = 1
  while ($isfile($scriptdirJSONTmpFile $+ %n $+ .json)) {
    inc %n
  }
  return $scriptdirJSONTmpFile $+ %n $+ .json
}
alias -l escape {
  var %esc = $replace($1-,\,\\,",\")
  return $iif($prop == quote, $qt(%esc), %esc)
}
alias -l JScript {
  if (!$isid) return
  if (!$0) return (function(){status="init";json=null;url={m:"GET",u:null,h:[],d:null};response=null;var r,x=['MSXML2.SERVERXMLHTTP.6.0','MSXML2.SERVERXMLHTTP.3.0','MSXML2.SERVERXMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'],i;while(x.length){try{r=new ActiveXObject(x.shift());break}catch(e){}}xhr=r?function(){r.open(url.m,url.u,false);for(i=0;i<url.h.length;i+=1)r.setRequestHeader(url.h[i][0],url.h[i][1]);r.send(url.d);return(response=r).responseText}:function(){throw new Error("HTTP Request object not found")};read=function(f){var a=new ActiveXObject("ADODB.stream"),d;a.CharSet="utf-8";a.Open();a.LoadFromFile(f);if(a.EOF){a.close();throw new Error("No content in file")}d=a.ReadText();a.Close();return d;};write=function(f,d){var a=new ActiveXObject("ADODB.stream");a.CharSet="utf-8";a.Open();a.WriteText(d);a.SaveToFile(f,2);a.Close()};parse=function(t){if(/^[\],:{}\s]*$/.test((t=(String(t)).replace(/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})).replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){try{return eval('('+t+')');}catch(e){throw new SyntaxError('Unable to Parse: Invalid JSON');}}throw new SyntaxError('Unable to Parse: Invalid JSON')};fuzzy=function(){var a=Array.prototype.slice.call(arguments),b=a.shift(),c="",d=Object.prototype.toString.call(b),e,f,g,h,i;for(e=0;e<a.length;e+=1){f=a[e];if(b.hasOwnProperty(f)){if(typeof b[f]==="function")throw new TypeError("Reference points to a function");b=b[f];c+="[\""+f+"\"]"}else if(d==="[object Object]"){if(typeof f==="number")f=f.toString(10);f=f.toLowerCase();g=-1;i=!1;for(h in b){if(b.hasOwnProperty(h)&&typeof b[h]!=="function"){g+=1;if(h.toLowerCase()===f){b=b[h];c+="[\""+h+"\"]";i=!0;break}else if(g.toString(10)===f){b=b[h];c+="[\""+h+"\"]";i=!0;break}}}if(!i)throw new Error("No matching reference found");}else{throw new Error("Reference does not exist")}d=Object.prototype.toString.call(b)}return c}}());
  if ($1 == FileParse)     return if(status!=="init")throw new Error("Parse Not Pending");json=parse(read(@1@));status="done";
  if ($1 == UrlInit)       return if(status!=="init")throw new Error("JSON handler not ready");url.u=@1@;status="url";
  if ($1 == UrlMethod)     return if(status!=="url")throw new Error("URL Request Not Pending");url.m=@1@;
  if ($1 == UrlHeader)     return if(status!=="url")throw new Error("URL Request Not Pending");url.h.push([@1@,@2@]);
  if ($1 == UrlData)       return if(status!=="url")throw new Error("URL Request Not Pending");url.d=read(@1@);
  if ($1 == UrlParse)      return if(status!=="url")throw new Error("URL Request Not Pending");json=parse(xhr());status="done";
  if ($1 == UrlStatus)     return if(status!=="done")throw new Error("Data not parsed");if(!response)throw new Error("URL request not made");return response.status;
  if ($1 == UrlStatusText) return if(status!=="done")throw new Error("Data not parsed");if(!response)throw new Error("URL request not made");return response.statusText;
  if ($1 == UrlHeader)     return if(status!=="done")throw new Error("Data not parsed");if(!response)throw new Error("URL Request not made");return response.getResponseHeader(@1@);
  if ($1 == fuzzy)         return if(status!=="done")throw new Error("Data not parsed");return "1 "+fuzzy(@1@,@2@);
  if ($1 == typeof)        return if(status!=="done")throw new Error("Data not parsed");var i=@1@;if(i===undefined)throw new TypeError("Reference doesn't exist");if(i===null)return"1 null";var s=Object.prototype.toString.call(i);if(s==="[object Array]")return"1 array";if(s==="[object Object]")return"1 object";return "1 "+typeof(i);
  if ($1 == length)        return if(status!=="done")throw new Error("Data not parsed");var i=@1@;if(i===undefined)throw new TypeError("Reference doesn't exist");if(/^\[object (?:String|Array)\]$/.test(Object.prototype.toString.call(i)))return"1 "+i.length.toString(10);throw new Error("Reference is not a string or array");
  if ($1 == isparent)      return if(status!=="done")throw new Error("Data not parsed");var i=@1@;if(i===undefined)throw new TypeError("Reference doesn't exist");if(/^\[object (?:Object|Array)\]$/.test(Object.prototype.toString.call(i)))return"1 1";return"1 0";
  if ($1 == tofile)        return if(status!=="done")throw new Error("Data not parsed");var i=@2@;if(i===undefined)throw new TypeError("Reference doesn't exist");if(typeof i!=="string")throw new TypeError("Reference must be a string");write(@1@,i);
  if ($1 == get)           return if(status!=="done")throw new Error("Data not parsed");var i=@1@;if(i===undefined)throw new TypeError("Reference doesn't exist");if(i===null)return"1";if(/^\[object (?:Array|Object)\]$/.test(Object.prototype.toString.call(i)))throw new TypeError("Object or Array referenced");if(i.length>4000)throw new Error("Data would exceed mIRC's line length limit");if(typeof i == "boolean")return i?"1 1":"1 0";if(typeof i == "number")return "1 "+i.toString(10);return "1 "+i;
}
alias -l jsTry {
  if ($isid) {
    if ($0 < 2 || $prop == withError && $0 < 3) {
      return 0 Missing parameters
    }
    elseif (!$com($1)) {
      return 0 No such com
    }
    else {
      var %code = $2, %error, %n = 2, %o, %js
      if ($prop == withError) {
        %error = $3
        %n = 3
      }
      %o = %n
      while (%n < $0) {
        inc %n
        set -l $+(%, arg, $calc(%n - %o)) $eval($+($, %n), 2)
      }
      %code = $regsubex($regsubex(%code, /@(\d+)@/g, $var($+(%, arg, \


Edited by x3pos (30/09/16 09:34 PM)

Top
#259058 - 30/09/16 09:36 PM Re: [Twitch]follower script help [Re: x3pos]
x3pos Offline
Babel fish

Registered: 17/01/16
Posts: 79


Edited by x3pos (30/09/16 09:38 PM)

Top