From 0f47100dc974e55d00d4661710e26fdad15aef02 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 14 Aug 2010 09:45:58 +0000 Subject: [PATCH] Rate-limit now per-channel (sort of) --- PBot/Factoids.pm | 14 +++++++++++++- PBot/VERSION.pm | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 4b60362b..4144ee8d 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -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"); diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index e94daf63..57ca0cb7 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -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;