mIRC Home    About    Download    Register    News    Help

Print Thread
#209156 05/02/09 08:03 AM
Joined: Feb 2009
Posts: 1
N
Mostly harmless
OP Offline
Mostly harmless
N
Joined: Feb 2009
Posts: 1
How make it? Thanks

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Use:An ON TEXT event and $read

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Tomao #209160 05/02/09 12:02 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
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" 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) }

Last edited by Horstl; 05/02/09 12:06 PM.
Horstl #209176 05/02/09 09:01 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
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.

Horstl #209179 05/02/09 10:58 PM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
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
Wims #209181 06/02/09 12:15 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
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 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)

Horstl #209183 06/02/09 01:07 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Indeed, sorry, I was confused


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard