mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2014
Posts: 42
K
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Aug 2014
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.


Last edited by Krawalli; 25/08/14 11:10 AM.
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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
Joined: Mar 2014
Posts: 42
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2014
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


Last edited by Sjoepele; 25/08/14 03:56 PM.
Joined: Aug 2014
Posts: 42
K
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Aug 2014
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 :<

Last edited by Krawalli; 25/08/14 05:16 PM.
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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
Joined: Mar 2014
Posts: 42
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2014
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...

Last edited by Sjoepele; 25/08/14 05:30 PM.
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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
Joined: Mar 2014
Posts: 42
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
You sir are a genius. Thanks!

Joined: Aug 2014
Posts: 42
K
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Aug 2014
Posts: 42
Perfect Nillen! Thanks a lot.

Joined: Apr 2015
Posts: 42
A
Ameglian cow
Offline
Ameglian cow
A
Joined: Apr 2015
Posts: 42
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

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
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? -> https://irc.chathub.org <-
Joined: Apr 2015
Posts: 42
A
Ameglian cow
Offline
Ameglian cow
A
Joined: Apr 2015
Posts: 42
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
}

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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
Joined: Dec 2015
Posts: 5
Y
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
Y
Joined: Dec 2015
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

Joined: Apr 2014
Posts: 24
T
Ameglian cow
Offline
Ameglian cow
T
Joined: Apr 2014
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.

Last edited by Thedelirious1; 06/01/16 03:15 PM.
Joined: Apr 2014
Posts: 24
T
Ameglian cow
Offline
Ameglian cow
T
Joined: Apr 2014
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
}

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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

Link Copied to Clipboard