This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

protect flood

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pilouuu
Halfop
Posts: 82
Joined: Mon Dec 26, 2005 8:03 pm

protect flood

Post by pilouuu »

hi

Code: Select all

set dbfile "scripts/database.txt" 

bind pub - !blg aleatory 

proc aleatory {nick uhost hand chan arg} { 
 global dbfile 
 set r [lindex [set d [split [read [set f [open $dbfile]]] \n]] [rand [llength $d]]] 
 puthelp "PRIVMSG $chan :$r $nick" 
 close $f 
}
putlog "blg loaded"
possible to add protection flood?

expl:
user> !blg
bot> blabla
user> !blg
bot> blabla
user> !blg
bot> blabla
user> !blg
the bot say /notice user you have been ignoring for 1 mns and set ignore user for 1 mns

thx
p
pilouuu
Halfop
Posts: 82
Joined: Mon Dec 26, 2005 8:03 pm

Post by pilouuu »

Code: Select all

# database
set dbfile "scripts/database.txt" 

# bind
bind pub - !blg aleatory

# set flood 
set fun(flood) 5:30 

# Ignorer users after flood (0=no, 1=yes) : 
set fun(ignore) 1 

# Yes?,tine mns : 
set fun(ignoretime) 1 

# flags protect: 
set fun(ignflags) "fmnov|fmnov" 

proc fun:flood:init {} { 
global fun funflood 
set fun(floodnum) [lindex [split $fun(flood) :] 0] 
set fun(floodtime) [lindex [split $fun(flood) :] 1] 
set i [expr $fun(floodnum) - 1] 
while {$i >= 0} { 
   set funflood($i) 0 
   incr i -1 
} 
} 
fun:flood:init 

proc fun:flood {nick uhost} { 
global fun funflood botnick 
if {$fun(floodnum) == 0} { 
   return 0 
} 
set i [expr $fun(floodnum) - 1] 
while {$i >= 1} { 
   set funflood($i) $funflood([expr $i - 1]) 
   incr i -1 
} 
set funflood(0) [unixtime] 
if {[expr [unixtime] - $funflood([expr $fun(floodnum) - 1])] <= $fun(floodtime)} { 
   if {$fun(ignore)} { 
      newignore [join [maskhost *!*[string trimleft $uhost ~]]] $botnick "Flood" $fun(ignoretime) 
   } 
   return 1 
} { 
   return 0 
} 
}

proc aleatory {nick uhost hand chan arg} {
if ![matchattr $nick $fun(ignflags) $channel] { 
   if {[fun:flood $nick $uhost]} { 

 global dbfile 
 set r [lindex [set d [split [read [set f [open $dbfile]]] \n]] [rand [llength $d]]] 
 puthelp "PRIVMSG $chan :$r $nick" 
 close $f 
} 
putlog "blg loaded"

help me please :D i am lost after :) error
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

here's how to do that (code from my rssnews script) inside your public cmd proc:

Code: Select all

...
	variable pcount; variable pubflud
	if {[info exists pcount]} {
		set n [lindex $pcount 1]; incr n
		set ts [lindex $pcount 0]
		set pcount [list $ts $n]
		scan $pubflud {%[^:]:%s} maxr maxt
		if {$n >= $maxr} {
			if {[unixtime] - $ts <= $maxt} {return}
			set n 1; set ts [unixtime]
		}
	} {
		set n 1; set ts [unixtime]
	}
	set pcount [list $ts $n]
...
this thing will ignore any command requests beyond M:N (at most M requests in N seconds), set in the global variable pubflood (of course, you need to replace variable with global since you don't use namespaces)
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
p
pilouuu
Halfop
Posts: 82
Joined: Mon Dec 26, 2005 8:03 pm

Post by pilouuu »

ok thx my variable

set pubflud 5:30

it good?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

noone could possibly know that but you
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
p
pilouuu
Halfop
Posts: 82
Joined: Mon Dec 26, 2005 8:03 pm

Post by pilouuu »

lol the proc is good :) lol :) thx demond :)
Post Reply