Bot::Cobalt::IRC::FloodChk - Flood check utils for Bot::Cobalt
my $flood = Bot::Cobalt::IRC::FloodChk->new( count => 5, in => 4, ); ## Incoming IRC message, f.ex ## Throttle user to 5 messages in 4 seconds if ( $flood->check( $context, $nick ) ) { ## Flood detected } else { ## No flood, continue }
This is a fairly generic flood control manager intended for Bot::Cobalt::IRC (although it can be used anywhere you'd like to rate limit messages).
The object's constructor takes two mandatory parameters, count and in, indicating that count messages (or events, or whatever) are allowed in a window of in seconds.
$flood->check( $context, $key );
If there appears to be a flood in progress, returns the number of seconds until it would be permissible to process more events.
Returns boolean false if there is no flood detected.
Clear the tracked state for a specified context and key; if the key is omitted, the entire context is cleared.
Check all contexts and keys in the object for stale entries that can be safely removed; in other words, entries whose latest recorded event was more than the specified in seconds ago.
Algorithm is borrowed from an excellent article regarding Algorithm::FloodControl; for a more generic rate limiting solution, try there.
Jon Portnoy <avenj@cobaltirc.org>
http://www.cobaltirc.org
To install Bot::Cobalt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::Cobalt
CPAN shell
perl -MCPAN -e shell install Bot::Cobalt
For more information on module installation, please visit the detailed CPAN module installation guide.