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 

detect nicks with excessive digits in it

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Wed Dec 07, 2016 1:23 pm    Post subject: detect nicks with excessive digits in it Reply with quote

is it possible to have tcl check for digits like more than 6 digits anywhere in the nick

Last edited by simo on Sun Mar 03, 2019 12:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Thu Dec 08, 2016 2:09 am    Post subject: Reply with quote

Code:

if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
   # 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
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Thu Dec 08, 2016 4:43 pm    Post subject: Reply with quote

tested it and works fine thnx caesar
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Thu Jun 04, 2020 11:17 pm    Post subject: Reply with quote

its old topic but i tried this one again and it seems it counts general chars lenght and not the amount of digits anywhere in the nick
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Thu Jun 04, 2020 11:42 pm    Post subject: Reply with quote

i tried this

Code:

   if {[regexp -all {[0-9]} $nick] > 6} {
       do whatever here
}


it does seem to work not sure if its proper and not sure if its fastest ? since from what i keep hearing is regexp might not be the fastest to process
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Fri Jun 05, 2020 1:27 am    Post subject: Reply with quote

The code you mentioned returns the digits from the string, not it's length, hence why i suggested the initial code:
Code:

if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
   # do whatever
}

that removes any character that isn't in the 0 to 9 range and then returns it's length.

Anyway, there are 3 options to get the digits from a string:

1. regsub
2. regexp
3. split, loop and compare

Code:

% set text "f2A94d"
f2A94d

% regsub -all {[^0-9]} $text ""
294

% join [regexp -all -inline -- {[0-9]+} $text] ""
294

% join [regexp -all -inline -- {\d+} $text] ""
294

% foreach e [split $text ""] {
        if {[string is integer $e]} {
                append result $e
        }
}
% puts $result
294


Now, if you want to see who's faster, or if you wonder if that regsub is slow:
Code:

% time { regsub -all {[^0-9]} $text "" } 1000
3.553 microseconds per iteration

% time { join [regexp -all -inline -- {\d+} $text] "" } 1000
3.457 microseconds per iteration
% time { join [regexp -all -inline -- {[0-9]+} $text] "" } 1000
3.939 microseconds per iteration

% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
10.051 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
8.604 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
9.156 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
6.549 microseconds per iteration
% time { foreach e [split $text ""] { if {[string is integer $e]} { append result $e } } } 1000
9.37 microseconds per iteration


Right off the bat we see two possible candidates, so we try again with 10000 times:
Code:

% time { regsub -all {[^0-9]} $text "" } 10000
2.5413 microseconds per iteration
% time { join [regexp -all -inline -- {\d+} $text] "" } 10000
2.7552 microseconds per iteration

Hope this answers your question. Smile

Edit: We can use scan instead of string is integer
Code:

% foreach e [split $text ""] {
        if {[scan $e {%d} no] > 0} {
                append result $e
        }
}
% puts $result
294

but given that it's a loop will still take a lot longer than regsub or regexp:
Code:

% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
11.501 microseconds per iteration
% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
13.495 microseconds per iteration
% time { unset result; foreach e [split $text ""] { if {[scan $e {%d} no] > 0} { append result $e} } } 1000
13.228 microseconds per iteration



Edit: Actually the code you tried:
Code:

   if {[regexp -all {[0-9]} $nick] > 6} {
       #do whatever here
}

returns the length of digits from 0 to 9 it finds in $nick variable. Duno at what was looking at when did the initial test. /facepalm
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Mon Jun 22, 2020 1:22 am; edited 1 time in total
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Fri Jun 05, 2020 1:31 pm    Post subject: Reply with quote

Quote:

that removes any character that isn't in the 0 to 9 range and then returns it's length.


but we wanted to count the digits in the nick to check for amount of digits

as this seems to count the length of the nick and not the amount of digits in it:

Code:

if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
   # do whatever
}
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Sat Jun 06, 2020 3:23 am    Post subject: Reply with quote

Code:

% set nick "f2A94d"
f2A94d
% regsub -all {[^0-9]} $nick ""
294
% string length [regsub -all {[^0-9]} $nick ""]
3
% set nick "aaaa3db4"
aaaa3db4
% string length [regsub -all {[^0-9]} $nick ""]
2

isn't this what you where looking for?
_________________
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
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Sat Jun 06, 2020 8:39 am    Post subject: Reply with quote

im not sure what that does ceasar but what we was looking for was to count digits in nick and if exceeding like 6 or higher to take action
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Sat Jun 06, 2020 10:34 am    Post subject: Reply with quote

tested it again seems to work now
Back to top
View user's profile Send private message
CrazyCat
Owner


Joined: 13 Jan 2002
Posts: 987
Location: France

PostPosted: Sun Jun 07, 2020 5:58 pm    Post subject: Reply with quote

simo wrote:
im not sure what that does ceasar but what we was looking for was to count digits in nick and if exceeding like 6 or higher to take action

What does ceasar is quite simple: he replaces all characters which are not between 0 to 9 with nothing and count the length of the resulting string.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 894

PostPosted: Sun Jun 07, 2020 10:55 pm    Post subject: Reply with quote

Tnx crazycat after taking a look again i saw its working and its exactly what was desired another fine job from caesar tnx again caesar much appreciated as always
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 -> Script Requests 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