Code: Select all
bind pub - test proc:banlist
proc proc:banlist {nick uhost hand chan text} {
set text [split $text];#always split input for safety :P
set mybans [banlist $chan];set matches ""
if {$mybans != ""} {
foreach ban $mybans {
if {[lsearch -start -6 $ban $text] != -1} {
lappend matches "[lindex $ban 0] [lindex $ban 5]"
}
}
if {$matches != ""} {
set i 0
puthelp "PRIVMSG $chan :Matching bans found: [llength $matches]"
foreach match $matches {
incr i
puthelp "PRIVMSG $chan :$i: [lindex $match 0] banned by [lindex $match 1]"
}
} else {
puthelp "PRIVMSG $chan :No bans matching [join $text] found on channel $chan."
}
} else {
puthelp "PRIVMSG $chan :No bans for channel $chan."
}
}
putlog "test.tcl loaded"
#-I_Really_hate-Word-Wrap!-######################################################################################
Indeed It worked because your search pattern had the same case as your bans and the masks/handles did not contain any brackets and braces.rosc2112 wrote:I tested this, it worked for me. YMMV
I made the script the way it way requested. Mav knows enough to modify it if he wants it case-insensitive. And yeah I know it's not tcl-special char safe, but again, that's an exercise for Maverickuser wrote:1) You do case sensitive GLOB matching with IRC BAN as a pattern. (brackets have a special meaning in glob matching - case doesn't matter on irc)rosc2112 wrote:I tested this, it worked for me. YMMV
2) lindex used on strings is bad (and I know you know this )
Nope. They would never cause an error because the variable names contain no special characters...rosc2112 wrote:Hmm, I'm guessing you meant in the foreach vars, I should've used
To fix it, you could just lappend them both as separate elements and dorosc2112 wrote:Code: Select all
# the elements you append to the matches list are strings... lappend matches "[lindex $ban 0] [lindex $ban 5]" # ...but later you treat them like lists... foreach match $matches { ... [lindex $match 0] ... [lindex $match 1]" }
Code: Select all
foreach {ban by} {...}
Code: Select all
lappend matches [list [lindex $ban 0] [lindex $ban 5]]