This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

online timer on irc server

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

online timer on irc server

Post by Fire-Fox »

Hey

Is there a script that shows total online timer on irc server

Like:

1. irc.name.org Uptime: 1 Day 2 hours 5 mins.

And possible to add more :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

# Time in minutes to check for server's uptime 
# 
set suptime(config:time) "30" 

# Send a warning to all channels with +suptime about server's going down? 
# Usage: 
#        1     =>   enable (recommended) 
#        0     =>   disable 
# 
set suptime(config:warn) "1" 

# The warning message to display in channels when a server is lost 
#  (netsplit or unlinked from the irc network) 
# 
# %date         => Date and Time 
# %server       => The name of the server 
# 
# <message-type>        can be:  PRIVMSG or NOTICE 
# 
set suptime(config:info) "PRIVMSG I've lost %server on %date" 

proc suptime:dcc {handle idx text} { 
 global suptime 
  set indx 0 
  if {[llength $text] == 0} { 
  if {[llength [array get suptime "*:start"]] == 0} { 
   putidx $idx "server's list is empty." 
   return 1
  } elseif {([llength [array get suptime "*:start"]] != 0) && ([llength [array get suptime "*:uptime"]] == 0)} {
   putidx $idx "server's uptimes not available"
   return 1
  } else {
   foreach {string rest} [array get suptime "*:uptime"] {
    set indx [expr {$indx+1}] 
    set s_name [lindex [split "$string" ":"] 0] 
    set from $::suptime($s_name:start)
    set to $rest
     if {($from == "") && ([info exists suptime($s_name:info)])} { 
      putidx $idx "$indx. $s_name \[$::suptime($s_name:info)\] Last Uptime: [duration [expr {$::suptime($s_name:lastuptime) - $from}]]" 
     } elseif {($from != "") && ($to != "")} { 
      putidx $idx "$indx. $s_name Uptime: [duration [expr {$to-$from}]]" 
     } else {
       if {[info exists suptime($s_name:info)]} {
        putidx $idx "$indx. $s_name ($::suptime($s_name:info))"
       } else {
        putidx $idx "$indx. $s_name (unknown)"
       }
     }
   }
    return 1
   }
  }
  set cmd [lindex [split $text] 0] 
  switch $cmd { 
   "list" { 
           if {[llength [array get suptime "*:start"]] == 0} { 
            putidx $idx "server's list is empty." 
            return 1 
           } 
           foreach {string rest} [array get suptime "*:start"] { 
            set indx [expr {$indx+1}] 
            putidx $idx "$indx. [lindex [split "$string" ":"] 0] Added [duration [expr {[clock seconds] - [lindex [split $rest] 0]}]] ago." 
           }; return 1
          }
   "del" { 
          set d_name [lindex [split $text] 1] 
          if {$d_name == ""} { 
           putidx $idx "Usage: .suptime <add/del/list> \[server-name\]" 
          } elseif {[info exists suptime($d_name:start)]} { 
           array unset suptime $d_name:start 
           array unset suptime $d_name:uptime 
           array unset suptime $d_name:info 
           array unset suptime $d_name:lastuptime 
           putidx $idx "removed '$d_name' from server list" 
          } else { 
           putidx $idx "unable to find '$d_name' in server list" 
          }; return 1
         }
   "add" { 
          set a_name [lindex [split $text] 1] 
          if {$a_name == ""} { 
           putidx $idx "Usage: .suptime <add/del/list> \[server-name\]" 
          } elseif {[info exists suptime($a_name:start)]} { 
           putidx $idx "server '$a_name' already exists!" 
          } else { 
           set suptime($a_name:start) [clock seconds]
           putidx $idx "added '$a_name' to server's list"
          }; return 1
         }
  }
}

proc suptime:351 {from keyword text} { 
 global suptime 
 set rtime [clock seconds] 
 set sname [string tolower [lindex [split $text] 2]] 
 if {[info exists suptime($sname:start)]} { 
  set suptime($sname:uptime) $rtime 
  return
 } 
} 

