mIRC Home    About    Download    Register    News    Help

Topic Options
#247752 - 25/08/14 12:06 PM Little socket script - problem with the message!
Krawalli Offline
Ameglian cow

Registered: 01/08/14
Posts: 42
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.



Edited by Krawalli (25/08/14 12:10 PM)

Top
#247757 - 25/08/14 01:39 PM Re: Little socket script - problem with the message! [Re: Krawalli]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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
}
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#247758 - 25/08/14 01:41 PM Re: Little socket script - problem with the message! [Re: Krawalli]
Sjoepele Offline
Ameglian cow

Registered: 22/03/14
Posts: 42
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



Edited by Sjoepele (25/08/14 04:56 PM)

Top
#247763 - 25/08/14 06:15 PM Re: Little socket script - problem with the message! [Re: Nillen]
Krawalli Offline
Ameglian cow

Registered: 01/08/14
Posts: 42
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 :<


Edited by Krawalli (25/08/14 06:16 PM)

Top
#247765 - 25/08/14 06:29 PM Re: Little socket script - problem with the message! [Re: Krawalli]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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
}
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#247766 - 25/08/14 06:29 PM Re: Little socket script - problem with the message! [Re: Krawalli]
Sjoepele Offline
Ameglian cow

Registered: 22/03/14
Posts: 42
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...


Edited by Sjoepele (25/08/14 06:30 PM)

Top
#247767 - 25/08/14 06:34 PM Re: Little socket script - problem with the message! [Re: Sjoepele]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#247768 - 25/08/14 06:39 PM Re: Little socket script - problem with the message! [Re: Nillen]
Sjoepele Offline
Ameglian cow

Registered: 22/03/14
Posts: 42
You sir are a genius. Thanks!

Top
#247769 - 25/08/14 06:44 PM Re: Little socket script - problem with the message! [Re: Nillen]
Krawalli Offline
Ameglian cow

Registered: 01/08/14
Posts: 42
Perfect Nillen! Thanks a lot.

Top
#255116 - 24/09/15 12:19 AM Re: Little socket script - problem with the message! [Re: Nillen]
Artiiz Offline
Ameglian cow

Registered: 03/04/15
Posts: 42
Loc: Sweden
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

Top
#255129 - 25/09/15 02:08 PM Re: Little socket script - problem with the message! [Re: Artiiz]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
Try use this:

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


/help $replace
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#255141 - 25/09/15 09:21 PM Re: Little socket script - problem with the message! [Re: westor]
Artiiz Offline
Ameglian cow

Registered: 03/04/15
Posts: 42
Loc: Sweden
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
}

Top
#255142 - 25/09/15 09:50 PM Re: Little socket script - problem with the message! [Re: Artiiz]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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.
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#256286 - 06/01/16 06:13 AM Re: Little socket script - problem with the message! [Re: Nillen]
YeyoSsj Offline
Nutrimatic drinks dispenser

Registered: 14/12/15
Posts: 5
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

Top
#256290 - 06/01/16 03:01 PM Re: Little socket script - problem with the message! [Re: YeyoSsj]
Thedelirious1 Offline
Ameglian cow

Registered: 11/04/14
Posts: 24
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.


Edited by Thedelirious1 (06/01/16 03:15 PM)

Top
#256296 - 07/01/16 05:26 AM Re: Little socket script - problem with the message! [Re: YeyoSsj]
Thedelirious1 Offline
Ameglian cow

Registered: 11/04/14
Posts: 24
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
}

Top
#256299 - 07/01/16 09:21 PM Re: Little socket script - problem with the message! [Re: Krawalli]
FroggieDaFrog Offline
Hoopy frood

Registered: 16/04/10
Posts: 910
Loc: USA
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.
  }
}
_________________________
I am SReject
My Stuff

Top