- Home»
- Cod sursa: top.users.tcl
top.users.tcl
top.users.tcl
TCL Script that keep stats for active users on channel. Command: .top [#channel] - requires moretools v1.1.6 or higher to run.
| Postat de | Copyright | Categorie | Review user | Vizualizari | Data |
|---|---|---|---|---|---|
| BLKoldSUN | MC_8 | stats | Cod netestat | 508 | 2023-12-25 10:09:38 |
##@
# Top Users v1.5 by MC_8 <[email protected]>
##@
# requires moretools v1.1.6 or higher to run.
# if using 1.3.28 (eggdrop) 1.1.7 version of moretools recomended.
##
# Dcc Command: .top [#channel]
##
# HISTORY
#
# v1.5 (11.22.99)
# max days was eating from wrong side of list, supposed to eat up oldest record not vice versa...
# added "Today's Growth" display to channel specific .top's
#
# v1.4 (10.30.99)
# updated the moretools look up
# added veriable on length of days to keep.
# added new display feature, average gain/lose per day to channel specific .top's
#
# v1.0 - v1.3 (??.??.??)
# Internal release
##
# Max number of entries (usually days, if bot is always up... isn't down for days at a time)
# to keep track of? (oldest get skim'd off) {0 is off}
set mc_t0p(max_days) 30
####
set mc_t0p(version) "v1.5"
if {[file exists TopUsers.tmp[lindex [date] 0]]} {
foreach line [split [exec cat TopUsers.tmp[lindex [date] 0]] \n] {
set mc_top([lindex $line 0]) [lrange $line 1 e]
}
foreach chan [string tolower [channels]] {
if {![info exists mc_top($chan)]} {
set mc_top($chan) "[llength [chanlist $chan]] [unixtime]"
exec echo "$chan $mc_top($chan)" >> TopUsers.tmp[lindex [date] 0]
}
}
} {
if {$server == ""} {if {[info exists mc_top]} {unset mc_top}} {
foreach chan [string tolower [channels]] {
set mc_top($chan) "[llength [chanlist $chan]] [unixtime]"
exec echo "$chan $mc_top($chan)" >> TopUsers.tmp[lindex [date] 0]
}
}
}
proc MC:top:join {nick uhost hand chan} {
global mc_top botnick
set chan [string tolower $chan]
if {![info exists mc_top($chan)]} {set mc_top($chan) "[llength [chanlist $chan]] [unixtime]"} {
if {[lindex $mc_top($chan) 0] < [llength [chanlist $chan]]} {
set mc_top($chan) "[llength [chanlist $chan]] [unixtime]"
set buffer "\{$chan $mc_top($chan)\}"
if {[file exists TopUsers.tmp[lindex [date] 0]]} {
foreach list [split [exec cat TopUsers.tmp[lindex [date] 0]] \n] {
if {[lindex $list 0] != $chan} {set buffer "\{$list\} $buffer"}
}
} {
foreach chann [string tolower [channels]] {
if {![info exists mc_top($chann)]} {
set mc_top($chann) "[llength [chanlist $chann]] [unixtime]"
}
if {$chann != $chan} {
set buffer "\{$chann $mc_top($chann)\} $buffer"
}
}
}
foreach file [split [exec find [pwd] -follow -name "TopUsers.tmp*"] \n] {
exec rm -r $file
}
foreach buffer2 $buffer {
exec echo "$buffer2" >> TopUsers.tmp[lindex [date] 0]
}
}
}
catch {unset buffer}
catch {unset list}
catch {unset chann}
catch {unset file}
catch {unset buffer2}
}
proc MC:top:time {m h d mo y} {
global mc_top mc_t0p server
if {![file exists TopUsers.doc]} {
exec echo "Channel Date Top Users Time" >> TopUsers.doc
}
set buffer [ctime [expr [unixtime] - [expr 60 * 60 * 24]]]
set buffer "[lindex $buffer 2] [lindex $buffer 1] [lindex $buffer 4]"
foreach file [split [exec find [pwd] -follow -name "TopUsers.tmp*"] \n] {
exec rm -r $file
}
foreach chan [array names mc_top] {
exec echo "$chan[str " " [expr 20-[string length $chan]]] [str " " [expr 11-[string length $buffer]]]$buffer [str " " [expr 9-[string length [lindex $mc_top($chan) 0]]]][lindex $mc_top($chan) 0] [lindex [ctime [lindex $mc_top($chan) 1]] 3]" >> TopUsers.doc
}
if {[info exists mc_top]} {unset mc_top}
foreach entry [split [exec cat TopUsers.doc] \n] {
if {![info exists mc_top([lindex $entry 0])]} {
set mc_top([lindex $entry 0]) "{$entry}"
} {
set mc_top([lindex $entry 0]) "$mc_top([lindex $entry 0]) {$entry}"
}
}
foreach chan [array names mc_top] {
# if {[llength $mc_top($chan)] > [expr $mc_t0p(max_days)-1]} {
set mc_top($chan) [lrange $mc_top($chan) [expr [llength $mc_top($chan)]-$mc_t0p(max_days)+2] e]
# }
}
catch {unset mc_top(Channel)} ; set overall(0) ""
foreach chan [array names mc_top] {
set overall(0) "$overall(0) $mc_top($chan)"
}
set overall(0) [lsort -real -index 1 $overall(0)]
set months "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set ver "[lrange $months [lsearch $months [lindex [ctime [unixtime]] 1]] e] [lrange $months 0 [expr [lsearch $months [lindex [ctime [unixtime]] 1]]-1]]"
set ver "[lrange $ver 1 e] [lindex $ver 0]" ; set overall(1) ""
foreach ver1 $ver {
foreach entry $overall(0) {
if {[lindex $entry 2] == $ver1} {
set overall(1) "$overall(1) {$entry}"
}
}
}
catch {exec rm -r TopUsers.doc}
exec echo "Channel Date Top Users Time" >> TopUsers.doc
foreach entry $overall(1) {
exec echo $entry >> TopUsers.doc
}
catch {unset mc_top} ; catch {unset overall} ; catch {unset chan} ; catch {unset i} ; catch {unset ver}
if {$server != ""} {
foreach chan [string tolower [channels]] {
set mc_top($chan) "[llength [chanlist $chan]] [unixtime]"
exec echo "$chan $mc_top($chan)" >> TopUsers.tmp[lindex [date] 0]
}
}
catch {unset buffer}
catch {unset file}
}
proc MC:top:dcc {hand idx args} {
global mc_top
if {[llength $args] == 1} {set args [lindex $args 0]}
set args [lindex [string tolower $args] 0]
set buffer2 ""
if {[llength $args]} {set buffer $args} {set buffer *}
if {[file exists TopUsers.doc]} {
set buffer2 [split [exec cat TopUsers.doc] \n]
set buffer2 [lrange $buffer2 1 e]
}
if {[info exists mc_top]} {
foreach chan [array names mc_top] {
set buffer2 "$buffer2 \{$chan[str " " [expr 20-[string length $chan]]] [str " " [expr 11-[string length [date]]]][date] [str " " [expr 9-[string length [lindex $mc_top($chan) 0]]]][lindex $mc_top($chan) 0] [lindex [ctime [lindex $mc_top($chan) 1]] 3]\}"
}
}
putdcc $idx "[color]0,12 [color]"
putdcc $idx "[color]0,12 [color]0,14[uline]Channel [uline] [uline]Date [uline] [uline]Top Users[uline] [uline]Time [uline][color]0,12 [color]"
set buffer3 0 ; set Sum 0 ; set Posts 0 ; set Top 0 ; set adg ""
foreach post $buffer2 {
if {[string match $buffer [lindex $post 0]]} {
putdcc $idx "[color]0,12 [color][reverse]$post[reverse][color]0,2 [color]0,12 [color]"
set buffer3 1
if {$buffer != "*"} {
set Sum [expr [lindex $post 4]+$Sum]
incr Posts 1
if {[lindex $post 4] > [lindex $Top 0]} {set Top "[lindex $post 4] [lindex $post 5] [lrange $post 1 3]"}
if {[info exists yg]} {set dg [expr [lindex $post 4]-$yg]} ; set yg [lindex $post 4]
set adg "$adg [lindex $post 4]"
}
}
}
if {!$buffer3} {
if {$args == ""} {putdcc $idx "Sorry, no top records right now."} {
putdcc $idx "Sorry, no top records for $args."
}
} {
if {$buffer != "*"} {
putdcc $idx "[color]0,12 [color][reverse]Average Top Users: [expr $Sum / $Posts][str " " [expr 35-[string length [expr $Sum / $Posts]]]][reverse][color]0,2 [color]0,12 [color]"
catch {
putdcc $idx "[color]0,12 [color][reverse]Today's Growth (from last entry): $dg[str " " [expr 20-[string length $dg]]][reverse][color]0,2 [color]0,12 [color]"
}
catch {
set adgr ""
for {set i 0} {$i < [expr [llength $adg]-1]} {incr i 1} {
set adgr "$adgr [expr [lindex $adg [expr $i+1]] - [lindex $adg $i]]"
}
set adg [expr [expr [join $adgr "+"]].0000000000 / [llength $adgr].0000000000]
putdcc $idx "[color]0,12 [color][reverse]Average Daily Growth: $adg[str " " [expr 32-[string length $adg]]][reverse][color]0,2 [color]0,12 [color]"
}
putdcc $idx "[color]0,12 [color][reverse]Top Users over all: [lindex $Top 0] users at [lrange $Top 1 e][str " " [expr 24-([string length [lindex $Top 0]] + [string length [lrange $Top 1 e]])]][reverse][color]0,2 [color]0,12 [color]"
unset Sum ; unset Posts ; unset Top
}
putdcc $idx "[color]0,12 [color]0,2 [color][color]0,12 [color]"
putdcc $idx "[color]0,12 ... And Growing Daily [color]"
}
catch {unset buffer}
catch {unset buffer2}
catch {unset buffer3}
return 1
}
if {(![info exists moretools]) || ($moretools < "010106")} {
catch {unbind join - * MC:top:join}
catch {unbind time - "00 00 * * *" MC:top:time}
catch {unbind dcc - top MC:top:dcc}
putlog "Top Users not loaded, you need to load moretools version 1.1.3 (before this one)"
} {
bind join - * MC:top:join
bind time - "00 00 * * *" MC:top:time
bind dcc - top MC:top:dcc
putlog "Top Users $mc_t0p(version) by MC_8 loaded"
}
IRC Snippets