egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

trouble with a nick containing [ ]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Oct 24, 2007 8:03 am    Post subject: trouble with a nick containing [ ] Reply with quote

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
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Oct 24, 2007 10:44 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Oct 24, 2007 11:56 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Oct 24, 2007 12:02 pm    Post subject: Reply with quote

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 Smile
_________________
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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Oct 24, 2007 12:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Oct 24, 2007 3:31 pm    Post subject: Reply with quote

I'll try this tomorrow and give a report here, it might be an add to the FAQ about strings.
_________________
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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber