mIRC Home    About    Download    Register    News    Help

Print Thread
#200013 26/05/08 01:17 AM
Joined: Jan 2008
Posts: 6
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Jan 2008
Posts: 6
I am trying to make a kick that reads from a text file. It is reading the file ok, and it is kicking ok, but only if the word is used by itself, i.e. if there is anything before or after the trigger word it won't kick. I assume there is something wrong with the line;

if ($read(swearwords.txt,w,* $+ $1- $+ *) iswm $1-) {

but I can't figure it out.

Code:
on *:TEXT:*:#:{
  if ($nick isop $chan) || ($me == $nick) { halt }
  if ($read(swearwords.txt,w,* $+ $1- $+ *) iswm $1-) {
    if ($chan == $chr(37) $+ $chr(35) $+ Channel\bName) {
      kick $chan $nick That word is not tolerated in here!
    }
    else { halt }
  }
}


TIA for any help

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
$read(file,w,*text*) already performs a wildcard search. You're double evaluating with the iswm comparison...
Quote:
//echo $read(help.txt, w, *help*)

Scans the file help.txt for a line matching the wildcard text *help*. The r switch implies a regex match.

Another side note: on text events do not trigger on your own text inputs (this is the on input event), thus you dont need the $me == $nick check.
Instead, I'd use:
if ($nick !isop $chan) { ...rest of code as nick is no operator... }
or if ($nick isreg $chan) { ...rest of code as nick is a regular user... }
In addition, you don't have to use 'halt' in the else part, in fact this prevents the execution of other on text events (other scripts). If you have no 'else' to do - leave it out (it's not mandatory) smile

Now the main problem:
You apparently want to compare badwords to the users whole line: Badword wildcard-matching line (*badword* iswm $1-), but your read condition is checking for line wildcard-matching badword: $read(file,w,*text*) works like if (*text* iswm badword). That's why it only triggers if the word is used by itself.

To get arround this:
Either loop all badwords in the file and compare it to the line ($read(file,linenumber) iswm $1-), or (much better):
Use a hash table and $hfind:
$hfind(YourHashTableWithTheBadwords,Text (that is: $1-), 1, W)
example:

Code:
hadd -m test *damn*
echo -a $hfind(test,This is a damn example!,1,W)
if ($hfind(test,Goddamn - hfind is fast...,1,W)) { echo -a text contains badword: $v1 }


(Check the mIRC help file on how to create/load/save hash tables)

Hope it helps,
Regards

Joined: Jan 2008
Posts: 6
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Jan 2008
Posts: 6
Thanks, that helped heaps, my remote file now looks like this;

Code:
on *:TEXT:*:#:{
  if ($nick isop $chan) { halt }
  if ($hfind(badwords,$1- ,1,W)) {
    if ($chan == $chr(37) $+ $chr(35) $+ Valhalla) {
      kick $chan $nick That word is not tolerated in here
    }
  }
}


on *:ACTION:*:#:{
  if ($nick isop $chan) { halt }
  if ($hfind(badwords,$1- ,1,W)) {
    if ($chan == $chr(37) $+ $chr(35) $+ Valhalla) {
      kick $chan $nick That word is not tolerated in here
    }
  }
}


on *:START: {
  /hmake badwords 10
  if ($isFile(badwords.hsh)) {
    /hload badwords badwords.hsh
  }
}

on *:EXIT: {
  /hsave -o badwords badwords.hsh
  /hfree badwords
} 


I had to find a quick tut on hash tables, so I hope this one explained it all properly. It all seems to work anyway.

Thanks again

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
you can also do it as such:

Code:
on *:TEXT:*:#: { var %b = $lines(swearwords.txt) | while (%b) { if ($nick !isop $chan) && ($read(swearwords.txt,%b) isin $1-) { kick # $nick That word is not tolerated in here! } | return } | dec %b }


Add the bad words vertically in your text file. It will loop through the file containing the bad words you put in there to match via people's sentences.

Last edited by Tomao; 26/05/08 04:33 AM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I would suggest using adding a ON DISCONNECT event that saves the hash table to a file, just in case you get disconnected from the network, but mIRC doesn't exit (eg: connection reset by peer)

Also I suggest making these changes
Code:
on *:TEXT:*:$+(%,#,Valhalla):{
  badword $nick $chan $1-
}
on *:ACTION:*:$+(%,#,Valhalla):{
  badword $nick $chan $1-
}
alias -l badword {
  if $1 !isop $2 {
    if $hfind(badwords,$3-,1,W) {
      kick $2 $1 That word is not tolerated in here
    }
  }
}
on *:START: {
  if !$hget(badwords) { hmake badwords 10 }
  if ($isFile(badwords.hsh)) {  hload badwords badwords.hsh  }
}

on *:EXIT: {
  hsave badwords badwords.hsh
} 
on *:Disconnect: {
  hsave badwords badwords.hsh
} 

Please note that I'm not on any networks that support the %# channel name format, so I'm unable to test these modifications.

The hsave command doesn't have a -o switch, as it overwrites by default. If you didn't want it to over-write, the command does support a -a switch, which appends.

Joined: Jan 2008
Posts: 6
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Jan 2008
Posts: 6
Originally Posted By: RusselB

I would suggest using adding a ON DISCONNECT event that saves the hash table to a file, just in case you get disconnected from the network, but mIRC doesn't exit (eg: connection reset by peer)


Good idea, thanks

Originally Posted By: RusselB

Please note that I'm not on any networks that support the %# channel name format, so I'm unable to test these modifications.


Tested and works perfectly, thanks again

Originally Posted By: RusselB

The hsave command doesn't have a -o switch, as it overwrites by default. If you didn't want it to over-write, the command does support a -a switch, which appends.


Yeah I haven't ever touched hash tables before this, I am going to have to spend some time getting to know how they work obviously.

Thanks for the help.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Why not use
Code:
if (Valhalla isin #) { ... }
?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Basically your code would match any channel that had the word Valhalla in the name, as mine only matches the one specific channel.


Link Copied to Clipboard