mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2014
Posts: 2
V
Bowl of petunias
OP Offline
Bowl of petunias
V
Joined: Jul 2014
Posts: 2
I want to write a simple socket to go with a !uptime command for a bot I'm running for a twitch stream. I've looked at multiple different examples of how to write a socket but nothing seems to be working. My code looks like this:

Code:
on *:TEXT:!uptime*:#:{
  sockclose utSocket
  sockopen utSocket www.nightdev.com 80
}


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

on *:sockread:utSocket:{
  var %read
  sockread -f %read
  msg # Stream has been running for %read .
 sockclose utSocket

}

www.nightdev.com/hosted/uptime.php?channel=STREAM_NAME will just display text of the running time of whatever stream is put in the URL in place of STREAM_NAME, which is exactly what I want.

Does anyone know what the problem is? Is there anything else that needs to be done when making a socket or am I missing something here?

Last edited by VidyaJames; 31/07/14 01:03 AM.
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
msg # means nothing in the sockread event. You have to store the channel name in the text event.

Also, you want to set an if statement and not use msg %chan %read - as this will spam the channel with irrelevant stuff.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jul 2014
Posts: 2
V
Bowl of petunias
OP Offline
Bowl of petunias
V
Joined: Jul 2014
Posts: 2
Thank you! My problem was indeed that I was sending the msg to #, when it should've been #STREAM_NAME. Everything works now.

Joined: Jul 2014
Posts: 1
N
Mostly harmless
Offline
Mostly harmless
N
Joined: Jul 2014
Posts: 1
Would you mind posting the code that you got working? I've been struggling with this the past week or so and haven't been able to solve the problem

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Code:
on *:text:!uptime*:#:{
  set -u10 %target $iif($2,$2,$mid(#,2-))
  set -u10 %channel #
  uptime 
}

alias uptime {
  sockclose uptime
  sockopen uptime nightdev.com 80
}

on *:sockopen:uptime:{
  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:uptime:{
  if ($sockerr) { sockclose $sockname }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1- }
  elseif (%data == The channel is not live.) msg %channel %target is currently not online.
}
Untested but should work.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Link Copied to Clipboard