I'd suggest something along these lines;
Iterate through each badword-pattern, and get a list of matching words from the spoken text.
Since you'd like to use wildcards in your exempts-list, we'll have to iterate through this list for each match, and see if it should be exempted. If it should be exempted, move on to the next match; else, ban the user and be done with it.
Further, instead of manually adding the ban, kicking the user, and setting up a timer to finally remove it, why not just use the newchanban command with a custom expire-time?
The above converted to code:
Code: Select all
set advban(time) "30"
set advban(chans) [list "#chan"]
set advban(words) [list "*http*//*" "*http:*" "*www.*" "*.htm*" "*ftp*//*" "*www.*.co*" "*/server*.*.*"]
set advban(exempts) [list]
bind pubm - "*" advban
proc advban {nick host hand chan txt} {
global advban
set advban(chans) [string tolower $advban(chans)]
set chan [string tolower $chan]
set items [split [string tolower $txt]]
if {[validuser $hand] || [isop $nick $chan] || ([llength $advban(chans)] > 0 && [lsearch -exact $advban(chans) $chan] == -1)} {
return 0
}
foreach pattern $advban(words) {
foreach match [lsearch -all -inline $items [string tolower $pattern]] {
set exempt 0
foreach exception $advban(exempts) {
if {[string match -nocase $exception $match]} {
set exempt 1
break
}
}
if {$exempt} {
continue
} else {
newchanban $chan "*!*@[lindex [split $host "@"] 1]" "advban.tcl" "Spam match from ($match) is not allowed here" $advban(time)
return 1
}
}
}
}
Or, if we skip the wildcard matching of exempts:
Code: Select all
set advban(time) "30"
set advban(chans) [list "#chan"]
set advban(words) [list "*http*//*" "*http:*" "*www.*" "*.htm*" "*ftp*//*" "*www.*.co*" "*/server*.*.*"]
set advban(exempts) [list "*example.com*"]
bind pubm - "*" advban
proc advban {nick host hand chan txt} {
global advban
set advban(chans) [string tolower $advban(chans)]
set chan [string tolower $chan]
set items [split [string tolower $txt]]
if {[validuser $hand] || [isop $nick $chan] || ([llength $advban(chans)] > 0 && [lsearch -exact $advban(chans) $chan] == -1)} {
return 0
}
foreach pattern $advban(words) {
foreach match [lsearch -all -inline $items $pattern] {
if {[lsearch -exact $advban(exempts) $match]} {
continue
} else {
newchanban $chan "*!*@[lindex [split $host "@"] 1]" "advban.tcl" "Spam match from ($match) is not allowed here" $advban(time)
return 1
}
}
}
}