View previous topic :: View next topic |
Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Sat Jun 20, 2020 2:11 pm Post subject: |
|
|
does spaces get counted as well ? and if so could we take out all spaces ? |
|
Back to top |
|
 |
CrazyCat Owner

Joined: 13 Jan 2002 Posts: 987 Location: France
|
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Sun Jun 21, 2020 9:58 am Post subject: |
|
|
excellent thanks CrazyCat |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3740 Location: Mint Factory
|
Posted: Mon Jun 22, 2020 12:45 am Post subject: |
|
|
Your regsub should be:
Code: |
regsub -all {[\s]} $text ""
|
because that will substitute all white spaces not just space with nothing:
Code: |
% set text "some tab space"
some tab space
% regsub -all {\ } $text ""
some tabspace
% regsub -all {[\s]} $text ""
sometabspace
% string lengt [regsub -all {[\s]} $text ""]
12
|
You could go with a string map instead:
Code: |
% set length [string length [string map {" " "" " " ""} $text]]
12
|
or another cleaner approach with regexp:
Code: |
% regexp -all -- {[^\s]} $text ""
12
|
that returns the length without the white space characters.
Edit: Speaking of the topic CrazyCat mentioned, here's another regexp I didn't think of last time:
Code: |
% set text "fa24a22"
fa24a22
% regexp -all -- {[0-9]} $text
4
% time { regexp -all -- {[0-9]} $text } 100
3.82 microseconds per iteration
|
so that line turns from:
Code: |
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
|
into:
Code: |
if {[regexp -all -- {[0-9]} $nick] > 6} {
# do whatever
}
|
as you tried and for some reason i failed to see the proper results.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Mon Jun 22, 2020 4:25 am Post subject: |
|
|
tnx ceasar
would that be like this?
Code: |
set length [regexp -all -- {[^\s]} $text ""]
|
|
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3740 Location: Mint Factory
|
Posted: Mon Jun 22, 2020 6:49 am Post subject: |
|
|
Yes, as I was testing stuff and kept editing the text i posted forgot to leave that as well. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Mon Jun 22, 2020 8:49 am Post subject: |
|
|
Tnx caesar |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Thu Jan 06, 2022 1:32 pm Post subject: |
|
|
i used this code on dalnet for few days now and it doesnt seem to count all chars from multiple lines it seems to count 1 line only to match against the threshold of 250
this is what i work with at the moment
Code: |
set bflood(maxlength) 250
set bflood(unsettime) 2
bind pubm - * pubm:byteflood
proc pubm:byteflood {nick host hand chan text} {
global bflood
if {(![botisop $chan]) || ([isop $nick $chan]) || ([ishalfop $nick $chan]) || ([validuser $hand] && [matchattr $hand +bfmo|fmo $chan])} {return}
set nick [string tolower $nick]
set chan [string tolower $chan]
set text [stripcodes * $text]
set length [string length $text]
set length [regexp -all -- {[^\s]} $text ""]
if {[info exists bflood($chan:$nick)]} { incr length $bflood($chan:$nick) }
if {($length > $bflood(maxlength))} {
if {[isvoice $nick $chan]} { pushmode $chan -v $nick }
dobans:lockchanx $chan
if {[set chost [getchanhost $nick $chan]] ne ""} {
switch -glob -- $chost {
{*.irccloud.com} - {*.mibbit.com} - {*.kiwiirc.com} - {*2001*67c*2f08*} - {*192.184.8.*} - {*192.184.9.*} - {*192.184.9.*} - {*192.184.10.*} {
}
{default} {
set banmask [maskhost $nick!$chost 4]
pushmode $chan +b $banmask
}
}
}
flushmode $chan
array unset bflood $chan:$nick
return 0
}
if {![info exists bflood($chan:$nick)]} {
utimer $bflood(unsettime) [list array unset bflood $chan:$nick]
}
set bflood($chan:$nick) $length
return 0
}
bind ctcp - action pubmaction:byteflood
proc pubmaction:byteflood { nick uhost hand chan key arg } {
if {[isbotnick $chan]} return
pubm:byteflood $nick $uhost $hand $chan $arg
}
|
|
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 894
|
Posted: Thu Jan 06, 2022 1:40 pm Post subject: |
|
|
i also tried using instead of
Quote: | if {($length > $bflood(maxlength))} { |
this instead
Quote: | if {($bflood($chan:$nick) > $bflood(maxlength))} { |
but it didnt seem to do either |
|
Back to top |
|
 |
|