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

Rate-limit now per-channel (sort of)

This commit is contained in:
Pragmatic Software 2010-08-14 09:45:58 +00:00
parent dd8f0e1811
commit 0f47100dc9
2 changed files with 15 additions and 3 deletions

View File

@ -203,6 +203,8 @@ sub interpreter {
my ($result, $channel);
my $pbot = $self->{pbot};
$from = lc $from;
# remove trailing comma or colon from keyword if keyword has other characters beforehand
$keyword =~ s/^(.+)[:,]$/$1/;
@ -239,8 +241,16 @@ sub interpreter {
return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command);
}
my $last_ref_in = 0;
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}) {
if(exists $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in}) {
if($self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} eq $from) {
$last_ref_in = 1;
}
}
if(($last_ref_in == 1) and (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.";
}
}
@ -255,6 +265,7 @@ sub interpreter {
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++;
$self->factoids->hash->{$channel}->{$keyword}->{ref_user} = $nick;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} = $from;
return $self->{factoidmodulelauncher}->execute_module($from, $tonick, $nick, $user, $host, $keyword, $arguments);
}
@ -270,6 +281,7 @@ sub interpreter {
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++;
$self->factoids->hash->{$channel}->{$keyword}->{ref_user} = $nick;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} = $from;
$self->{pbot}->logger->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host): $keyword: Displaying text \"" . $self->factoids->hash->{$channel}->{$keyword}->{action} . "\"\n");

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 232,
BUILD_DATE => "2010-07-22",
BUILD_REVISION => 233,
BUILD_DATE => "2010-08-14",
};
1;