This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Word Count/ Stats [SOLVED]

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Word Count/ Stats [SOLVED]

Post by cache »

I saw someone have this on mIRC just thought it be cool to have it on eggdrop, so if anyone can do this i'd be thankful :)

Here is what it does.

Word Count: Keeps track of how many words a chatter typed
Letter Count: Keeps track of how many letters chatter typed
Smile Count: Keeps track of how many smiles :) :-) chatter used
Time Wasted: How long they have wasted sitting in chat (chatting or idle together)

Sample of it used...
<Chatter> !mystats
<Bot> [STATS] Chatter: 4135 words, 15222 letters, 80 smilies, time wasted: 315 hours 22 minutes 49 seconds.

And the "word count" part comes with !top10stats showing the top 10 chatters word count score.

:?:
Last edited by cache on Thu Sep 13, 2007 12:18 am, edited 1 time in total.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Re: Word Count/ Stats

Post by TCL_no_TK »

I think the stats module dose this and, there might be a few scripts that do this in the TCL Archive.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Ok thanks, I will try my search again.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

I found one to suit my needs but there is a problem...

It works and saves data, but if I restart bot it stops working till user re-joins channel by typing /hop

This is error I get after I restart bot and type $stats
[09:44] Tcl error [::statistics::monitor]: can't read "lines": no such variable.

And this is error I get when I type $top10
[09:46] Tcl error [::statistics::toplist]: element 1 missing from sublist " 1"

Is this normal?

Here is the script:

Code: Select all

# Statistics.tcl (C) 2004 perpleXa
#  type ".chanset <chan> +stat" on the partyline to ativate the script for a specific channel.
#  commands: $stat <nick> - shows information about you or a nick. (works only for other nicks when you are op on a channel)
#            $top10 <smilies|words|lines|letters> - shows the top10 chatters, default option is words
#            $top20 <smilies|words|lines|letters> - same as $top10 but with places 11-20

namespace eval statistics {
# Storage file
  variable storage {scripts/dbase/statistics}

# Kill unused entries after x days
  variable killafter 30

# Command trigger
  variable trigger {$}

# smiley regex (only touch this, if you really know, what you are doing!)
  variable smileyregex {(:|8|;)(-|o)?(>|<|D|O|o|\)|\(|\]|\[|P|p|\||\\|/)}

  bind PUB   -|-  ${trigger}stat   [namespace current]::spew
  bind PUB   -|-  ${trigger}top10  [namespace current]::toplist
  bind PUB   -|-  ${trigger}top20  [namespace current]::toplist
  bind PUBM  -|-  *                [namespace current]::monitor
  bind CTCP  -|-  ACTION           [namespace current]::ctcp
  bind EVNT  -|-  save             [namespace current]::save
  bind TIME  -|-  {00 * * * *}     [namespace current]::cleanupdb

  setudef flag stat

  namespace export spew top10 toplist save load monitor
}

proc statistics::ctcp {nickname hostname handle target keyword arguments} {
  if {[validchan $target]} {
    monitor $nickname $hostname $handle $target $arguments
  }
  return 0
}

