3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 20:09:43 +01:00

Added rate_limit to factoids

This commit is contained in:
Pragmatic Software 2010-06-21 15:23:46 +00:00
parent c150e2018c
commit 818e09861c
3 changed files with 1067 additions and 16 deletions

View File

@ -94,6 +94,7 @@ sub add_factoid {
$self->factoids->hash->{$channel}->{$trigger}->{created_on} = gettimeofday; $self->factoids->hash->{$channel}->{$trigger}->{created_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$trigger}->{ref_count} = 0; $self->factoids->hash->{$channel}->{$trigger}->{ref_count} = 0;
$self->factoids->hash->{$channel}->{$trigger}->{ref_user} = "nobody"; $self->factoids->hash->{$channel}->{$trigger}->{ref_user} = "nobody";
$self->factoids->hash->{$channel}->{$trigger}->{rate_limit} = 15;
$self->save_factoids; $self->save_factoids;
} }
@ -227,10 +228,17 @@ sub interpreter {
return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command); return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command);
} }
if(exists $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on}) {
if(gettimeofday - $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} <= $self->factoids->hash->{$channel}->{$keyword}->{rate_limit}) {
return "/msg $nick '$keyword' is rate-limited; try again in " . ($self->factoids->hash->{$channel}->{$keyword}->{rate_limit} - int(gettimeofday - $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on})) . " seconds.";
}
}
if($self->factoids->hash->{$channel}->{$keyword}->{enabled} == 0) { if($self->factoids->hash->{$channel}->{$keyword}->{enabled} == 0) {
$self->{pbot}->logger->log("$keyword disabled.\n"); $self->{pbot}->logger->log("$keyword disabled.\n");
return "/msg $nick $keyword is currently disabled."; return "/msg $nick $keyword is currently disabled.";
} elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'module') { }
elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'module') {
$self->{pbot}->logger->log("Found module\n"); $self->{pbot}->logger->log("Found module\n");
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++; $self->factoids->hash->{$channel}->{$keyword}->{ref_count}++;

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 194, BUILD_REVISION => 195,
BUILD_DATE => "2010-06-21", BUILD_DATE => "2010-06-21",
}; };

File diff suppressed because it is too large Load Diff