mIRC Home    About    Download    Register    News    Help

Print Thread
#246490 13/06/14 04:10 PM
Joined: Mar 2014
Posts: 52
P
Babel fish
OP Offline
Babel fish
P
Joined: Mar 2014
Posts: 52
hi, could anyone tell me why this isnt working?

Code:
on *:text:!bla:#: {
  sockclose uptime
  sockopen uptime www.nightdev.com 80
  msg # %read 
}

on *:sockopen:uptime: {
  sockwrite -n $sockname GET hosted/uptime.php?channel=riotgames HTTP/1.0
  sockwrite -n $sockname Host: www.nightdev.com
}

on *:sockread:uptime: {
  set %read
  sockread -f %read
}


i either get nothing or "Error 400 Bad Request" when tyipng !bla
:s

Last edited by patrickplays; 13/06/14 04:18 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
All GET requests must begin with a slash: /hosted/uptime.php?channel=riotgames

You must end your request with a blank line: sockwrite -n $sockname $crlf

You should use a local variable for %read, and you cannot use that variable in your text event. The text event finishes processing before the socket starts. Your options for messaging the channel are to hard code it into the socket, or store/pass a callback alias/signal to be called.

Joined: Jun 2014
Posts: 8
D
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
I reworked your script making it check for errors, seeing if the script is already open (to prevent spam), timers (to prevent flooding), HTML stripping, skip header display, added an input, on text and alias, and securly set and unset all variables and the socket, and if it says "channel not live" it will simply just say that and end the script.

I would recommend scanning through it to see what stuff does to get a better insight. You can change the bla's to whatever command you want, or the channel variable to a specific channel.

I mainly worked on this to increase my knowledge of mIRC scripting. The script could be written shorter and better, but it did increase my knowledge getting it done lol. Let me know if it works for you and if you have any questions.

Code:
alias bla {
  if (%nightdev) { halt }
  else {
    $iif($sock(uptime), sockclose uptime)
    sockopen uptime nightdev.com 80
    set %uptime-chan $active
  }
}

alias uptime-message {
  if (%notlive) { .timer 1 2 msg %uptime-chan %notlive | uptime-unset }
  elseif (!%notlive) {
    var %lineread = 7
    while (%lineread <= %readcount) {
      .timer 1 2 msg %uptime-chan %readline. [ $+ [ %lineread ] ]
      inc %lineread
    }
    uptime-unset
  }
}

alias uptime-unset {
  unset %readcount
  unset %readline*
  unset %readerror
  unset %nightdev
  unset %uptime-chan
  unset %notlive
  $iif($sock(uptime), sockclose uptime)
}

on *:input:#: {
  if ($$1 == !bla) {
    if (%nightdev) { halt }
    else {
      $iif($sock(uptime), sockclose uptime)
      sockopen uptime nightdev.com 80
      set %uptime-chan $active
    }
  }
}

on *:text:!bla:#: {
    if (%nightdev) { halt }
    else {
      $iif($sock(uptime), sockclose uptime)
      sockopen uptime nightdev.com 80
      set %uptime-chan $chan
  }
}

on *:sockopen:uptime: {
  if ($sockerr > 0) {
    .timer 1 2 msg %uptime-chan Error while opening the page.
    .timer 1 3 uptime-unset
  }
  elseif (!$sockerr) {
    sockwrite -n $sockname GET /hosted/uptime.php?channel=riotgames/ HTTP/1.1
    sockwrite -n $sockname Host: www.nightdev.com
    sockwrite -n $sockname User-Agent: Mozilla/30.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    sockwrite -n $sockname Connection: close
    sockwrite -n $sockname $crlf
  }
}

on *:sockread:uptime: {
  :top
  sockread -f %read
  if ($sockbr == 0) { goto bottom } 
  $iif(%read == %null, %read = -)
  var %stripread = $regsubex(%read,/(<[^>]*>)/g,)
  inc %readcount 1
  set %readline. [ $+ [ %readcount ] ] %stripread
  if (not live. isin %readline. [ $+ [ %readcount ] ]) { set %notlive %stripread }
  goto top
  :bottom
  uptime-message
}

