Twitch New Follower Welcome

By ^WeSt on Oct 14, 2014

Requested for: Wikked

Contact: http://westor.ucoz.com/contact

Thanks SReject for JSON code!!!


Description:

In order to work you must first setup the stream channel and the user must be an channel operator, if the bot will be kicked,parted from the channel it will automatically stop scanning, this code scanning for new follower on your twitch channel if there exist any it will automatically message the channel the nickname and the follow date (time ago), notice that if you don't setup the stream channel the autofollow will not work, also be in mind that the timeago parameter maybe the result may not be correct during an timezone difference between you and Twitch API results.

Commands (on the channel):

!setstreamchan STREAM-CHANNEL = This will set up the stream channel for starting looking for followers.

!streamchan = This will display the currently set Twitch Stream Channel.

!autofollow ON/OFF = If this will set as ON then it will start scanning for the latest follower on your stream channel.

!lastfollow = This will display the last nick that follows your Twitch Stream Channel.

!followed NICK = This will give on the channel the date that the nickname has follow the Twitch Stream Channel.

  • Thanks!
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 $+ ): Welcome & Thank you for following our channel! - (Followed on:  $+ %followed $+  $iif(%followed_ago,( $+ $v1 $+ ))) - (Type:  $+ %type $+ )
  :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 $+ )
}

Comments

Sign in to comment.
trizanthium   -  Apr 06, 2017

Im new to this whole mIRC bot thing, is there anything i need to change in this code or can i just copy+paste to my script editor?

 Respond  
Bestpeff   -  Apr 15, 2016

How come I can't do anything with the commands, only other OPs of the channel can do it

 Respond  
stevemagic   -  Mar 19, 2016

For some odd reason I can not "activate" it myself I have to have other mods of the channel do it

 Respond  
MVPGraffix   -  Jun 24, 2015

When I do !setstreamchan (ChannelNAME) it says you are not a channel operator but i am an op?!? help pls does the bot have to be op?

MsDiz  -  Sep 22, 2015

This makes no sense, the code basically is saying that if you are op you cant do the command, it doesnt make any sense to me either

MsDiz  -  Sep 22, 2015

Ok sorry, I figured it out, change the !isop to !(your name)

the "!" means not equal to so anyone that is NOT you

Sign in to comment

SReject   -  Apr 13, 2015

@^WeSt: Instead of including my JSON script with yours, please link to my page instead. Its not that I mind its inclusion, but this way people that use multiple scripts that require it don't have conflicting copies stored. With that said, very nice script. good job :)

^WeSt  -  Apr 13, 2015

Ok @SReject , i had included because a lot of ppl does not reading the description and only coping the main code without the JSON Code but i will do it like this way.

powerade661  -  Apr 29, 2015

Is it possible to display the amount of followers with the follow script? After the type:user?

Regards,
Powerade661

Sign in to comment

^WeSt   -  Apr 13, 2015
  • Code updated!!

  • Updated the JSON Code. - Thanks SReject
  • Updated some code stuff.

  • Thanks!
 Respond  
Blood_Wolf89   -  Mar 31, 2015

How can I set this to work on multiple channels?

^WeSt  -  Mar 31, 2015

Its already working on multi-channels ..

Blood_Wolf89  -  Mar 31, 2015

Thank you sir, Sorry I posted this at 3am.. Great work! ♥

Sign in to comment

ShadsDream   -  Mar 04, 2015

Everything seems to be working except for the !followed command. Any name I have tried on it will not find the person. Tried with multiple nicknames who have been following the channel for a long time. Or does it only check when it is a recent follower?

^WeSt  -  Mar 05, 2015

In order to make !followed to work the bot must have this feature in use, because it saves the new followers that have been followed to the channel.

Sign in to comment

^WeSt   -  Jan 18, 2015
  • Code has been updated!

  • Removed the automatically turn off if the stream was offline
  • Updated the JSON code - (Thanks to SReject)
  • Fixed some characters that twitch.tv cannot parse it.
VitruxPT  -  Jan 20, 2015

Well i need your help with something.
My local bot runs the script perfectly but when i upload it to my online hosted bot, it does not appear to see new followers.
I'm thinking this is a "port" related problem, so can you please tell the which ports are you using to connect to the twitch servers, so i can add an exception.

Sign in to comment

^WeSt   -  Oct 15, 2014
  • Code has been updated!
Dekkzter  -  Nov 13, 2014

Hmm, where does it save the nicks for those who follow? i have 2 mirc bots running and the 2nd one takes !lastfollow from bot no 1. Is there any fix for this??

^WeSt  -  Nov 13, 2014

Thats not an bug also why you use 2 bots on same mirc client the code is multi channel support, but if need an second channel to follow you must use an second mirc client.

Dekkzter  -  Nov 13, 2014

I do use 2 mirc clients, but still it takes the 2nd one takes the same !lastfollow as the first bot

^WeSt  -  Nov 13, 2014

Try to paste the code on an different mirc client to avoid the duplication.

^WeSt  -  Nov 13, 2014
Dekkzter  -  Nov 13, 2014

First i copied the no1 mirc client to a new location and just changing the name of the username, and mirc on the new location, when starting the bot and testing !lastfollow i got a follower from the old channel. so installed a fresh copy of the mirc client, nothing had been done, and opied the code still i got the same !lastfollow as the old one. so i tried the stuff you suggested. :(

ProGamerzFTW  -  Nov 18, 2014

It doesn't seem to be detecting new follows, and ideas?

^WeSt  -  Nov 18, 2014

give some error or the twitch channel name that you used, also did you first used: !setstreamchan stream channel ?

ProGamerzFTW  -  Nov 18, 2014

I did !setstreamchan progamerzftw, it says it was set. then did !autofollow on (yes i was streaming), made a alt account to follow the stream, didn't welcome me in chat nor does it add it to the database, there was no errors, atleast i dont think

ProGamerzFTW  -  Nov 18, 2014

Got it working I think, the channel name i needed to put in is CaSe SeNsAtIvE.

ProGamerzFTW  -  Nov 19, 2014

the auto welcome module seems to often think the channel went offline when it never did, how would one make it so it wont automatically disable when a stream went offline?

Paper0rPlastic  -  Dec 03, 2014

Any way to make this not detect re-follows?

omexlu  -  Dec 10, 2014

Hello,

How i must make it to work?

I have created a ini with the script and load it
I have load json.mrc into mirc

But i receive no answer on commands?

Thanks in advance.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.