proc statistics::monitor {nickname hostname handle channel arguments} {
  variable data
  variable smileyregex
  if {([isbotnick $nickname]) || (![channel get $channel stat])} {
    return 0
  }
  set hostname [maskhost *!$hostname]
  regsub -all -- {\002|\003[\d]{0,2}(,[\d]{0,2})?|\006|\007|\017|\026|\037|\n|\t} $arguments {} arguments
  set added(words) [regexp -all -- {\S+} $arguments]
  set added(letters) [regexp -all -- {\S} $arguments]
  if {[string length $smileyregex] >= 1} {
    set added(smilies) [regexp -all -- $smileyregex $arguments]
  } else {
    set added(smilies) 0
  }
  if {(![info exists data($channel,$hostname)])} {
    set data($channel,$hostname) "0 0 0 0 0 NULL"
  }
  regexp -- {^(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $data($channel,$hostname) -> lastseen lines words letters smilies lastnick
  incr lines 1
  incr words $added(words)
  incr letters $added(letters)
  incr smilies $added(smilies)
  set data($channel,$hostname) "[unixtime] $lines $words $letters $smilies $nickname"
}

proc statistics::spew {nickname hostname handle channel arguments} {
  variable data
  if {(![channel get $channel stat])} {
    return 0
  }
  if {([isop $nickname $channel]) && ([string length $arguments] >= 1)} {
    set target [lindex [clean $arguments] 0]
  } else {
    set target $nickname
  }
  if {![onchan $target $channel]} {
    putserv "PRIVMSG $channel :\[Statistics - Unknown user \002$target\002\]"
    return 0
  }
  set targethost [maskhost *![getchanhost $target $channel]]

  if {[info exists data($channel,$targethost)]} {
    regexp -- {^(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $data($channel,$targethost) -> lastseen lines words letters smilies lastnick
    set wpl [round [expr ($words / $lines.)]]
    set spl [round [expr ($smilies / $lines.)]]
    set lpw [round [expr ($letters / $words.)]]
    putserv "PRIVMSG $channel :\[Statistics - \002$target\002 has written \002$lines\002 lines, \002$words\002 ($wpl per line) words and \002$letters\002 ($lpw per word) letters, containing \002$smilies\002 ($spl per line) smilies\]"
  } else {
    putserv "PRIVMSG $channel :\[Statistics - No valuable information available for \002$target\002\]"
  }
}

proc statistics::top {channel number {type ""}} {
  variable data
  set statistics {}
  switch $type {
    {lines} {set index 1}
    {letters} {set index 3}
    {smilies} {set index 4}
    {default} {set index 2 ; set type "words"}
  }
  foreach {user stats} [array get data $channel,*] {
    set stats [clean $stats]
    lappend statistics "[lindex [clean $stats] 5] [lindex $stats $index]"
  }
  set statistics [lrange [lsort -integer -decreasing -index 1 [lsort -unique -index 0 [lsort -integer -increasing -index 1 $statistics]]] [expr $number - 10] [expr $number - 1]]
  if {$statistics == ""} {
    return "\[Top$number $type - No valuable information available for \002$channel\002\]"
  }
  set output "\[Top$number $type -"
  for {set i 0} {$i < [llength $statistics]} {incr i 1} {
    set item [lindex $statistics $i]
    append output "\x20[expr $i+$number-9]: \002[join [lindex [clean $item] 0] { }]\002 ([lindex $item 1])"
  }
  append output "\]"
  return $output
}

proc statistics::toplist {nickname hostname handle channel arguments} {
  global lastbind
  if {(![channel get $channel stat])} {
    return 0
  }
  set arguments [clean $arguments]
  set key [lindex $arguments 0]
  if {![regexp -- {^.*?([0-9]+)$} $lastbind -> number]} {
    return 0
  }
  if {![regexp -nocase -- {^(words|letters|smilies|lines|)$} $key]} {
    putserv "PRIVMSG $channel :\[Statistics - Unknown option: \002$key\002, valid options are \002letters\002, \002lines\002, \002smilies\002 and \002words\002\]"
    return 0
  }
  putserv "PRIVMSG $channel :[top $channel $number [string tolower $key]]"
}

proc statistics::cleanupdb {args} {
  variable killafter
  variable data
  set killed 0
  foreach {item} [array names data] {
    set lastseen [lindex [clean $data($item)] 0]
    set expire [expr 60 * 60 * 24 * $killafter]
    if {[expr [unixtime] - $lastseen] >= $expire} {
      incr killed
      unset data($item)
    }
  }
  return $killed
}

proc statistics::load {} {
  variable data
  variable storage
  regexp -- {^(\S+/)?.*$} $storage -> directory
  if {[string length $directory] >= 1} {
    if {![file isdirectory $directory]} {
      file mkdir $directory
    }
  }
  if {![file exists $storage]} {
    return 0
  }
  if {[array exists data]} {
    array unset data
  }
  set file [open $storage r]
  while {![eof $file]} {
    gets $file line
    if {[regexp -nocase -- {^channel:(\S+)\sid:(\S+)\svalue:(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)$} $line -> channel hostname lastseen lines words letters smilies lastnick]} {
      set data($channel,$hostname) "$lastseen $lines $words $letters $smilies $lastnick"
    }
  }
  close $file
}

proc statistics::save {args} {
  variable data
  variable storage
  set file [open $storage w]
  foreach chan_user [array names data] {
    regexp {^(\S+),(\S+)$} $chan_user -> channel user
    puts $file "channel:$channel id:$user value:$data($chan_user)"
  }
  close $file
}

proc statistics::clean {i} {
  regsub -all -- \\\\ $i \\\\\\\\ i
  regsub -all -- \\\[ $i \\\\\[ i
  regsub -all -- \\\] $i \\\\\] i
  regsub -all -- \\\} $i \\\\\} i
  regsub -all -- \\\{ $i \\\\\{ i
  return $i
}

proc statistics::round {num} {
  if {![string match "*.*" $num]} {
    return $num\.0
  }
  if {![regexp -- {^(\d+?)\.(\d+)$} $num -> primary secondary]} {
    error "syntax error in expression '$num'"
  }
  set secondary [expr round([string index $secondary 0].[string range $secondary 1 end])]
  return [expr {($secondary == 10) ? ($primary+1.0) : "$primary.$secondary"}]
}

statistics::load

putlog "Script loaded: Statistics by perpleXa"
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Can anyone help me by pointing out what I need to look at? Been trying my hardest lol.

I load that script then soon as bot joins room it displays this error:

Code: Select all

[19:41] Tcl error [::statistics::monitor]: can't read "lines": no such variable
[19:41] Tcl error [::statistics::monitor]: can't read "lines": no such variable
[19:41] Tcl error [::statistics::monitor]: can't read "lines": no such variable

Three times in a row, it does keep count and write to file just fine. :oops: :?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

There are numerous procs within that script that try to use the variable "lines" before it has been initialized (given a value). Unfortunately, sorting out those issues might not be trivial, as you'd have to thurroghly study the script and "get inside" the authors mind.

Most likely tho, he is trying to use lines as a global or namespace variable, but failed to access it as such...
NML_375
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Ok I feel like a dummy now lol, after hours of searching I realized there is a new version just not listed here in TCL Archives :oops:
Post Reply