This is a pretty simple code that will count all words said on all channels you are on. I do not recommend using this if you are normally on many channels and/or there are alot of big talkers in your channels. In the past few days on my rather small and slow channel it has recorded about 5,000 different words.
Saying !word alone will show the total number of distinct words said on that channel and saying !word (word here) will show how many times that specific word has been said on that channel.
I'm not extremely experienced in scripting for mirc so any constructive criticism is welcome.
EDIT: I changed this script to run off hash tables instead of .ini files, this along with my recently submitted Character Counter script are my first real attempts at using hash tables, so any advice would be appreciated.
EDIT: I added a new search function. To use it type !word -s .
This supports both wildcard and regex searches. To make a regex search just ensure that the search string begins with the / character.
on *:TEXT:!word*:#: {
out -r $qt($1-) triggered in $chan by $nick
if (!$2) { .msg $chan Total number of distinct words said on $+ $chan $+ is: $+ $comma($iif(!$hget(WordCount.Totals,$chan), 0, $hget(WordCount.Totals,$chan))) $+ $+ . }
elseif ($2 == -s) {
var %x = 1, %searchtype = $iif($left($3,1) == $chr(47),r,w), %matches
while ($hfind($+(WordCount.,$chan),$3,%x,%searchtype)) {
inc %matches $hget($+(WordCount.,$chan),$v1)
inc %x
}
.msg $chan There were $+ $comma($iif(%matches,%matches,0)) $+ results for the $iif(%searchtype == r,regex,wildcard) search for $+ $3 $+ on $+ $chan $+ $+ .
}
elseif ($hget($+(WordCount.,$chan),$2)) { .msg $chan The word $+ $2 $+ has been said $+ $hget($+(WordCount.,$chan),$2) $+ $iif($hget($+(WordCount.,$chan),$2) == 1, time, times) on $+ $chan $+ $+ . }
else .msg $chan The word $+ $2 $+ has not been recorded yet for $+ $chan $+ $+ .
}
on *:TEXT:*:#: {
var %x = 1
while ($gettok($1-,%x,32)) {
var %y = $v1
if ($hget($+(WordCount.,$chan),%y)) hinc -m $+(WordCount.,$chan) %y
else {
hadd -m $+(WordCount.,$chan) %y 1
hinc -m WordCount.Totals $chan
}
inc %x
}
}
on *:KICK:#: if ($hget($+(WordCount.,$chan))) && ($knick == $me) { hsave -o $+(WordCount.,$chan) $+(WordCount.,$chan,.dat) | hfree $+(WordCount.,$chan) }
on *:PART:#: if ($hget($+(WordCount.,$chan))) && ($nick == $me) { hsave -o $+(WordCount.,$chan) $+(WordCount.,$chan,.dat) | hfree $+(WordCount.,$chan) }
on *:START: {
var %x = 1
while (%x <= $chan(0)) {
if ( !$hget($+(WordCount.,$chan)) ) hmake $+(WordCount.,$chan) 100
if ( $isfile($+(Wordcount.,$chan,.dat)) ) hload $+(WordCount.,$chan) $+(Wordcount.,$chan,.dat)
inc %x
}
if (!$hget(WordCount.Totals)) hmake WordCount.Totals 100
if ($isfile(WordCount.Totals.dat)) hload WordCount.Totals WordCount.Totals.dat
}
on *:JOIN:#:{
if ($nick == $me) {
if ( !$hget($+(WordCount.,$chan)) ) hmake $+(WordCount.,$chan) 100
if ( $isfile($+(Wordcount.,$chan,.dat)) ) hload $+(WordCount.,$chan) $+(Wordcount.,$chan,.dat)
}
}
on *:EXIT:{
var %x = 1
while (%x <= $chan(0)) {
if ( $hget($+(WordCount.,$chan(%x))) ) hsave -o $+(WordCount.,$chan(%x)) $+(WordCount.,$chan(%x),.dat)
inc %x
}
if ($hget(WordCount.Totals)) hsave -o WordCount.Totals WordCount.Totals.dat
}
on *:DISCONNECT:{
var %x = 1
while (%x <= $chan(0)) {
if ( $hget($+(WordCount.,$chan(%x))) ) hsave -o $+(WordCount.,$chan(%x)) $+(WordCount.,$chan(%x),.dat)
inc %x
}
if ($hget(WordCount.Totals)) hsave -o WordCount.Totals WordCount.Totals.dat
}