From 75f6d86a88db2df60c286fc48c0a1d06d07e07f2 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 13 Aug 2018 14:25:35 -0700 Subject: [PATCH] AntiFlood: disregard unreg spam floods on +z channels --- PBot/AntiFlood.pm | 7 ++++++- PBot/Interpreter.pm | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index e42d2719..39078ec5 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -292,7 +292,7 @@ sub update_join_watch { } sub check_flood { - my ($self, $channel, $nick, $user, $host, $text, $max_messages, $max_time, $mode) = @_; + my ($self, $channel, $nick, $user, $host, $text, $max_messages, $max_time, $mode, $stuff) = @_; $channel = lc $channel; my $mask = "$nick!$user\@$host"; @@ -346,6 +346,11 @@ sub check_flood { return; } + # don't do flood processing for unidentified or banned users in +z channels + if (defined $stuff and $stuff->{'chan-z'} and ($stuff->{'unidentified'} or $stuff->{'banned'})) { + return; + } + my $ancestor = $self->{pbot}->{messagehistory}->{database}->get_ancestor_id($account); $self->{pbot}->{logger}->log("Processing anti-flood account $account " . ($ancestor != $account ? "[ancestor $ancestor] " : '') . "for mask $mask\n") if $self->{pbot}->{registry}->get_value('antiflood', 'debug_account'); diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 3d655d10..327d8002 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -69,20 +69,32 @@ sub process_line { $flood_threshold = $pbot->{registry}->get_value('antiflood', 'chat_flood_threshold') if not defined $flood_threshold; $flood_time_threshold = $pbot->{registry}->get_value('antiflood', 'chat_flood_time_threshold') if not defined $flood_time_threshold; - $pbot->{antiflood}->check_flood($from, $nick, $user, $host, $text, - $flood_threshold, $flood_time_threshold, - $pbot->{messagehistory}->{MSG_CHAT}) if defined $from; - if (defined $from and $from =~ m/^#/) { my $chanmodes = $self->{pbot}->{channels}->get_meta($from, 'MODE'); if (defined $chanmodes and $chanmodes =~ m/z/) { + $stuff->{'chan-z'} = 1; + if (exists $self->{pbot}->{bantracker}->{banlist}->{$from}->{'+q'}->{'$~a'}) { + my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account); + if (not defined $nickserv or not length $nickserv) { + $stuff->{unidentified} = 1; + } + } + if ($self->{pbot}->{bantracker}->is_banned($nick, $user, $host, $from)) { - $self->{pbot}->{logger}->log("Disregarding banned user message (channel $from is +z).\n"); - return 1; + $stuff->{banned} = 1; } } } + $pbot->{antiflood}->check_flood($from, $nick, $user, $host, $text, + $flood_threshold, $flood_time_threshold, + $pbot->{messagehistory}->{MSG_CHAT}, $stuff) if defined $from; + + if ($stuff->{banned}) { + $self->{pbot}->{logger}->log("Disregarding banned user message (channel $from is +z).\n"); + return 1; + } + my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); # get channel-specific trigger if available