
Code: Select all
bind pub -|- !traffic traffic_pub
proc gettraffic {type direction time} {
set d 0
set t 0
switch -- [string tolower $direction] {
"in" { set d 1 }
"out" { set d 3 }
default { error "Invalid direction used" }
}
switch -- [string tolower $time] {
"today" { set t 0 }
"total" { set t 1 }
default { error "Invalid value type given" }
}
set traf [traffic]
if {[set idx [lsearch $traf "$type *"]] < 0} {
error "Invalid traffic type given"
}
return [lindex [lindex $traf $idx] [expr $d + $t]]
}
proc traffic_pub { nick uhost hand chan text } {
set totaltrafficin [gettraffic total in total]
set todaytrafficin [gettraffic total in today]
set totaltrafficout [gettraffic total out total]
set todaytrafficout [gettraffic total out today]
set totaltrafficin [calc_mb $totaltrafficin]
set todaytrafficin [calc_mb $todaytrafficin]
set totaltrafficout [calc_mb $totaltrafficout]
set todaytrafficout [calc_mb $todaytrafficout]
putserv "PRIVMSG $chan :Total : $totaltrafficin in, $totaltrafficout out"
putserv "PRIVMSG $chan :Today : $todaytrafficin in, $todaytrafficout out"
}
proc calc_mb { wert } {
if {[expr $wert > 1024] && [expr $wert < 1048576]} {
set wert [expr $wert / 1024]
lappend wert KB
} else {
if {[expr $wert > 1048576]} {
set wert [expr $wert / 1048576]
lappend wert MB
}
}
return $wert
}