greetz, i was trying out this small badwords tcl with regexp the idea is to have it strip colorscodes bold and such and strip from duplicate characters and non alphabetical/digit and have comon chars replaces wich are often used to evade badwords like 0 for o 3 for e and such and after all that to have it match against the text but for some reason it seems to trigger regardless of what text is used.
set badwords {
"*censored*"
"somebadword"
}
bind pubm - * text:badwords
proc text:badwords {nick uhost hand chan text} {
global badwords
set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
regsub -all -- {(.)\1+} $text {\1} text
regsub -all -nocase {[^a-z0-9]+} $text "" textedit
set textedit [string map {o [0o] u [uv] i [i1] e [3e] a [a4]} $text]
set banmask "*!*@[lindex [split $uhost @] 1]"
foreach bword $badwords {
if {[regexp -nocase {[$bword]} $textedit]} {
pushmode $chan +b m:$banmask
}
}
}
not sure where i went wrong i suspect the line : if {[regexp -nocase {[$bword]} $textedit]} {
but im not sure what the proper method would be to use that line in this case since we test text matched against like [0o] [3e] i thought its proper to use regexp for it unless there is a better way.
Regexp synopsis: regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?
You use bword as exp (must be a regular expression) and textedit as string (must not be a regular expression).
you'd better transform bword rather than textedit:
% set bword "test"
test
% set textedit "I'am a test0r gonna testing"
I'am a test0r gonna testing
# What you do
% set textedit [string map {o [0o] u [uv] i [i1] e [3e] a [a4]} $textedit]
I'[a4]m [a4] t[3e]st0r g[0o]nn[a4] t[3e]st[i1]ng
% regexp -nocase $bword $textedit
0
# bad :)
# What I do
% set textedit "I'am a test0r gonna testing"
I'am a test0r gonna testing
% set bword [string map {o [0o] u [uv] i [i1] e [3e] a [a4]} $bword]
t[3e]st
% regexp -nocase $bword $textedit
1
#good