This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

badwords tcl with regexp

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
simo
Revered One
Posts: 1106
Joined: Sun Mar 22, 2015 2:41 pm

badwords tcl with regexp

Post by simo »

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.

Code: Select all


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.

hope someone might have a solution.

apreciated,
User avatar
CrazyCat
Revered One
Posts: 1296
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: badwords tcl with regexp

Post by CrazyCat »

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
Small addition: use -all:
% regexp -all -nocase $bword $textedit
2
s
simo
Revered One
Posts: 1106
Joined: Sun Mar 22, 2015 2:41 pm

Re: badwords tcl with regexp

Post by simo »

thanks CC
Post Reply