egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

onlineserver.tcl - best server times (make public command)

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Thunderdome
Op


Joined: 15 Mar 2005
Posts: 187

PostPosted: Thu May 05, 2005 3:23 pm    Post subject: onlineserver.tcl - best server times (make public command) Reply with quote

Code:
#---------------------------------------------------------------------
# serveronline.tcl
# Tcl script for IRC bot eggdrop
#
# A ".bestserver" on the partyline displays a ranking of the servers
# with the longest online times (duration of connection between
# server and bot).
# Upon each disconnect from the ircserver the bot writes the
# duration of the connection to a file.
#
# v0: 23-Sep-2003
# v1: 27-Sep-2003
# v2: 01-Oct-2003
# + include current server
#---------------------------------------------------------------------

package require Tcl 8.4
package require eggdrop 1.6.15

#---------------------------------------------------------------------
# bindings
# dcc binding to display result
# event binding for logging online time when disconnecting
#---------------------------------------------------------------------

bind DCC n bestserver dcc:serveronline

bind EVNT - disconnect-server evnt:serveronline

#---------------------------------------------------------------------
# Upon a disconnect write time and online time to file
#---------------------------------------------------------------------

proc evnt:serveronline { type } {

   global server-online serveraddress

   set currenttime [clock seconds]

   set fileid [open serveronline.dat a+]

   puts $fileid "$serveraddress $currenttime ${server-online}"

   close $fileid

}

#---------------------------------------------------------------------
# Analyse the data file and report the respective online times.
#---------------------------------------------------------------------

proc dcc:serveronline { hand idx text } {

   global server-online serveraddress

   # initialise serverlist and serverdata

   set serverlist [list]

   # if data file exists, read data from file and analyse the data

   if { [file exists serveronline.dat] } {

      # read data from file

      set fileid [open serveronline.dat r]

      set serverdata [read $fileid]

      close $fileid

      # analyse data

      set serverdata [split $serverdata "\n"]

      foreach line $serverdata {

         if { [scan $line "%s %d %d" name distime contime] != 3 } {
            continue
         }

         set servertime [expr $distime - $contime]

         if { $servertime < 0 } { continue }

         set date [clock format $distime -format\
            "%d-%b-%y %H:%M" -gmt YES]

         lappend serverlist [list $name $date $servertime ]

      }

   }

   # if bot is connected add current server

   set name $serveraddress

   if { $name != "" } {   

      set curtime [clock seconds]

      set servertime [ expr $curtime - ${server-online} ]

      set date "<- I am here"

      lappend serverlist [list $name $date $servertime]

   }

   # no valid data?

   if { [llength $serverlist] < 1 } {
      putdcc $idx "No server online data available."
      return 1
   }

   # sort the list: longest connection time comes first

   set serverlist [lsort -index 2 -integer -decreasing $serverlist]

   # only take first 20 entries

   set serverlist [lrange $serverlist 0 19]

   # formatting: determine maximum string length of servername

   set namelen 0

   foreach serverinfo $serverlist {
      set servername [lindex $serverinfo 0]
      set serverlen [string length $servername]
      if { $serverlen > $namelen } { set namelen $serverlen }
   }

   incr namelen 3

   # formatting: rank, servername, onlinetime

   append fmtstring %-3d % - $namelen s %-18s %-s

   # output the servernames and the respective online times

   set count 0

   putdcc $idx "Servers (host:port), date and time of disconnection\
      and the online times:\r"

   foreach serverinfo $serverlist {
      incr count
      set servername [lindex $serverinfo 0]
      set serverdate [lindex $serverinfo 1]
      set servertime [duration [lindex $serverinfo 2] ]
      set string [format $fmtstring $count $servername\
         $serverdate $servertime]
      # seems my telnet client is bugged?
      append string "\r"
      putdcc $idx $string
   }

   putdcc $idx "End of servers and the online times.\r"

}

