|
Joined: Feb 2009
Posts: 1
Mostly harmless
|
OP
Mostly harmless
Joined: Feb 2009
Posts: 1 |
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Use:An ON TEXT event and $read
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Here is the basic using regex to get your started: 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.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
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" Some of the many matching methods that cross my mind: $count (simple wildmatch): if ($count(TEXT,badword1,badword2,badwordN)) { echo -a TEXT wildmatches a badword } $istok (word match) ,e.g. 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): 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): 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 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) }
Last edited by Horstl; 05/02/09 12:06 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
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.
|
|
|
|
Joined: Jul 2006
Posts: 4,149
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,149 |
The $matchtok method is not useful if you use a space to separate the string, it's the same as $istok then...
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
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 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)
|
|
|
|
Joined: Jul 2006
Posts: 4,149
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,149 |
Indeed, sorry, I was confused
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|