mIRC Home    About    Download    Register    News    Help

Print Thread
J
jimieo
jimieo
J
I was browsing on here and found this !uptime script.

This had me thinking that if one can check the uptime of a stream that it would be possible to have mIRC simply check if a stream is live, and if so, do something.

Right now, I am figuring every 20-30 seconds, the script would check if my stream is live, and if it is run a timer and send a message to the chat

if live
.timertest 0 23 fancy timer thing here
msg $chan timer started

Does anything think this can be done? or know how to point me in the right direction?

Last edited by jimieo; 06/01/15 12:37 AM.
S
Sakana
Sakana
S
You need to change the uptime script so it sets the uptime (if present) to a variable (e.g %uptime), and also have it unset %uptime and %target at the beginning.

Then I imagine you would need something like this

Code:
on *:connect:{ timer1 0 30 streamcheck } 

alias -l streamcheck {

uptime

if ( %uptime ) && (%target = YourChannelName) {

timer1 off
timer2 0 30 msg # text goes here

   }   
}



But you should make it say different lines. Getting spammed with the same timed message is pretty obnoxious :p

Last edited by Sakana; 06/01/15 02:56 AM.
J
jimieo
jimieo
J
I'll check that out in a moment.

I agree about the message. The plan is to have it say the message once while the timer runs until the uptime variable is set to 0, when the show ends.

S
Sakana
Sakana
S
Maybe there's something more optimal, but this works as intended when I tested it. Just replace all instanes of STREAMNAME with your Twitch name

Code:
on *:connect:{ timer1 0 30 StreamCheck } 

alias StreamCheck {
   StreamOn STREAMNAME
  .timer 1 2 Streamcheck2   
}

alias StreamCheck2 {
    if (%uptime) && (%target = STREAMNAME)  {
    timer1 off
    timer2 0 30 msg #STREAMNAME text goes here
}   
    else echo -a StreamCheck error
}

alias StreamOn {
  unset %target
  unset %uptime
  set %target $iif($1,$1,$mid(#,2-)) 
  sockclose StreamOn
  sockopen StreamOn nightdev.com 80
}

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

on *:sockread:StreamOn:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { set %uptime $1- }
}


Last edited by Sakana; 06/01/15 07:27 AM.
J
jimieo
jimieo
J
Thank you, Sakana, for the time you have invested in this. I truly appreciate the work.

J
jimieo
jimieo
J
Hrmm.. While yes, this does work. I've been encountering issues lately.

For starters I use this script to start some timers that I only want to run while I am live. But lately, I've been having issues where it turns them off and back on frequently. The script isn't always able to tell my stream is live.

Does anyone know if there is a better method, using twitch's API or something?

B
Belhifet
Belhifet
B
Get a json parser and use the https://api.twitch.tv/kraken/streams/ endpoint

Joined: Apr 2010
Posts: 964
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 964
Originally Posted By: Belhifet
Get a json parser and use the https://api.twitch.tv/kraken/streams/ endpoint


Parser: JSON for MIRC,

Though I'd recommend AGAINST looping over the entirety of the streams list, instead use https://api.twitch.tv/kraken/streams/<username>

Last edited by FroggieDaFrog; 16/01/15 08:07 AM.
J
jimieo
jimieo
J
Thanks. Looking up how to use the api now smile

EDIT:
Code:
on *:text:!hmm*:#:{
  if ($nick == jimieo) {
    var %twitchapi = https://api.twitch.tv/kraken/streams/jimieo
    set %game $json(%twitchapi,stream,game)
  }
}


So, I was trying this to see if I could get it to set the game as a variable (just to see if I could). I failed. Did I just miss something stupidly obvious.

My end goal is to be able to detect if my channel shows as live or not.

Last edited by jimieo; 18/01/15 09:15 AM.
Joined: Apr 2010
Posts: 964
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 964
A few things:
1: On text events do not trigger for the client that sends them. That is the same client that sends "!hmm" will not trigger it's own on text event

2: Read the scripts documentation:

Code:
  jsonopen -ud twitchapi https://api.twitch.tv/kraken/streams/jimieo
  set %game $json(twitchapi, stream, game)


Link Copied to Clipboard