proc suptime:402 {from keyword text} { 
 global suptime 
 set date [clock format [clock seconds]] 
 set sname [string tolower [lindex [split $text] 1]] 
 if {([info exists suptime($sname:start)]) && (![info exists suptime($sname:uptime)])} {
  putloglev 1 * "recived \"bad server name\" error for server: $sname"
  return
 } elseif {([info exists suptime($sname:start)]) && ([info exists suptime($sname:uptime)])} {
  set suptime($sname:lastuptime) $suptime($sname:uptime) 
  set suptime($sname:uptime) "" 
  set suptime($sname:info) "Offline" 
   if {$suptime(config:warn)} { 
    foreach dest [channels] { 
     if {[channel get $dest suptime]} { 
      regsub -all "%server" "[join [lrange [split $suptime(config:info)] 1 end]]" "$sname" msg 
      regsub -all "%date" "$msg" "$date" msg 
      puthelp "[lindex [split $suptime(config:info)] 0] $dest :$msg" 
     }
    }
   }; return
 } else {
  return
 }
}

proc suptime:time {minute hour day month year} { 
 global suptime 
 set halt 3 
  if {[llength [array get suptime "*:start"]] == 0} { 
   return 
  } 
  foreach {string rest} [array get suptime "*:start"] { 
   timer $halt [list putserv "VERSION [lindex [split "$string" ":"] 0]"] 
   set halt [expr {$halt+1}] 
  } 
  putloglev 1 * "Checking server uptimes..." 
  return
}

setudef flag suptime 
bind dcc mt|mt suptime suptime:dcc 
bind time - "$suptime(config:time) * * * *" suptime:time 
bind raw - 351 suptime:351 
bind raw - 402 suptime:402 

putlog "loaded suptime.tcl version 1.1 by TLC_no_TK" 
return
:P
not tested, but as long as the servers on the irc network allow /version command and support the 351 numeric (which google says they all do) it should work fine :)

EDIT: see post(s) below
Last edited by TCL_no_TK on Fri Jul 10, 2009 1:46 pm, edited 2 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'd suggest you don't use "args" with your raw bindings, and you've got a few list operations on strings in your suptime:dcc. The "channel get" command expects suptime, not +suptime, as it's a udef flag.

Also, the "start" value is set to when the "add" command was run, not when the server was first seen online. Equally, it is only cleared when the "del" command is run, not whenever the server is detected as offline. At best, you'll report the time elapsed between your "add" command and the last timestamp before the server was detected as offline for the most recent time.

Finally, I'm having a hard time making any sense of your nested foreach-loops and the corresponding splits and maths. To me, it would seem you would compare each server's :start value with each server's :uptime value, not only server1:start with server1:uptime and server2:start with server2:uptime.

The approach with the VERSION-test seems like a perfectly valid approach though.
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

[quote="TCL_no_TK"]

Code: Select all

   foreach {string_1 rest_1} [array get suptime "*:uptime"] {
   foreach {string_2 rest_2} [array get suptime "*:start"] {
    set indx [expr {$indx+1}]
    set s_name [lindex [split "$string_1" ":"] 0]
    set s_from [lindex [split $rest_2] 1]
    set s_to [lindex [split $rest_1] 1]
     if {($s_from == "") && ([info exists suptime($s_name:info)])} {
      putidx $idx "$indx. $s_name \[$suptime($s_name:info)\] Last Uptime: [duration [expr {$s_from - $suptime($s_name:lastuptime)}]]"
     } elseif {$s_from != ""} {
      putidx $idx "$indx. $s_name Uptime: [duration [expr {$s_from - $s_to}]]"
     } else {
      putidx $idx "$indx. $s_name (unknown)"
     }
   }
   };
Wow.. this part is just amazing. Only because of the mistakes made within it. Why are there two foreach's nested into each other? You do realize the inner foreach will be repeated each iteration of the outer one right? What this means primarily is your putlogs will appear out of sequence and will also repeat often.

I see what you intended by using that method. How else can you loop through the contents of two [array get]'s at once and get any contents? Well you can use a simple counter that is offset by -1 and incr it each iteration by 2. Then using lindex against this counter you can find your way along the second array. That is _if_ both contents line up built exactly the same, which we will assume here that yours is.

