mIRC Homepage
Posted By: NightMan31 Bad Word Filter - 05/02/09 08:03 AM
How make it? Thanks
Posted By: RusselB Re: Bad Word Filter - 05/02/09 08:11 AM
Use:An ON TEXT event and $read
Posted By: Tomao Re: Bad Word Filter - 05/02/09 09:30 AM
Here is the basic using regex to get your started:
Code:
on *:TEXT:*:#: {
  var %b = /(badword1|badword2|badword3|badword4|badword5|badword6)/Si
  if ($regex($1-,%b)) { msg $chan $nick $+ , please refrain yourself from using profanity! }
}

change the badword1, badword2, etc...to the ones you want to filter. You can add more bad words in the same fashion, with a pipe between them. This may not be the best method, but should be enough to filter some words you want to look after.
Posted By: Horstl Re: Bad Word Filter - 05/02/09 12:02 PM
Hum, I question the usage of regular expressions if there's no particular advantage in it. As pointed out to you before, with $regex you're not matching plain text/words but expressions - I doubt the OP is aware of this (At least escape "literal" things with \Qtexthere\E ?).
In the case of your code: $count is cleaner and faster than a regex string, and as well more "secure" smile

Some of the many matching methods that cross my mind:

$count (simple wildmatch):
Code:
if ($count(TEXT,badword1,badword2,badwordN)) { echo -a TEXT wildmatches a badword }

$istok (word match) ,e.g.
Code:
var %badwords = badword1 badword2 badwordN, %n = 1
while ($gettok(%badwords,%n,32)) {
  if ($istok(TEXT,$v1,32)) { echo -a TEXT matches badword: $gettok(%badwords,%n,32) }
  inc %n
}

$matchtok (wildstring match):
Code:
var %badstrings = badstring1 badstring2 badstringN , %n = 1
while ($gettok(%badstrings,%n,32)) {
  if ($matchtok(TEXT,$v1,1,32)) { echo -a word $v1 in TEXT wildmatches badword definition: $gettok(%badstrings,%n,32) }
  inc %n
}

$wildtok (mixed definitions):
Code:
var %bad = badword1 *badstring* anotherbadword anotherb*string, %n = 1
while ($gettok(%bad,%n,32)) {
  if ($wildtok(TEXT,$v1,1,32)) { echo -a word $v1 in TEXT matches badword definition: $gettok(%bad,%n,32)  }
  inc %n
}

A hash-table-based wildmatch where you could assign an explanation or whatever additional data you like
Code:
hadd -m bad *badstring1* reason1
hadd -m bad *badstring2* reason2
hadd -m bad *badstringN* reasonN
if ($hfind(bad,TEXT,1,W)) { echo -a TEXT matches $v1 - reason: $hget(bad,$v1) }
Posted By: Tomao Re: Bad Word Filter - 05/02/09 09:01 PM
Thanks much Horstl for showing me various usage of word match examples in scripting. Yes, I agree with you there's no distinctive advantage of using regex if it's not needed, as metioned to me before.
Posted By: Wims Re: Bad Word Filter - 05/02/09 10:58 PM
The $matchtok method is not useful if you use a space to separate the string, it's the same as $istok then...
Posted By: Horstl Re: Bad Word Filter - 06/02/09 12:15 AM
Nope, $matchtok(tokens ("TEXT"),string ("badword"),N,C) returns the Nth C-separated token (if C is 32: "word") that contains "badword".
The main advantage of a $matchtok-loop to $count is that - in terms of a badword script - you can easily put the token matched ("word" of TEXT) and the matching string ("badword") in a kick reason or the like smile

I think I'd go for either:
- $wildtok (one may use both tokens with and without wildcards - applied e.g. on $remove($strip(TEXT),-punctuacion marks etc-)
or (if it shall be more versatile):
- a hash table + $hfind(R) + custom routines (for example to "translate" "plaintext" badwords to expressions that match on word boundaries only)
Posted By: Wims Re: Bad Word Filter - 06/02/09 01:07 AM
Indeed, sorry, I was confused
© mIRC Discussion Forums