Last edited by Demon1LT; 14/06/14 11:11 PM.
Joined: Jun 2014
Posts: 8
D
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
Also I almost forgot, you might want to add a set %nightdev in the main alias, the on input and on text. Forgot about that, but it still seemed to work strangely enough.

Joined: Mar 2014
Posts: 52
P
Babel fish
OP Offline
Babel fish
P
Joined: Mar 2014
Posts: 52
thanks for your effort, but this is not working correctly when the stream is online

Joined: Jun 2014
Posts: 8
D
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2014
Posts: 8
Here, replace all codes with this:

Code:
on *:input:#: {
  if ($$1 == !bla) {
    if (%nightdev) { halt }
    else {
      bla
    }
  }
}

on *:text:!bla:#: {
  if (%nightdev) { halt }
  else {
    bla
  }
}

alias bla {
  if (%nightdev) { halt }
  else {
    $iif($sock(uptime), sockclose uptime)
    set %nightdev
    sockopen uptime nightdev.com 80
    set %uptime-chan $active
  }
}

on *:sockopen:uptime: {
  if ($sockerr > 0) {
    .timer 1 2 msg %uptime-chan Error while opening the page.
    .timer 1 3 uptime-unset
  }
  elseif (!$sockerr) {
    sockwrite -n $sockname GET /hosted/uptime.php?channel=riotgames/ HTTP/1.1
    sockwrite -n $sockname Host: www.nightdev.com
    sockwrite -n $sockname User-Agent: Mozilla/30.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    sockwrite -n $sockname Connection: close
    sockwrite -n $sockname $crlf
  }
}

on *:sockread:uptime: {
  :top
  var %y
  sockread -f %y
  if ($sockbr == 0) { goto bottom } 
  var %stripread = $regsubex(%y,/(<[^>]*>)/g,)
  $iif(%stripread != $null, inc %readcount 1, return)
  if (not live. isin %stripread) {
    set %readline. [ $+ [ %readcount ] ] %stripread
    set %notlive %stripread
    uptime-message
    return
  }
  set %readline. [ $+ [ %readcount ] ] %stripread
  goto top
  :bottom
  .timer 1 $calc(%readcount +2) uptime-unset
  uptime-message
  return
}

alias uptime-message {
  if (%notlive) { .timer 1 2 msg %uptime-chan %notlive | uptime-unset | halt }
  elseif (!%notlive) {
    var %a = 7
    var %b = %readcount
    while (%a <= %b) {
      .timer 1 $calc(%a -5) msg %uptime-chan %readline. [ $+ [ %a ] ]
      inc %a
    }
  }
}

alias uptime-unset {
  unset %read*
  unset %nightdev
  unset %uptime-chan
  unset %notlive
  $iif($sock(uptime), sockclose uptime)
}


Works fine when its offline, however, I can't test when a channel thats online because there's no list of online channels. Mind telling me what happens when its online?

Joined: Mar 2014
Posts: 4
J
Self-satisified door
Offline
Self-satisified door
J
Joined: Mar 2014
Posts: 4
Sorry for bumping this thread but I saw someone link to this in another thread.
When I try to use this script whilst the channel is live, it says nothing. Any help? smile


Best Regards,
John.

Last edited by John67; 14/07/14 08:58 PM.
Joined: Jul 2014
Posts: 48
A
Ameglian cow
Offline
Ameglian cow
A
Joined: Jul 2014
Posts: 48
it does not seem to work for me either, when online.

I ended up just going through the twitch api, and got a working setup. Only downfall is uptime from twitch is reported in PST, which could be a problem for people.

Joined: Mar 2014
Posts: 52
P
Babel fish
OP Offline
Babel fish
P
Joined: Mar 2014
Posts: 52
just use math! its very effective laugh


Link Copied to Clipboard