mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2005
Posts: 54
B
Bundy Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Dec 2005
Posts: 54
I want to create a script that counts how many times a specific word has been used.
One can search for any word - just add it at the back of !wcount-lol, !wcount-rofl, !wcount-sleep etc...
Am I correct in saying that I only need code that search through a log and count the words, or do you suggest using hash tables?

regards,

b

Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
I'd probably filter a log, just my preference though.

btk


billythekid
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The problem with log filtering is having it use a "lifetime" word count. You'd have to filter a lot of log files. I'm not sure that's what he wants. I also don't think you can use filter to get the number of times on a single line without looping through all of the lines to count the number of times after filtering, which would be time consuming.

I do think a hash table is the best solution.

Code:
on *:start: {
  hmake WordList 500
  if ($isfile(wordlist.hsh)) { hload WordList Wordlist.hsh }
}

on *:text:*:#: {
  ; Make sure there is a hash table and that all data is loaded.
  if (!$hget(WordList)) {
    hmake WordList 500
    if ($isfile(wordlist.hsh)) { hload WordList Wordlist.hsh }
  }
  ; Display word usage
  if ($left($1,8) == !wcount-) {
    var %word = $gettok($1,2,45)
    var %times = $iif($hget(WordList,%word),$v1,0)
    msg $chan %word was used %times $iif(%times == 1,time.,times.)
    return
  }
  ; Remove all punctuation and characters that are likely to be touching the words so something like "this." is treated as "this" .  Add any others you think are needed.
  var %cleaned.text = $replace($1-,.,$chr(32),?,$chr(32),!,$chr(32),-,$chr(32),_,$chr(32),$chr(42),$chr(32),",$chr(32),*,$chr(32))
  var %cnt = 1
  var %words = $gettok(%cleaned.text,0,32)
  while (%cnt <= %words) {
    hinc WordList $gettok(%cleaned.text,%cnt,32)
    inc %cnt
  }
  hsave WordList Wordlist.hsh
}


If you want this to also work when the person/bot that has the script types something, then copy/paste everything in the on TEXT into an on INPUT. If you need help with that, let me know.

Also, you may decide that you don't want words counted if they are used as part of a command/trigger in the channel. For example, you might now want !ping to be counted if that command is allowed in your channel. If you want to prevent certain triggers (or all lines starting with ! or similar), let me know and I'll adjust it for you. !wcount will not count as a word that was used already.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2005
Posts: 54
B
Bundy Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Dec 2005
Posts: 54
Thank you very much Riamus2, the code is going into a bot - on text will be 100%.
I'll use it and let you know how it works - I'm sure it'll be fine.

You guys are always gr8 with the help, I appreciate it!

Regards,

b


Link Copied to Clipboard