putlog "Loaded (version 2): Serveronline."


My ideia was just to put a !bestserver public command available...
how can it be done?
greetz
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu May 05, 2005 5:33 pm    Post subject: Reply with quote

try adding this to the script:
Code:
bind pub - !bestserver pub:serveronline

proc pub:serveronline {nick uhost hand chan text} {
   global server-online serveraddress
   # initialise serverlist and serverdata
   set serverlist [list]
   # if data file exists, read data from file and analyse the data
   if { [file exists serveronline.dat] } {
      # read data from file
      set fileid [open serveronline.dat r]
      set serverdata [read $fileid]
      close $fileid
      # analyse data
      set serverdata [split $serverdata "\n"]
      foreach line $serverdata {
         if { [scan $line "%s %d %d" name distime contime] != 3 } {
            continue
         }
         set servertime [expr $distime - $contime]
         if { $servertime < 0 } { continue }
         set date [clock format $distime -format "%d-%b-%y %H:%M" -gmt YES]
         lappend serverlist [list $name $date $servertime ]
      }
   }
   # if bot is connected add current server
   set name $serveraddress
   if { $name != "" } {   
      set curtime [clock seconds]
      set servertime [ expr $curtime - ${server-online} ]
      set date "<- I am here"
      lappend serverlist [list $name $date $servertime]
   }
   # no valid data?
   if { [llength $serverlist] < 1 } {
      puthelp "PRIVMSG $chan :No server online data available."
      return 1
   }
   # sort the list: longest connection time comes first
   set serverlist [lsort -index 2 -integer -decreasing $serverlist]
   # only take first 20 entries
   set serverlist [lrange $serverlist 0 19]
   # formatting: determine maximum string length of servername
   set namelen 0
   foreach serverinfo $serverlist {
      set servername [lindex $serverinfo 0]
      set serverlen [string length $servername]
      if { $serverlen > $namelen } { set namelen $serverlen }
   }
   incr namelen 3
   # formatting: rank, servername, onlinetime
   append fmtstring %-3d % - $namelen s %-18s %-s
   # output the servernames and the respective online times
   set count 0
   puthelp "PRIVMSG $chan :Servers (host:port), date and time of disconnection and the online times:\r"
   foreach serverinfo $serverlist {
      incr count
      set servername [lindex $serverinfo 0]
      set serverdate [lindex $serverinfo 1]
      set servertime [duration [lindex $serverinfo 2] ]
      set string [format $fmtstring $count $servername $serverdate $servertime]
      # seems my telnet client is bugged?
      append string "\r"
      puthelp "PRIVMSG $chan :$string"
   }
   puthelp "PRIVMSG $chan :End of servers and the online times.\r"
}


Edit: fixed code format.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts


Last edited by Sir_Fz on Fri May 06, 2005 8:21 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Thunderdome
Op


Joined: 15 Mar 2005
Posts: 187

PostPosted: Fri May 06, 2005 8:15 pm    Post subject: Reply with quote

Code:
Tcl error [pub:serveronline]: wrong # args: should be "clock format clockval ?-format string? ?-gmt boolean?"


this shows up .... the dcc still works, but not the pub... :\
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri May 06, 2005 8:23 pm    Post subject: Reply with quote

This is probably caused by the uncorrect code format after you pasted it. Try it now (I edited it.).
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Thunderdome
Op


Joined: 15 Mar 2005
Posts: 187

PostPosted: Fri May 06, 2005 8:40 pm    Post subject: Reply with quote

All okay! Thanks... I've been looking at the code... I get what you made... Smile
You passed all dcc-stuff to pub-stuff... so you have a proc for dcc and another for pub... Smile
Nice! Cool
Thanks for the work! Very Happy
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri May 06, 2005 9:54 pm    Post subject: Reply with quote

Glad you understood it Very Happy hopefully next time you'll be able to tweak such things by yourself Wink
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber