Noticias:

Juega trivias en español en el canal #Trivias

Menú Principal

Stats

Iniciado por TerraChat, Ago 14, 2024, 02:15 PM

Tema anterior - Siguiente tema

TerraChat

# to enable on #channel:
# .chanset #channel +cstats

namespace eval cstats {

   variable stats
   variable peak

   setudef flag cstats
   
   # Normal proc
   proc logpubm {nick uhost handle chan text} {
      if {[string index $text 0] eq "\001"} { return }
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,pub)
      }
   }
   
   proc logact {nick uhost handle chan key text} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,act)
      }
   }
   
   proc lognick {nick uhost handle chan newnick} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::stats($chan,nick)
      }
   }
   
   proc logjoin {nick uhost handle chan} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,join)
         set tmp [llength [chanlist $chan]]
         if {[info exists ::cstats::peak($chan)] && $::cstats::peak($chan)<$tmp} {
            set ::cstats::peak($chan) $tmp
         }
      }
   }
   
   proc logpart {nick uhost handle chan text} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,part)
      }
   }

   proc logsign {nick uhost handle chan text} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,quit)
      }
   }

   proc logkick {nick uhost handle chan target text} {
      if {[validchan $chan] && [channel get $chan cstats]} {
         incr ::cstats::stats($chan,kick)
      }
   }
   
   proc logban {nick uhost handle chan mode {target ""}} {
      if {[validchan $chan] && [channel get $chan cstats] && mode eq "+b"} {
         incr ::cstats::stats($chan,ban)
      }
   }


   proc showstats {min hour day month dow} {
      foreach c [channels] {
         if {![channel get $c cstats]} {
            continue
         }
         ::cstats::init $c
         putserv "PRIVMSG $c :Stats $c: Join(s): $::cstats::stats($c,join) | Part(s): $::cstats::stats($c,part) | Quit(s): $::cstats::stats($c,quit) | Kick(s): $::cstats::stats($c,kick) | Ban(s): $::cstats::stats($c,ban) | Peak: $::cstats::peak($c)"
         putserv "PRIVMSG $c :[::cstats::culist $c]"
      }
   }

   proc init {chan} {
      foreach t [list pub act nick join part quit ban] {
         if {![info exists ::cstats::stats($chan,$t)]} {
            set ::cstats::stats($chan,$t) 0
         }
         if {![info exists ::cstats::peak($chan)]} {
            set ::cstats::peak($chan) 0
         }
      }
   
   }
   
   proc culist {chan} {
      set op 0
      set hop 0
      set vop 0
      set uop 0
      foreach user [chanlist $chan] {
         if { [isop $user $chan] == 1 } {
            incr op
         } elseif { [ishalfop $user $chan] == 1 } {
            incr hop
         } elseif { [isvoice $user $chan] == 1 } {
            incr vop
         } else {
            incr uop
         }
      }
      return "Stats $chan: @ Total: $op | % Total: $hop | + Total: $vop | Total Users: $uop"
   }
   
   bind pubm - * ::cstats::logpubm
   bind ctcp - "ACTION" ::cstats::logact
   bind nick - * ::cstats::lognick
   bind join - * ::cstats::logjoin
   bind part - * ::cstats::logpart
   bind sign - * ::cstats::logsign
   bind kick - * ::cstats::logkick
   bind mode - "* +b" ::cstats::logban
   bind cron - "0 */2 * * *" ::cstats::showstats
}