Code: Select all
set length [string length [regsub -all {\ } $text ""]]
Code: Select all
regsub -all {[\s]} $text ""
Code: Select all
% 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
Code: Select all
% set length [string length [string map {" " "" " " ""} $text]]
12
Code: Select all
% regexp -all -- {[^\s]} $text ""
12
Code: Select all
% set text "fa24a22"
fa24a22
% regexp -all -- {[0-9]} $text
4
% time { regexp -all -- {[0-9]} $text } 100
3.82 microseconds per iteration
Code: Select all
if {[string length [regsub -all {[^0-9]} $nick ""]] > 6} {
# do whatever
}
Code: Select all
if {[regexp -all -- {[0-9]} $nick] > 6} {
# do whatever
}
Code: Select all
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 }
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
}
[N]espresso
anyway to fix this ?if {[info exists bflood($chan:$nick)]} { incr length $bflood($chan:$nick) }
utimer $bflood(unsettime) [list array unset bflood $chan:$nick]
set bflood($chan:$nick) $length
Code: Select all
bind PUB -|- !byte bytes:checker
setudef flag byteschecker
proc bytes:checker {nick uhost hand chan arg} {
if {![isop $nick $chan] && ![ishalfop $nick $chan] && ![matchattr $hand n|n $chan]} {return}
switch -nocase -- [lindex [split $arg] 0] {
on {
if {[channel get $chan byteschecker]} {
putserv "NOTICE $nick :byteschecker is already enabled on $chan."
} else {
channel set $chan +byteschecker
putserv "NOTICE $nick :byteschecker is now enabled."
}
}
off {
if {![channel get $chan byteschecker]} {
putserv "NOTICE $nick :byteschecker is already disabled on $chan."
} else {
channel set $chan -byteschecker
putserv "NOTICE $nick :byteschecker is now disabled."
}
}
}
}
set bflood(maxlength) 350
set bflood(unsettime) 3
bind pubm - * pubm:byteflood
proc pubm:byteflood {nick host hand chan text} {
if {![channel get $chan byteschecker]} { return }
if {[validuser $hand] && [matchattr $hand +bfmo|fmo $chan]} { return 0 }
if {(![botisop $chan]) || ([isop $nick $chan]) || ([ishalfop $nick $chan]) || ([validuser $hand] && [matchattr $hand +bfmo|fmo $chan])} {return}
global bflood
set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
set lengthXZ [regexp -all -- {[^\s]} $text ""]
if {[info exists bflood($chan:$nick)]} { incr lengthXZ $bflood($chan:$nick) }
if {($lengthXZ > $bflood(maxlength))} {
if {[isvoice $nick $chan]} { pushmode $chan -v $nick }
if {[string match -nocase "*@*irccloud*" $host]} {
regsub -all -- ~ $host "" host
set ident [lindex [split $host @] 0]
set xbmaskx [string map {sid id uid id} $ident]
set bmask *!*[string tolower $xbmaskx ]@*
if {![ischanban $bmask $chan]} { pushmode $chan +b $bmask }
} else {
set bmask "[maskhost $nick!$host 2]"
if {![ischanban $bmask $chan]} { pushmode $chan +b $bmask }
}
if {[onchan $nick $chan]} { putkick $chan $nick "Excess Characters Flood" }
after [expr {30*1000*60}] [list Qtimed:banQ $chan $bmask]
if {[info exists bflood($chan:$nick)]} { unset bflood($chan:$nick) }
return 0
}
if {![info exists bflood($chan:$nick)]} { set bflood($chan:$nick) $lengthXZ ; utimer $bflood(unsettime) [list unset:byteflood $chan $nick]}
return 0
}
proc Qtimed:banQ {chan banmask} {
if {[ischanban $banmask $chan]} {
pushmode2 $chan -b $banmask
}
}
proc unset:byteflood {chan nick} {
global bflood
if {[info exists bflood($chan:$nick)]} { unset bflood($chan:$nick) }
}