mIRC Homepage

Little socket script - problem with the message!

Posted By: Krawalli

Little socket script - problem with the message! - 25/08/14 11:06 AM

Hey fellas,
i just try to give out the informations from this URL:
http://nightdev.com/hosted/uptime.php?channel=pest_xin

The scripts is "working" i have no idea how to give out the "x hours, x minutes" text from the website w.o. saveing the informations to a .ini file - the problem there, its saveing the ini like: "x=hours, x minutes" so i cant even read the ini file correct -.-!

Please - could someone help me? laugh

My script (i know its pure noob!):
Code:
on *:sockopen:uptime: {
    sockwrite -n $sockname GET /hosted/uptime.php?channel=pest_xin 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:{ 
  var %uptime 
  sockread %uptime
  /writeini uptime.ini Uptime Test %uptime
}
on *:text:!uptime:#: {
  sockclose uptime
  sockopen uptime nightdev.com 80
  .msg # Uptime: $readini(uptime.ini,np,Uptime)
}


The ini file looks then like:
Code:
[Uptime]
HTTP/1.1=200 OK
Server:=nginx
Date:=Mon, 25 Aug 2014 11:03:22 GMT
Content-Type:=text/html
Transfer-Encoding:=chunked
Connection:=close
2=hours, 27 minutes


I just need that my bot is giving out the single line that is on the url posted - not more.

Posted By: Nillen

Re: Little socket script - problem with the message! - 25/08/14 12:39 PM

Your ini file shouldn't look like that. The item you're writing to is supposed to be Test.
[Uptime]
Test=2 hours, 27 minutes
Should be what it looks like.

Your ini file looks like you're using
writeini uptime.ini Uptime %uptime
which would use the first word in %uptime as the item.

You could just use the first method and then use $readini() for the test item, but you could also just use something like
Code:
on *:sockread:uptime:{ 
  var %uptime 
  sockread %uptime
  tokenize 32 %uptime
  if ($1 isnum) writeini uptime.ini uptime #channelorsomething %uptime
}
Posted By: Sjoepele

Re: Little socket script - problem with the message! - 25/08/14 12:41 PM

cant you replace 'Uptime' in:
.msg # Uptime: $readini(uptime.ini,np,Uptime)
to the actual line you want to read? so:
.msg # Uptime: $read(uptime.ini,n,8)

