| View previous topic :: View next topic |
| Author |
Message |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Oct 24, 2007 8:03 am Post subject: trouble with a nick containing [ ] |
|
|
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: | 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: | | {[nick1]} - {[nick1]} {[nick2]} => -1 |
I can't understand why the result is not 0... it works well with others users... _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Oct 24, 2007 10:44 am Post subject: |
|
|
I've found a method I used previously: a filtering procedure:
| Code: | 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... _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Oct 24, 2007 11:56 am Post subject: |
|
|
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: | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Oct 24, 2007 12:02 pm Post subject: |
|
|
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  _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Oct 24, 2007 12:09 pm Post subject: |
|
|
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: | ...
set exclude $::excludednicks
lappend exclude $::botnick
... |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
|