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.

string match problem

Old posts that have not been replied to for several years.
Locked
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

string match problem

Post by Solarin »

Help with error:
Tcl error [join:nospam]: invalid command name "a-z"

The code is as follows:

Code: Select all

bind join - * join:nospam
proc join:nospam {nick host hand chan} { 
  set ident [string range $host [string first ! $host] [string first @ $host]]
  if {[string match [a-z] [string index $ident 0] == 1] && [string match [0-9] [string index $ident 1] == 1] && [string match [a-z] [string index $ident 2] == 1] && [string match [0-9] [string index $ident 3] == 1] && [string match [a-z] [string index $ident 4] == 1]} {
    putserv "KICK $chan $nick :Spamming ident."
    newban [string trimleft [maskhost [getchanhost $nick $chan]] ~] NoSpam "Spamming ident." $spambantime
  }
}
Basically, I want to kick and ban any user with the alpha-number-alpha-number-alpha type ident (i.e. o1j2e).
This is a widely used type of spamming ident on Austnet and the ident always follows such a pattern. It would be nice to get this working.

Your help is appreciated.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

escape the brackets (\[a-z\])

btw: you can do [string match \[a-z\]\[0-9\]\[a-z\]\[0-9\]\[a-z\] $ident] if the number/order of chars is always the same.
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

I escaped the brackets and now I receive the following error:
Tcl error [join:nospam]: wrong # args: should be "string match ?-nocase? pattern string"

Code: Select all

if {[string match \[a-z\] [string index $ident 0] == 1] && [string match \[0-9\] [string index $ident 1] == 1] && [string match \[a-z\] [string index $ident 2] == 1] && [string match \[0-9\] [string index $ident 3] == 1] && [string match \[a-z\] [string index $ident 4] == 1]} {
?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Well you have this bit:

[string match \[a-z\] [string index $ident 0] == 1]

Now, the way you have that written, these are the arguments:

match
\[a-z\]
[string index $ident 0]
==
1

Tcl is treating "==" as a string argument to the command, because it's inside the [ ] with the rest of the parameters. Probably you meant for the ] after the 1 to actually be before the ==.

Do yourself a favor and split that horrible mess into a couple different lines heh. Also take a look at what User said.
S
Solarin
Voice
Posts: 29
Joined: Wed Apr 09, 2003 1:50 pm
Location: Sydney Australia
Contact:

Post by Solarin »

Well I took user's suggestion at the bottom of his post. That is much better now. I don't receive any more errors.

Thanks for the post stdragon. I did not think anything of the == 1 being taken as arguments. I'll keep that in mind next time.
Locked