| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Mon Oct 24, 2016 9:34 pm Post subject: string match ONLY LETTER (no number) |
|
|
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: | Quote: | | /msg chan #mychannel access list |
Result:
| Quote: | 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  |
|
| Back to top |
|
 |
Get_A_Fix Master

Joined: 07 May 2005 Posts: 206 Location: New Zealand
|
Posted: Mon Oct 24, 2016 11:12 pm Post subject: |
|
|
You could use something like..
| Code: |
proc isnum {string} {
if {[regexp {^-?\d+(\.\d+)?$} $string]} {
return 1;
}
return 0;
}
|
Then just ..
| Code: |
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. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Oct 25, 2016 3:27 am Post subject: |
|
|
Why not go with a more direct approach with string is digit instead of a regexp, cos is a lot faster?
| Code: |
if {![string is digit $number]} {
# do whatever
}
|
Proof:
| Code: |
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: |
% 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: |
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. |
|
| Back to top |
|
 |
Get_A_Fix Master

Joined: 07 May 2005 Posts: 206 Location: New Zealand
|
Posted: Tue Oct 25, 2016 4:53 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Wed Oct 26, 2016 2:57 pm Post subject: |
|
|
| 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. |
| Quote: | <- :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.
| Quote: | 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  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Thu Oct 27, 2016 9:15 am Post subject: |
|
|
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: |
set nick [lindex [split $text] 2]
|
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Thu Oct 27, 2016 2:02 pm Post subject: |
|
|
| 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: |
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.
| Quote: | 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  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Oct 28, 2016 7:18 am Post subject: |
|
|
In this case a
| Code: | | scan $text {%d%d%s} num niv user |
will do what you want.
You can even use it like:
| Code: |
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. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Fri Oct 28, 2016 3:13 pm Post subject: |
|
|
Ok.
I did not understand how the data nicks (% s) is taken.
It would be like this?:
| Quote: | 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  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Oct 29, 2016 4:02 am Post subject: |
|
|
The scan will create the $num, $niv and $user variables and use the ones you need.
| Code: |
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. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sat Oct 29, 2016 8:16 pm Post subject: |
|
|
Ok, thank you.  _________________ 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  |
|
| Back to top |
|
 |
|