mIRC Homepage
Posted By: Pie [Twitch] Bot reacts to stream status. - 16/01/17 06:45 PM
Hi there,

I was wondering if mIRC could react to the stream status, i.e: stream being online or offline.

I'd like to have it send a message to the channel when the stream goes online, and offline.

I.e:
(Stream online) Hi Streamer, Good to have you back!

(Stream offline) See you again tomorrow!

If anyone could help me out with this, I'd appreciate it a lot! laugh
AFAIK, twitch doesn't tell chat when the stream goes online/offline.

You'd have to poll twitch's api for changes
Posted By: Pie Re: [Twitch] Bot reacts to stream status. - 16/01/17 08:09 PM
Yea i figured.
I couldn't find anything in the raw data as well so i guess i'll have to see how to pull data from the API with mIRC.

Thanks though! smile
Posted By: OrFeAsGr Re: [Twitch] Bot reacts to stream status. - 16/01/17 08:37 PM
https://forums.mirc.com/ubbthreads.php/topics/254744/Re:_Command_for_making_bot_ret#Post254744
Check this post out.
Posted By: Pie Re: [Twitch] Bot reacts to stream status. - 16/01/17 09:12 PM
Originally Posted By: OrFeAsGr
https://forums.mirc.com/ubbthreads.php/topics/254744/Re:_Command_for_making_bot_ret#Post254744
Check this post out.


That would output the text on that given website.
If im right, I cant modify the output of that which is what i would want.

I could be wrong ofcourse :P
Posted By: OrFeAsGr Re: [Twitch] Bot reacts to stream status. - 16/01/17 10:08 PM
Hey i was bored so i checked this out and edited a bit for you.
All you have to do is load this on mIRC and input your channel name where it says INPUT_CHAN_HERE
The script will start checking for stream state when mIRC starts and you can also use /decapi to toggle the checking on or off.
Code:
alias livestream {
  sockopen -e decapi decapi.me 443
}


alias decapi {
  if ($timer(decapi).secs) { .timerdecapi off | echo -at The Stream Checker is now off }
  elseif (!$timer(decapi).secs) { .timerdecapi 0 200 livestream | echo -at The Stream Checker is now on }
}

alias mytchan { return INPUT_CHAN_HERE }

on *:SOCKOPEN:decapi: {
  sockwrite -nt $sockname GET $+(/twitch/uptime.php?channel=,$mytchan) HTTP/1.1
  sockwrite -nt $sockname Host: decapi.me
  sockwrite $sockname $crlf
}

on *:SOCKREAD:decapi: {
  var %decapi
  sockread %decapi
  while ($sockbr) {
    sockread %decapi
  }
}

on *:sockclose:decapi: {
  var %decapi
  sockread -f %decapi
  if (*not live* iswm %decapi) {
    if (!%streamisoff) {
      set -e %streamisoff 1
      msg $+($chr(35),$mytchan) Stream is now off...
      unset %streamison
    }
  }
  else { 
    if (!%streamison) {
      set -e %streamison 1
      msg $+($chr(35),$mytchan) Stream is now on!
      unset %streamisoff
    }
  }
}


ON *:START: { .timerdecapi 0 200 livestream }

I tested it and it works! smile
Enjoy!
Posted By: Pie Re: [Twitch] Bot reacts to stream status. - 17/01/17 05:40 PM
Holy crap! That's really generous of you! shocked

Im gonna put this to the test today, But i'll take your word for it that it will work! grin

Thank you so much! Saves me a bit of a headache whistle
Really appreciate it! blush

EDIT: Yep, It works perfectly! laugh
I assume setting the timer to 0 60 wont be too much of a problem, Right?

Thank you again!
© mIRC Discussion Forums