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 

string match ONLY LETTER (no number)

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


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Oct 24, 2016 9:34 pm    Post subject: string match ONLY LETTER (no number) Reply with quote

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 Smile
Back to top
View user's profile Send private message
Get_A_Fix
Master


Joined: 07 May 2005
Posts: 206
Location: New Zealand

PostPosted: Mon Oct 24, 2016 11:12 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Oct 25, 2016 3:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Get_A_Fix
Master


Joined: 07 May 2005
Posts: 206
Location: New Zealand

PostPosted: Tue Oct 25, 2016 4:53 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Wed Oct 26, 2016 2:57 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Oct 27, 2016 9:15 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Thu Oct 27, 2016 2:02 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri Oct 28, 2016 7:18 am    Post subject: Reply with quote

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
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Fri Oct 28, 2016 3:13 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sat Oct 29, 2016 4:02 am    Post subject: Reply with quote

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
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Sat Oct 29, 2016 8:16 pm    Post subject: Reply with quote

Ok, thank you. Very Happy
_________________
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 Smile
Back to top
View user's profile Send private message
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