rendered paste bodynamespace eval ::ngBot::top {
variable top
## Config Settings ###############################
##
## Interval between announces in seconds (default: 7200 - 2 hours)
set top(interval) 7200
##
## Path to the glftpd stats executable
set top(stats-exec) "/glftpd/bin/stats"
##
## Section to display
set top(sect) 0
##
## Maximum number of users to display
set top(users) 10
##
## Message prefix
set top(prefix) "Week Top (Up): "
##
## Output channels
set top(chan) "#pzs-ng"
##
##################################################
variable timer
}
proc ::ngBot::top::killTimer {} {
variable timer
if {[catch {killutimer $timer} error] != 0} {
putlog "\[ngBot\] Top :: Warning: Unable to kill announce timer \"$error\""
}
}
proc ::ngBot::top::startTimer {} {
variable top
variable timer [utimer $top(interval) "[namespace current]::showTop"]
}
proc ::ngBot::top::showTop {args} {
variable top
[namespace current]::startTimer
if {[catch {exec $top(stats-exec) -u -w -x $top(users) -s $top(sect)} output] != 0} {
putlog "\[ngBot\] Top :: Error: Problem executing stats-exec \"$output\""
return
}
set msg [list]
foreach line [split $output "\n"] {
regsub -all -- {(\s+)\s} $line " " line
if {[regexp -- {^\[(\d+)\] (\w+) (.*?) (\d+) (\d+)\w+ (\S+)} $line -> pos username tagline files bytes speed]} {
lappend msg "\[$pos. $username \002$bytes\002M\]"
}
}
if {[llength $msg] == 0} {
set msg "Empty..."
}
foreach chan [split $top(chan)] {
puthelp "PRIVMSG $chan :$top(prefix) [join $msg " "]"
}
}
::ngBot::top::killTimer
::ngBot::top::startTimer