Code: Select all

   set counter -1
   foreach {name value} [array get suptime "*:uptime"] {
     set indx [expr {$indx+1}]
     set s_name [lindex [split "$name" ":"] 0]
     set s_from [lindex [split [lindex [array get suptime "*:start"] [expr {[incr counter 2}]]] 1]
     set s_to [lindex [split $value] 1]
     if {($s_from == "") && ([info exists suptime($s_name:info)])} {
       putidx $idx "$indx. $s_name \[$suptime($s_name:info)\] Last Uptime: [duration [expr {$s_from - $suptime($s_name:lastuptime)}]]"
     } elseif {$s_from != ""} {
       putidx $idx "$indx. $s_name Uptime: [duration [expr {$s_from - $s_to}]]"
     } else {
       putidx $idx "$indx. $s_name (unknown)"
     }
   };
This code may still be flawed. It still puzzles me why you've used [split] when all the values of the array you build are simply single elements consiting of [seconds]... But..., let's remember, I've only corrected your amazing nested foreach's and the repeated putlog's that would've appeared as a result. I'm guessing this is what nml375 meant when he observed the same. This is just so your aware of it too.. ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

speechles,
Wouldn't it simply be easier to use the s_name value and build the index of the array, than using that complex code with array get, counter, and praying we end up with the correct list offset?

Btw, what's the point of encapsulating the incr command with expr?
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:speechles,
Wouldn't it simply be easier to use the s_name value and build the index of the array, than using that complex code with array get, counter, and praying we end up with the correct list offset?

Btw, what's the point of encapsulating the incr command with expr?
Of course it would've.. lmao.. But I was more puzzled at how he expected the nested foreach's to even work. So was giving really an alternative to times when those are required. Which may be never, haw. But certainly yes, referring directly to the values would be infinitely easier.. Having two arrays come out exactly parallel to each other is what the way I described requires. This may not be possible and using [lsort] on an inline list really isn't advisable. So forcing them to align isn't exactly simple either.

The [expr] command is there because of how I approached it the first time. Instead of offseting the counter and [incr 2] I tried to simply [incr] the counter and [expr] * 2 + 1. That way of course was flawed. But it's there now because you never gave me enough time to ponder my post and silently correct it. I would have to go back and edit it leaving bread crumbs, aka edit: tags.. xD :P
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

But it's there now because you never gave me enough time to ponder my post and silently correct it.
That's why there is a preview button.. And if you're so afraid of it saying "Edited", then perhaps you should put more thought into your posts before hitting the submit button.

That aside, there really is no reliable way of making sure the output of the two "array get"'s will be in sync, as "The order of the pairs is undefined" (taken from array manpage).
NML_375
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

I only needed 1 foreach loop. makes sense. The use of args with the raw binds, was thinking of an other post at the time. but thats fixed, and the +suptime on the channel get, was down to just working out what channel option name i was going to use. Alot of it i didn't have time to go over while writting it on the small window you get on the forum, will try and do it on ma computer or something give me more time check for error's. As for the use of VERSION, this allows the script to check for server's that are hidden on some irc networks. since they still reply to version command, it seems like a "good work around" in this case. As for just basic understanding of how its working out the uptime of the server, it only needs to do that from when the server was added => to the last time we checked. It only creats a "last uptime" when the server isn't found on the network anymore. hopefully, that makes sense, its pretty simple to me. since they script isn't there to just send the server's uptime. it just if the server is online, and then displays the duration its been online from when the server was added to the script. In a nut shell, the script was created with the idea it would be helpful to find the server thats online the most while eggdrop is running.

P.S the use of 'split' is a habbit i got ma self in to. i try not follow the man pages by the letter, and just prefer to work things out for myself.
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Post by Fire-Fox »

Hey

Nice TCL_no_TK :) does it have a pub trigger? if not, have could i get it :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

It was mostly down to nml375 & speechles in the end :D but, the public command (basicly just the same as the dcc command apart from most of the ouput is to the user/channel)

Code: Select all

bind pub mt|mt !suptime pub:suptime

proc pub:suptime {nick host handle channel text} {
global suptime
  set indx 0 
  if {[llength $text] == 0} { 
  if {[llength [array get suptime "*:start"]] == 0} { 
   puthelp "NOTICE $nick :server's list is empty." 
   return 0
  }
   foreach {string_1 rest_1} [array get suptime "*:uptime"] { 
    set indx [expr {$indx+1}] 
    set s_name [lindex [split "$string_1" ":"] 0] 
    set s_from $suptime($s_name:start)
    set s_to [lindex [split $rest_1] 1] 
     if {($s_from == "") && ([info exists suptime($s_name:info)])} { 
      puthelp "PRIVMSG $channel :$indx. $s_name \[$suptime($s_name:info)\] Last Uptime: [duration [expr {$s_from - $suptime($s_name:lastuptime)}]]" 
     } elseif {$s_from != ""} { 
      puthelp "PRIVMSG $channel :$indx. $s_name Uptime: [duration [expr {$s_from - $s_to}]]" 
     } else { 
      puthelp "PRIVMSG $channel :$indx. $s_name (unknown)" 
     }
   }; return 1 
  }
  set cmd [lindex [split $text] 0] 
  switch $cmd -- { 
   "list" { 
           if {[llength [array get suptime "*:start"]] == 0} { 
            puthelp "NOTICE $nick :server's list is empty." 
            return 1 
           } 
           foreach {string rest} [array get suptime "*:start"] { 
            set indx [expr {$indx+1}] 
            puthelp "PRIVMSG $channel :$indx. [lindex [split "$string" ":"] 0] Added [duration [expr {[clock seconds] - [lindex [split $rest] 0]}]] ago." 
           } 
          }
   "del" { 
          set d_name [lindex [split $text] 1] 
          if {$d_name == ""} { 
           puthelp "NOTICE $nick :Usage: .suptime <add/del/list> \[server-name\]" 
          } elseif {[info exists suptime($d_name:start)]} { 
           array unset suptime $d_name:start 
           array unset suptime $d_name:uptime 
           array unset suptime $d_name:info 
           array unset suptime $d_name:lastuptime 
           puthelp "NOTICE $nick :removed '$d_name' from server list" 
          } else { 
           puthelp "NOTICE $nick :unable to find '$d_name' in server list" 
          } 
         } 
   "add" { 
          set a_name [lindex [split $text] 1] 
          if {$a_name == ""} { 
           puthelp "NOTICE $nick :Usage: .suptime <add/del/list> \[server-name\]" 
          } elseif {[info exists suptime($a_name:start)]} { 
           puthelp "NOTICE $nick :server '$a_name' already exists!" 
          } else { 
           set suptime($a_name:start) [clock seconds]
           puthelp "NOTICE $nick :added '$a_name' to server's list."
          } 
         } 
  }; return 1 
}
again not tested :twisted:
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Just stepped through the code by hand, and I must say it currently does not work:

"!suptime add test" sets suptime(test:start) to the current timestamp.
At some time, the timer will send a Version request
If the server is online, we see if suptime(test:uptime) is set, if it is, we update it, if not we don't do anything.
Since it's not yet set, we won't do anything.
If the server is not online, we check for the existance of suptime(test:start): if set, we try to set suptime(test:lastuptime) to the value of suptime(test:uptime) - unfortunately, this is not set, and the script bails out.

Also, the "!suptime" command will fail as you use a foreach-loop on the suptime array filtered on *:uptime - which again is never set in your script. The "if ($s_from == "")" test is rather useless, as the supname(name:start) is always set to hold an integer value, and thus is never an empty string.

Still, the math is flawed in the case the server goes offline and then online again. In this case, the start-time should've been updated to the first time the server is seen online again, rather than hold the time when it was added to the "watch list".

Don't feel discouraged though, your ideas are good - you just need to tie up a few loose ends.
NML_375
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

have time to test to nite when i got in from work :) should be working ok now, i've still not tested the public command but i'm guessing still i just used the last code, it will not work. I'll edit that post and use the fixed one to see if it will work then :P
Post Reply