Word Count

By xDaeMoN on Jun 12, 2007

Like the title said, it count words when added to the database.

Just thought I post this as a snippet. It's a minor update to the code I posted on this thread.

Usage:

!addword
!countword
!delword

;================================================
;  Word Count
;  Version 1.1
;  Written by: xDaeMoN
;  Email: xdaemon@xdaemon.us
;  
;================================================

On *:START: {
  if ( !$hget($wc.table) ) hmake $wc.table 100
  if ( $isfile($wc.data) ) hload $wc.table $wc.data
}

On *:EXIT: if ( $hget($wc.table) ) hsave -o $wc.table $wc.data
On *:DISCONNECT:  if ( $hget($wc.table) ) hsave -o $wc.table $wc.data

alias wc.table return wordcount
alias wc.data return $qt($scriptdirwordcount.dat)
alias wc.count {
  tokenize 32 $1-
  if ( $hfind($wc.table,$1-,1,W) ) {
    var %t = $v1
    if ( $wildtok($1-,%t,0,32) ) hinc -m $wc.table %t $v1
  }
}

On *:TEXT:!*word &:#: {
  if ( $1 == !addword ) {
    if ( !$hget($wc.table,$+(*,$2,*)) ) {
      hadd -m $wc.table $+(*,$2,*)
      msg $chan Added $2 in my database.
    }
    else msg $chan $2 is already in my database.
  }
  elseif ( $1 == !countword ) {
    if ( $hget($wc.table,$+(*,$2,*)) ) msg $chan $2 has been said: $v1 times.
    else msg $chan That word is not in my database.
  }
  elseif ( $1 == !delword ) {
    if ( $hget($wc.table,$+(*,$2,*)) ) {
      hdel $wc.table $+(*,$2,*)
      msg $chan Deleted $2 from my database.
    }
    else msg $chan That word is not in my database.
  }
}

on *:TEXT:*:#: wc.count $strip($1-)
On *:ACTION:*:#: wc.count $strip($1-)

Comments

Sign in to comment.
cptpan   -  Jun 16, 2012

This starts to fail after a while and only some words work.

Why?

 Respond  
zelic   -  Feb 11, 2011

is it possible to mix the counter with a calculator?
Say for example, Ill give command !unit 1000
then all in channel can remove any number by typing !-150
and the bot shows remaining ammount?
Units: 850.

that can work either way, + or - .

 Respond  
xDaeMoN   -  Jul 03, 2007

That\'s good. =)

 Respond  
lordmedo   -  Jul 03, 2007

on mirc 6.21 it works fine, i had mirc 6.12 before. thanks

 Respond  
xDaeMoN   -  Jun 20, 2007

Did you paste it on a new remote file? What version of mIRC is your bot using? I\'ve tested it several times with the latest version & should work from 6.17 because of the $qt, but other than that, I can\'t think of anything that would make it not work for you.

 Respond  
xDaeMoN   -  Jun 18, 2007

@ lordmedo, if you copy/pasted it to your remotes section, that is correct. Other people would have to type the commands. If you are typing the commands, it won\'t work since you have the script.

 Respond  
lordmedo   -  Jun 16, 2007

i dont know how to install this code?
i tried pasting it to remote but no effect...

 Respond  
xDaeMoN   -  Jun 12, 2007

Thanks. Got that corrected now. :)

 Respond  
Noutrious   -  Jun 12, 2007

It\'s nice, but i think, that:

msg $chan Deleted $2 in my database.
Corrected would be
msg $chan Deleted $2 from my database.

Greets! :)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.