From 314eabaf3ef08531d6021b466f254adbb590767f Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 4 Dec 2011 01:13:21 +0000 Subject: [PATCH] Quotegrabs: added more information to getq (grab owner and timestamp) Interpreter: remove leading and trailing whitespace from text to improve parsing AntiFlood: Remove some log output, improve some other log output --- PBot/AntiFlood.pm | 12 ++++++------ PBot/Interpreter.pm | 3 +++ PBot/Quotegrabs.pm | 8 ++++++-- PBot/VERSION.pm | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index ff5f40af..1beea233 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -94,7 +94,6 @@ sub add_message { if($mode == $self->{FLOOD_JOIN}) { if($text =~ /^JOIN/) { $self->message_history->{$account}->{channels}->{$channel}{join_watch}++; - $self->{pbot}->logger->log("$account $channel joinwatch adjusted: " . $self->message_history->{$account}->{channels}->{$channel}{join_watch} . "\n"); } else { # PART or QUIT # check QUIT message for netsplits, and decrement joinwatch if found @@ -204,7 +203,7 @@ sub check_flood { } if($max_messages > 0 and $length >= $max_messages) { - $self->{pbot}->logger->log("More than $max_messages messages, comparing time differences ($max_time)\n") if $mode == $self->{FLOOD_JOIN}; + # $self->{pbot}->logger->log("More than $max_messages messages, comparing time differences ($max_time)\n") if $mode == $self->{FLOOD_JOIN}; my %msg; if($mode == $self->{FLOOD_CHAT}) { @@ -213,9 +212,9 @@ sub check_flood { elsif($mode == $self->{FLOOD_JOIN}) { my $count = 0; my $i = $length - 1; - $self->{pbot}->logger->log("Checking flood history, i = $i\n") if $self->message_history->{$account}->{channels}->{$channel}{join_watch} >= $max_messages; + # $self->{pbot}->logger->log("Checking flood history, i = $i\n") if $self->message_history->{$account}->{channels}->{$channel}{join_watch} >= $max_messages; for(; $i >= 0; $i--) { - $self->{pbot}->logger->log($i . " " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{mode} ." " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{msg} . " " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{timestamp} . " [" . ago_exact(time - $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{timestamp}) . "]\n") if $self->message_history->{$account}->{channels}->{$channel}{join_watch} >= $max_messages; + # $self->{pbot}->logger->log($i . " " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{mode} ." " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{msg} . " " . $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{timestamp} . " [" . ago_exact(time - $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{timestamp}) . "]\n") if $self->message_history->{$account}->{channels}->{$channel}{join_watch} >= $max_messages; next if $self->message_history->{$account}->{channels}->{$channel}{messages}->[$i]{mode} != $self->{FLOOD_JOIN}; last if ++$count >= 4; } @@ -406,8 +405,9 @@ sub check_nickserv_accounts { my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask); if(defined $baninfo) { - $self->{pbot}->logger->log("anti-flood: [check-bans] $mask is banned in $baninfo->{channel} by $baninfo->{owner}\n"); - push @banned_channels, $baninfo->{channel}; + $self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}\n"); + push @banned_channels, $baninfo->{channel}; + $self->{pbot}->conn->privmsg($nick, "You have been banned in $baninfo->{channel} for attempting to evade a ban on $baninfo->{banmask} set by $baninfo->{owner}"); } } diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 259d9f8e..0cdc4c3f 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -71,6 +71,9 @@ sub process_line { $from = lc $from if defined $from; + $text =~ s/^\s+//; + $text =~ s/\s+$//; + my $pbot = $self->pbot; $pbot->antiflood->check_flood($from, $nick, $user, $host, $text, $pbot->{MAX_FLOOD_MESSAGES}, 10, $pbot->antiflood->{FLOOD_CHAT}) if defined $from; diff --git a/PBot/Quotegrabs.pm b/PBot/Quotegrabs.pm index 7798aa3b..300307e7 100644 --- a/PBot/Quotegrabs.pm +++ b/PBot/Quotegrabs.pm @@ -12,6 +12,8 @@ use vars qw($VERSION); $VERSION = $PBot::PBot::VERSION; use HTML::Entities; +use Time::Duration; +use Time::HiRes qw(gettimeofday); sub new { if(ref($_[1]) eq 'HASH') { @@ -46,7 +48,7 @@ sub initialize { #------------------------------------------------------------------------------------- $pbot->commands->register(sub { $self->grab_quotegrab(@_) }, "grab", 0); $pbot->commands->register(sub { $self->show_quotegrab(@_) }, "getq", 0); - $pbot->commands->register(sub { $self->delete_quotegrab(@_) }, "delq", 0); + $pbot->commands->register(sub { $self->delete_quotegrab(@_) }, "delq", 10); $pbot->commands->register(sub { $self->show_random_quotegrab(@_) }, "rq", 0); } @@ -261,7 +263,9 @@ sub show_quotegrab { } my $quotegrab = $self->{quotegrabs}[$arguments - 1]; - return "$arguments: <$quotegrab->{nick}> $quotegrab->{text}"; + my $timestamp = $quotegrab->{timestamp}; + my $ago = ago(gettimeofday - $timestamp); + return "$arguments: grabbed by $quotegrab->{grabbed_by} on " . localtime($timestamp) . " [$ago] <$quotegrab->{nick}> $quotegrab->{text}"; } sub show_random_quotegrab { diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 9067ba5d..e0f448ab 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 => 322, - BUILD_DATE => "2011-10-31", + BUILD_REVISION => 323, + BUILD_DATE => "2011-12-03", }; 1;