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.
Help for those learning Tcl or writing their own scripts.
CrazyCat
Revered One
Posts: 1334 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Oct 24, 2007 8:03 am
I know this is a recurent trouble but I can't find the solution, I've tried all my ideas.
I'm trying to exlude some users in a procedure (some bots) and their nick is
[nick]
So, I do:
Code: Select all
proc test {nick uhost handle chan args} {
set exclbot "\[nick1\] \[nick2\]"
set exclude [split "$::botnick $exclbot"]
set users [chanlist $chan]
foreach excl [split $exclude] {
set ind [lsearch $users $excl]
putlog "$excl - $users => $ind"
set users [lreplace $users $ind $ind]
}
}
When the tcl found [nick1] or [nick2], the lsearch returns -1 and I've in the log:
Code: Select all
{[nick1]} - {[nick1]} {[nick2]} => -1
I can't understand why the result is not 0... it works well with others users...
CrazyCat
Revered One
Posts: 1334 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Oct 24, 2007 10:44 am
I've found a method I used previously: a filtering procedure:
Code: Select all
proc filt {data} {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}
I don't really like it, I'm sure a real solution exists...
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Wed Oct 24, 2007 11:56 am
Keep in mind that lsearch uses glob-style patterns unless you specify otherwize.
Have you considdered using proper lists? Right now, you're splitting lists, which can damage contents.
Also, you really should check for the condition where the excluded nick was not found (-1 returned)...
Code: Select all
proc test {nick uhost handle chan arg} {
set exclude [list $::botnick {[nick1]} {[nick2]}]
set users [chanlist $chan]
foreach excl $exclude {
if {[set ind [lsearch -exact $users $excl]] >= 0} {
putlog "$excl - $users => $ind"
set users [lreplace $users $ind $ind]
}
}
}
NML_375
CrazyCat
Revered One
Posts: 1334 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Oct 24, 2007 12:02 pm
The trouble I've is that the list of excluded nicks is a configuration setting of the tcl, I can't ask users to use something different than the name the see on IRC.
Bu I'll try the lsearch with options like -exact and -ascii, peharps this is the solution
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Wed Oct 24, 2007 12:09 pm
The glob-style patternmatching is the cause of your issues, so adding -exact will solve that issue.
Yet, you should'nt use split over and over again...
Something like this then, perhaps?
Code: Select all
...
set exclude $::excludednicks
lappend exclude $::botnick
...
NML_375
CrazyCat
Revered One
Posts: 1334 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Oct 24, 2007 3:31 pm
I'll try this tomorrow and give a report here, it might be an add to the FAQ about strings.