Jon Portnoy > Bot-Cobalt-0.016002 > Bot::Cobalt::IRC::FloodChk

Download:
Bot-Cobalt-0.016002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.016002   Source  

NAME ^

Bot::Cobalt::IRC::FloodChk - Flood check utils for Bot::Cobalt

SYNOPSIS ^

  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
  }

DESCRIPTION ^

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

new

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.

check

  $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

Clear the tracked state for a specified context and key; if the key is omitted, the entire context is cleared.

expire

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.

SEE ALSO ^

Algorithm is borrowed from an excellent article regarding Algorithm::FloodControl; for a more generic rate limiting solution, try there.

AUTHOR ^

Jon Portnoy <avenj@cobaltirc.org>

http://www.cobaltirc.org

syntax highlighting: