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.

Special characters in string match

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Special characters in string match

Post by Dedan »

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.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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: Select all

set match [string map {[ \\[ ] \\]} $match]
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

what are you talking about?

Code: Select all


 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.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Fix your attitude so you would understand what I'm suggesting.
set banmask "*[M]*!*@*"
This obviously causes an error since it will try to evaluate M as a Tcl-command.
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: Select all

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
  }
 }
}
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

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]
Last edited by Dedan on Sat Apr 28, 2007 10:27 pm, edited 1 time in total.
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

{[ \\[ ] \\]} ??????
you mean {[ \\[ \\] ]} ????
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I already showed you how it's done, let me paste it again more explained:

Code: Select all

# 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
  }
 }
}
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

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

Code: Select all

set banmask [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\}} $banmask]
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Post Reply