(i have never ever in my life read from an ini so im not sure but i thought the 3rd argument was the line it's reading)

Also, im totally using this script if it works :P

Posted By: Krawalli

Re: Little socket script - problem with the message! - 25/08/14 05:15 PM

Hi nillen.
When is use your Code the ini file looks like:

Code:
[uptime]
#fragharry=0


When i use: "/writeini uptime.ini Uptime Test %uptime"
Code:
[uptime]
Test=0


When i use: "/writeini uptime.ini Uptime %uptime"
Code:
[Uptime]
HTTP/1.1=200 OK
Server:=nginx
Date:=Mon, 25 Aug 2014 17:15:02 GMT
Content-Type:=text/html
Transfer-Encoding:=chunked
Connection:=close
The=channel is not live.


The problem is. I dont know why the hell the script is not just saveing "x hours, x minutes" or "The Channel is not live" (the posted Url dont show more...)
I hope you understand my problem lol.

I just want to give out what the website is saying :<
Posted By: Nillen

Re: Little socket script - problem with the message! - 25/08/14 05:29 PM

So, basically it returns "The channel is not live" or "x hours x minutes"?
Code:
on *:sockread:uptime:{ 
  var %uptime 
  sockread %uptime
  tokenize 32 %uptime
  if (($1 isnum) && ($2)) || ($1- == The channel is not live) writeini uptime.ini uptime #channelorsomething %uptime
}
Posted By: Sjoepele

Re: Little socket script - problem with the message! - 25/08/14 05:29 PM

I changed it up a bit so you can check the uptime of any caster with !uptime caster. The problem im running into though, is that you need to trigger the command twice before it returns the right info.. not sure why

Code:
on *:sockopen:uptime: {
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %caster 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:{ 
  var %uptime 
  sockread %uptime
  /writeini uptime.ini Uptime  %uptime
  
}
on *:text:!uptime*:#: {
  set %caster $2
  sockclose uptime
  sockopen uptime nightdev.com 80
  msg # Uptime: $read(uptime.ini,n,8)
  remove uptime.ini
}


its like its returning info from the LAST query...
Posted By: Nillen

Re: Little socket script - problem with the message! - 25/08/14 05:34 PM

Code:
on *:text:!uptime*:#:{
  set %target $iif($2,$2,$mid(#,2-))
  set %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 | halt }
  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.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}
Tested and working.
If you wanna set a timer to update an ini file, you can do that as well, writeini uptime.ini uptime %target %data
Posted By: Sjoepele

Re: Little socket script - problem with the message! - 25/08/14 05:39 PM

You sir are a genius. Thanks!
Posted By: Krawalli

Re: Little socket script - problem with the message! - 25/08/14 05:44 PM

Perfect Nillen! Thanks a lot.
Posted By: Artiiz

Re: Little socket script - problem with the message! - 23/09/15 11:19 PM

Originally Posted By: Nillen
Code:
on *:text:!uptime*:#:{
  set %target $iif($2,$2,$mid(#,2-))
  set %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 | halt }
  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.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}
Tested and working.
If you wanna set a timer to update an ini file, you can do that as well, writeini uptime.ini uptime %target %data


Hey,

I have two questions about your uptime script.

1.
Is there a way of making so that I can have:
Code:
{ msg %channel @ $+ $nick %target has been online for $1- }

So that I first tag the person who writes the command, and then says how long the channel has been live for? I tried doing like I wrote in the code, but then it just tags myself, and not the writer.

2.
Is there a way making so that instead of showing:
Code:
has been online for 4 hours, 39 minutes

It will show like
Code:
has been online for 4h, 39m and *s


Best Regards
Artiiz
Posted By: westor

Re: Little socket script - problem with the message! - 25/09/15 01:08 PM

Try use this:

Code:
{ msg %channel @ $+ $nick %target has been online for $replace($1-,minutes,m,seconds,s,hours,h) }


/help $replace
Posted By: Artiiz

Re: Little socket script - problem with the message! - 25/09/15 08:21 PM

Originally Posted By: westor
Try use this:

Code:
{ msg %channel @ $+ $nick %target has been online for $replace($1-,minutes,m,seconds,s,hours,h) }


/help $replace


Hey,

Everything seem to be working fine except that it wont show seconds (s).
And also that the "@ $+ $nick" isn't working, it shows like this then:



The script looks like this:
Code:
on *:text:!uptime*:#chapmad:{
  set %target $iif($2,$2,$mid(#,2-))
  set %channel #chapmad
  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 | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel @ $+ $nick %target has been live for $replace($1-,minutes,m,seconds,s,hours,h,hour,h) }
  elseif (%data == The channel is not live.) msg %channel %target is currently not live.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}
Posted By: Nillen

Re: Little socket script - problem with the message! - 25/09/15 08:50 PM

You should set %nick = $nick in the on text event and use that in the sockread. You also can't output any seconds from a site that doesn't give you any seconds.

This script is functional but outdated anyway, there are better ways right now that pull it straight from twitch's api in a easy 3 line code assuming you have Froggie's JSON api script.
Posted By: YeyoSsj

Re: Little socket script - problem with the message! - 06/01/16 06:13 AM

Originally Posted By: Nillen
Code:
on *:text:!uptime*:#:{
  set %target $iif($2,$2,$mid(#,2-))
  set %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 | halt }
  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.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}
Tested and working.
If you wanna set a timer to update an ini file, you can do that as well, writeini uptime.ini uptime %target %data



Hello man, I've been using your script, which is excellent, but nightdev updated its API and now can not be used for the message showing



Editing will be possible to take the other side uptime than nightdev?
something like this page: http://decapi.me/twitch/uptime.php?channel=yeyossj

Sorry for my bad english!! XD
Posted By: Thedelirious1

Re: Little socket script - problem with the message! - 06/01/16 03:01 PM

Replace $1- with $1 $2 $3 $4

Code:
on *:sockread:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1 $2 $3 $4 }
  elseif (%data == The channel is not live. - Oh hey, you're using an API meant for Nightbot, not for whatever you're using. Maybe you'd want to try out the new Nightbot beta: https://beta.nightbot.tv) msg %channel %target is currently not online.
}


I had to edit this because it wasn't displaying that the channel was offline. There is probably a cleaner way to format this.
Posted By: Thedelirious1

Re: Little socket script - problem with the message! - 07/01/16 05:26 AM

I got it working by adding some variables. It works for being online for less than an hour and more than an hour, and for being offline without the message from nightdev.com.

Code:
  var %delmessage = $deltok($1-, 5-30, 32)
  var %online $remove(%delmessage,- Oh)


Code:
on *:text:!uptime*:#:{
  if (!$2) { set %target $remove($chan,$chr(35)) }
  else set %target $iif($2,$2,$mid(#,2-))
  set %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 | halt }
  var %data
  sockread %data
  tokenize 32 %data
  var %delmessage = $deltok($1-, 5-30, 32)
  var %online $remove(%delmessage,- Oh)
  if ($1 isnum) && ($2) { msg %channel %target has been online for %online }
  elseif (%data == The channel is not live. - Oh hey, you're using an API meant for Nightbot, not for whatever you're using. Maybe you'd want to try out the new Nightbot beta: https://beta.nightbot.tv) msg %channel %target is currently not online.
}

on *:sockclose:uptime:{ 
  unset %channel
  unset %target
}
Posted By: FroggieDaFrog

Re: Little socket script - problem with the message! - 07/01/16 09:21 PM

If you make use of my JSON for mIRC script (found in my signature) this is quite easy, using twitch's own API:

Code:
on *:TEXT:!uptime*:#: {
  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
  if ($JSONError) {
    msg # Unable to retrieve the state of %stream
  }
  elseif ($regex($JSON(%json, streams, 0, created_at), /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/)) {
    %time = $calc($ctime($+($gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec, $regml(2), 32) $ord($base($regml(3), 10, 10)), $chr(44) $regml(1) $regml(4), :, $regml(5), :, $regml(6))) + ( $time(z) * 3600))
    msg # %stream has been online for $duration(%time)
  }
  else {
    msg # %stream is currently not online.
  }
}
© 2021 mIRC Discussion Forums