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 

Special characters in string match

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


Joined: 09 Jul 2003
Posts: 260
Location: Memphis

PostPosted: Sat Apr 28, 2007 5:11 pm    Post subject: Special characters in string match Reply with quote

never the less user i am in the final stages
of a very nice blacklist script for large channels

i would like to be able to ban nicks with
special chars in them but it seems impossible.

i am currently using "string match" for compare


[01:50] <botowner> .tcl string match *[M]*!*@* *!*@*
[01:50] <bot> Tcl error: invalid command name "M"

[01:50] <botowner> .tcl string match *\[M\]*!*@* *M*!*@*
[01:50] <bot> Tcl: 1


upon blacklisting *[M]*!*@* the script banned
everyone that had a M in their nick

i would like to ban nicks with [,],-,_.\,{, and } in them

any suggestions?

Edit: I've moved this post from the FAQ to this forum due to its irrelevance. (Sir_Fz)
_________________
I once was an intelligent young man, now i am old and i can not remember who i was.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 28, 2007 8:44 pm    Post subject: Reply with quote

You won't face problems with {, }, -, _, or \ using [string match] (as long as you properly use string and list commands). You only need to skip [ and ], applying the following string map on the match should do it:
Code:
set match [string map {[ \\[ ] \\]} $match]

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Dedan
Master


Joined: 09 Jul 2003
Posts: 260
Location: Memphis

PostPosted: Sat Apr 28, 2007 9:15 pm    Post subject: Reply with quote

what are you talking about?

Code:


 set banmask "*[M]*!*@*"
 set blacklist($banmask)

bind join -|- * BLK:J
proc BLK:J {N uhost H C} {

  set U "$N![getchanhost $N]"
  foreach E [array names blacklist] {
    if {[string match -nocase $E $U]} {



and you are suggesting what?
_________________
I once was an intelligent young man, now i am old and i can not remember who i was.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 28, 2007 9:34 pm    Post subject: Reply with quote

Fix your attitude so you would understand what I'm suggesting.
Quote:
set banmask "*[M]*!*@*"

This obviously causes an error since it will try to evaluate M as a Tcl-command.
Quote:
set blacklist($banmask)

This also causes an error since it has no parameter (proper syntax is: set var-name value)...

And I don't see why you're storing the masks in an array where you can simply use a list.
Code:
set banmasks {
 *[M]*!*@*
 bla!*@*
 lame!*[foo]*@bar.*
}

bind join -|- * BLK:J
proc BLK:J {nick uhost hand chan} {
 global banmasks
 set U $nick!$uhost
 foreach banmask $banmasks {
  # here's where my suggestion helps
  set banmask [string map {[ \\[ ] \\]} $banmask]
  if {[string match -nocase $banmask $U]} {
   # You've found a match!
   break
  }
 }
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Dedan
Master


Joined: 09 Jul 2003
Posts: 260
Location: Memphis

PostPosted: Sat Apr 28, 2007 9:42 pm    Post subject: Reply with quote

1) the original post refected an aspect of the orginal topic user started
2) the orginal post was directed to user
3) it is set in an array because it does have value, 5+ values
4) are you suggesting i should use:
set banmask [string map {[ \\[ ] \\]} $banmask]

set banmask [string map {[ \\{ } \\]} $banmask]

set banmask [string map {[ \\- _ \\]} $banmask]
_________________
I once was an intelligent young man, now i am old and i can not remember who i was.


Last edited by Dedan on Sat Apr 28, 2007 10:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 28, 2007 9:50 pm    Post subject: Reply with quote

So your issue was with the move? I simply moved it because user's topic is about ban masks and not [string match]. If you don't want anyone but user to answer you then don't do a public post in the forum. I didn't get your array argument though, I still believe using a list is a better choice.

I already said that only [ and ] have special meaning in [string match] so all you need is to apply that string map to the match as I've indicated in the sample code I wrote.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Dedan
Master


Joined: 09 Jul 2003
Posts: 260
Location: Memphis

PostPosted: Sat Apr 28, 2007 10:04 pm    Post subject: Reply with quote

{[ \\[ ] \\]} ??????
you mean {[ \\[ \\] ]} ????
_________________
I once was an intelligent young man, now i am old and i can not remember who i was.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Apr 29, 2007 12:03 pm    Post subject: Reply with quote

I already showed you how it's done, let me paste it again more explained:
Code:
# List of masks which you want to be banned
set banmasks {
 *[M]*!*@*
 bla!*@*
 lame!*[foo]*@bar.*
 nickwith\{!*@*
 nick-with_\}!*@*
 nickwith\\!*@*
}

bind join -|- * BLK:J

proc BLK:J {nick uhost hand chan} {
 global banmasks
 # U is nick!user@host
 set U $nick!$uhost
 foreach banmask $banmasks {
  # here you skip the brackets [ and ]
  set banmask [string map {[ \\[ ] \\]} $banmask]
  # this way *[M]* will match only *[M]* and not *M*
  if {[string match -nocase $banmask $U]} {
   # You've found a match!
   break
  }
 }
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Tue May 08, 2007 9:23 pm    Post subject: Reply with quote

All special characters to replace which are used in nicks and masks:

Code:

set banmask [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $banmask]

_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
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