### CHANNELTALK STATISTICS ### By Goblet 1997 email: goblet@sci.fi ### ### Sorry for some finnish-language variable names, ### I'm just too lazy to translate them... ### ---------------------------------------------------------------- ### Masters can zero somebody's stats with command .formuser handle ### and users can also ask their stats ny msging the bot word "STAT" catch {unset wwwfile} catch {unset wwwlfile} catch {unset lfile} ## These are in order: ## fastlog file for logging the channel which clears after 200 publics ## webfile with a html-table ## webfile, only text for lynx users. ##which channel should stat? set statchan "#ste31" set lfile "/wwwhome/goblet/public_html/ste31/ste31.log.fast" logfile jkps * $lfile set wwwfile "/wwwhome/goblet/public_html/ste31/ste31stat.htm" set wwwlfile "/wwwhome/goblet/public_html/ste31/ste31stat_lynx.htm" ## after how many publics should update be done? set updatestat 10 ## should userfile be saved same time as the statistics-web page updates? set saveonupdate 1 ### ------ code begins ----------------------- bind pubm - * count_words proc count_words {nick uhost hand chan text} { if {[validuser $hand] != 1} {return 0} set sana 1 set kirjain 0 foreach i [split $text {}] { incr kirjain if {$i == " "} { incr sana } } set sanoja [user_get $hand "words"] user_set $hand "words" [expr { $sanoja + $sana }] set pubcomments [user_get $hand "comments"] user_set $hand "comments" [expr { $pubcomments + 1 }] set kirj [user_get $hand "letters"] user_set $hand "letters" [expr { $kirj + $kirjain - $sana + 1 }] } ## .formuser handle clears somebody's statistics if he has flooded ## to get higher on list (this has really happened ;-) bind dcc m formuser dcc_formatuser proc dcc_formatuser {hand idx text} { putlog "Set parms user $text to 0" user_set $text "words" 0 user_set $text "comments" 0 user_set $text "letters" 0 user_set $text "gone" 0 } proc user_get {handle key} { set xtra [getxtra $handle] for {set i 0} {$i < [llength $xtra]} {incr i} { set this [lindex $xtra $i] if {[string compare [lindex $this 0] $key] == 0} { return [lindex $this 1] } } return 0 } proc user_set {handle key data} { set xtra [getxtra $handle] for {set i 0} {$i < [llength $xtra]} {incr i} { set this [lindex $xtra $i] if {[string compare [lindex $this 0] $key] == 0} { set this [list $key $data] setxtra $handle [lreplace $xtra $i $i $this] return } } lappend xtra [list $key $data] setxtra $handle $xtra } ## word/comment/lettercounter ends set cmnts [expr { $updatestat -1 }] set cmnts2 198 bind pubm - * count_comment proc count_comment {nick uhost hand chan text} { global cmnts cmnts2 lfile incr cmnts incr cmnts2 if {$cmnts >= $updatestat} { set cmnts 0 if {$saveonupdate == 1} {save} do_stats } if {$cmnts2 >= 200} { set fdlog [open $lfile w] set cmnts2 1 puts $fdlog "log start [date] [time]" close $fdlog } } proc do_stats {} { global wwwfile wwwlfile set fd [open $wwwfile w] set fdl [open $wwwlfile w] puts $fd "" puts $fd "Top 50 talkers on channel $statchan" puts $fd "

Top 50 talkers on channel $statchan

" puts $fdl "Top 50 talkers on channel $statchan" puts $fdl "Top 50 talkers on channel $statchan
" puts $fd "" puts $fd "" puts $fdl "[time]

" puts $fd "" set handle [lindex $i 1] set chost [lindex [gethosts $handle] 0] set w_word [user_get $handle "words"] set w_comm [user_get $handle "comments"] set w_letr [user_get $handle "letters"] set lastonchan [ctime [user_get $handle "gone"]] if {[user_get $handle "gone"] == 0} {set lastonchan "Who cares?"} if {[onchan $handle $statchan] == 1 } {set lastonchan "NOW!"} puts $fd "" puts $fd "" puts $fd "" puts $fd "" puts $fd "" puts $fd "" puts $fd "" puts $fdl "
"
        puts $fdl "Nr:          $no"
        puts $fdl "Nick:        $handle"
        puts $fdl "Hostmask:    $chost"
        puts $fdl "Last on:     $lastonchan"
        puts $fdl "Words:       $w_word"
        puts $fdl "Comments:    $w_comm"
        puts $fdl "Letters:     $w_letr"
        puts $fdl "---------------------------------------------"
	puts $fdl "
" } } puts $fd "
[time]
Nr" puts $fd "Nick" puts $fd "Hostmask" puts $fd "Last on" puts $fd "Words" puts $fd "Comments" puts $fd "Letters" foreach i [userlist] { if {[matchattr $i 1] == 0} { set apu "[user_get $i "words"] $i" lappend apulist $apu } } set apulista [lsort -decreasing -command cmp $apulist] set no 0 foreach i $apulista { incr no if {$no < 51} { puts $fd "
$no$handle$chost$lastonchan$w_word$w_comm$w_letr

" puts $fd "
This page updates after $updatestat public messages.

" puts $fd "
© Goblet 1997
" puts $fd "" puts $fdl "This page updates after $updatestat public messages.
" puts $fdl "© Goblet 1997" puts $fdl "" close $fd close $fdl } proc cmp {one two} { if {[lindex $one 0] > [lindex $two 0]} { return 1 } elseif {[lindex $one 0] < [lindex $two 0]} { return -1 } else { return 0 } } bind msg - stat msg_stat proc msg_stat {nick uhost hand arg} { if {[validuser $hand] != 1} {return 0} set m_word [user_get $hand "words"] set m_comm [user_get $hand "comments"] set m_letr [user_get $hand "letters"] putserv "NOTICE $nick :You've said $m_comm comments, $m_word words, $m_letr letters." } bind part - * set_utim_p bind sign - * set_utim_s proc set_utim_p {nick uhost hand chan} { user_set $hand "gone" [unixtime] do_stats } proc set_utim_s {nick uhost hand chan arg} { user_set $hand "gone" [unixtime] do_stats } putlog "Channeltalk-statistics 0.2 by Goblet"