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 ONLY LETTER (no number)

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

string match ONLY LETTER (no number)

Post by juanamores »

I want to make a comparison that ignores the numbers and compare the text only in letters.

When I look at the access list for a channel, the bot ChanServ (Bot officer of IRCu network) displays a list with 3 items:
a) ordinal number
b) access level
c) nick
Thus:
Command:
/msg chan #mychannel access list
Result:
Access List of #mychannel:
Num Niv Nick
1 300 Michael
2 450 The_warrior
3 100 BLueRiGhT
4 300 mia25
5 300 Anais
How do I retrieve only nicks (words), ignoring the numbers?

What I want the bot retrieve the channel access list and perform a database with nicks that are at the time of executing the command?

The list may be changing as nicks are added or removed from the channel.
For this reason, when you run the command to retrieve the bot list, you read it and only list the nicks you find in it.

REASON: Perform a tcl to invite only nicks which have ChanServ access level on a given channel at the time of executing the invite command.
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

You could use something like..

Code: Select all

proc isnum {string} {
  if {[regexp {^-?\d+(\.\d+)?$} $string]} {
    return 1;
  }
  return 0;
}
Then just ..

Code: Select all

if {![isnum $arg]} {
Maybe throw in a string match too
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Why not go with a more direct approach with string is digit instead of a regexp, cos is a lot faster?

Code: Select all

if {![string is digit $number]} {
 # do whatever
}
Proof:

Code: Select all

proc test1 {} {
    for {set i 0} {$i < 1000} {incr i} {
        string is digit $i
    }
}

proc test2 {} {
    for {set i 0} {$i < 1000} {incr i} {
        regexp {^-?\d+(\.\d+)?$} $i
    }
}
result:

Code: Select all

% time test1
699 microseconds per iteration
% time test2
1162 microseconds per iteration
As for what juanamores is looking for needs a different approach that depends on how he receives the result. Is that a notice? If you have a mIRC client type in status /debug @raw then do that /msg chan #mychannel access list command and copy/paste here the result you see in the @raw window.

I would be inclined to use scan like:

Code: Select all

scan $line {%d%d%s} num niv nick
executed for each line of text the server replies that would create num, niv and nick variables he could later use to do whatever.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

caesar wrote:Why not go with a more direct approach with string is digit instead of a regexp, cos is a lot faster?
I've actually never used or heard of that function, caesar, but now that I have it does seem much more efficient. Thanks for bringing it to my attention.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

caesar wrote:As for what juanamores is looking for needs a different approach that depends on how he receives the result. Is that a notice? If you have a mIRC client type in status /debug @raw then do that /msg chan #mychannel access list command and copy/paste here the result you see in the @raw window.
<- :CHaN!-@- PRIVMSG juanam :Access List of #mychannel:
<- :CHaN!-@- PRIVMSG juanam : Num Niv Nick
<- :CHaN!-@- PRIVMSG juanam : 1 300 KoRn
<- :CHaN!-@- PRIVMSG juanam : 2 450 Guerrero
<- :CHaN!-@- PRIVMSG juanam : 3 300 deseo2
<- :CHaN!-@- PRIVMSG juanam : 4 300 mia123
Is a PRIVMSG not notice.
bind msgm - * acces:list

proc acces:list {nick CHaN!-@- hand text} {
if {[string match -nocase "*Access denied*" $text]} { return
} else {
set fs [open "database" a]
###Here filtering numbers, and retrieve only the 3rd word ([lindex $text 2])are the nicks##
puts $fs [lindex $text 2]
close $fs
}
}
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You don't want to filter numbers, you want to select the 3rd element in that list (especially since nicknames may contain numbers and other characters).

Code: Select all

set nick [lindex [split $text] 2]
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Sir_Fz wrote:You don't want to filter numbers, you want to select the 3rd element in that list (especially since nicknames may contain numbers and other characters).

Code: Select all

set nick [lindex [split $text] 2]
Actually, I had made that way, and then when you invite removes the words that are not nick (with command continue), because this way takes the words "of" and "nick" that are part of the titles.
Access List of #mychannel:
Num Niv Nick
Work, work ... although I saw little technical ...
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

In this case a

Code: Select all

scan $text {%d%d%s} num niv user
will do what you want.

You can even use it like:

Code: Select all

if {[scan $text {%d%d%s} num niv user] != 3} return
to make sure the input matches exactly what is expected.
Once the game is over, the king and the pawn go back in the same box.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Ok.
I did not understand how the data nicks (% s) is taken.
It would be like this?:
bind msgm - * acces:list

proc acces:list {nick CHaN!-@- hand text} {
if {[string match -nocase "*Access denied*" $text]} { return
} else {
if {[scan $text {%d%d%s} num niv user] != 3} return
set fs [open "database" a]
puts $fs "%s"
close $fs
}
}
Anyway, after you create the nicks database, to cross it with a WHILE I have to except the words "off" and "nick" of titles, with the command CONTINUE.
I think there is no other way ...
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The scan will create the $num, $niv and $user variables and use the ones you need.

Code: Select all

bind msgm - * acces:list

proc acces:list {nick uhost hand text} {
if {[string match -nocase "*Access denied*" $text]} return
if {[scan $text {%d%d%s} num niv user] != 3} return
	set fs [open "database" a]
	puts $fs "$user"
	close $fs
}
Once the game is over, the king and the pawn go back in the same box.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Ok, thank you. :D
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
Post Reply