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 

multi lines max text length within time frame
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sat Jun 20, 2020 2:11 pm    Post subject: Reply with quote

does spaces get counted as well ? and if so could we take out all spaces ?
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Sun Jun 21, 2020 4:08 am    Post subject: Reply with quote

caesar gives you the solution in another thread (detect nicks with excessive digits in it)
Code:
set length [string length [regsub -all {\ } $text ""]]

_________________
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
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sun Jun 21, 2020 9:58 am    Post subject: Reply with quote

excellent thanks CrazyCat
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Mon Jun 22, 2020 12:45 am    Post subject: Reply with quote

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. Rolling Eyes
_________________
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
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Mon Jun 22, 2020 4:25 am    Post subject: Reply with quote

tnx ceasar

would that be like this?
Code:

set length [regexp -all -- {[^\s]} $text ""]
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Mon Jun 22, 2020 6:49 am    Post subject: Reply with quote

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
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Mon Jun 22, 2020 8:49 am    Post subject: Reply with quote

Tnx caesar
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Thu Jan 06, 2022 1:32 pm    Post subject: Reply with quote

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  }



         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
}



Last edited by simo on Sat Dec 17, 2022 6:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Thu Jan 06, 2022 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Fri Dec 16, 2022 1:03 pm    Post subject: Reply with quote

im still having issues with this code it doesnt seem accurate as it triggers when user didnt exceed threshold i suspect it not unset with the added timer : bflood(unsettime)
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sat Dec 17, 2022 2:09 pm    Post subject: Reply with quote

what i also discovered with nicknames like:

Quote:

[N]espresso




it doesnt seem to store well as it doesnt seem to unset the var properly it only keeps increasing text length and doesnt unset it:

Quote:

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



anyway to fix this ?
Back to top
View user's profile Send private message
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Mon Dec 19, 2022 2:36 pm    Post subject: Reply with quote

with the help of SpiKe^^ so far the fixed and working version incase anyone needs it to enable in channel

Syntax: !byte on/off

Code:


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) }
}


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
Goto page Previous  1, 2, 3
Page 3 of 3

 
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