From 8934936658639931097d9f9d709a775b2e1f464c Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 14 May 2023 15:56:17 -0700 Subject: [PATCH] Perform anti-flood checking on NOTICEs to channels --- lib/PBot/Core/Handlers/Chat.pm | 28 +++++++++++++++++++++++++++- lib/PBot/VERSION.pm | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/PBot/Core/Handlers/Chat.pm b/lib/PBot/Core/Handlers/Chat.pm index e4372586..761784ec 100644 --- a/lib/PBot/Core/Handlers/Chat.pm +++ b/lib/PBot/Core/Handlers/Chat.pm @@ -10,6 +10,8 @@ package PBot::Core::Handlers::Chat; use PBot::Imports; use parent 'PBot::Core::Class'; +use PBot::Core::MessageHistory::Constants ':all'; + sub initialize($self, %conf) { $self->{pbot}->{event_dispatcher}->register_handler('irc.notice', sub { $self->on_notice (@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public (@_) }); @@ -32,8 +34,32 @@ sub on_notice($self, $event_type, $event) { # log notice $self->{pbot}->{logger}->log("NOTICE from $nick!$user\@$host to $to: $text\n"); + # handle NOTICE to channel (message history and anti-flood) + if ($to =~ /^#/) { + # add hostmask to user/message tracking database and get their account id + my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host); + + # add message to message history as a chat message + $self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $to, $text, MSG_CHAT); + + # look up channel-specific flood threshold settings from registry + my $flood_threshold = $self->{pbot}->{registry}->get_value($to, 'chat_flood_threshold'); + my $flood_time_threshold = $self->{pbot}->{registry}->get_value($to, 'chat_flood_time_threshold'); + + # get general flood threshold settings if there are no channel-specific settings + $flood_threshold //= $self->{pbot}->{registry}->get_value('antiflood', 'chat_flood_threshold'); + $flood_time_threshold //= $self->{pbot}->{registry}->get_value('antiflood', 'chat_flood_time_threshold'); + + # perform anti-flood processing on this message + $self->{pbot}->{antiflood}->check_flood( + $to, $nick, $user, $host, $text, + $flood_threshold, $flood_time_threshold, + MSG_CHAT + ); + } + # nothing further to do with NOTICEs - return undef; + return 0; } sub on_public($self, $event_type, $event) { diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 5f0c3b43..56a675d6 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4675, + BUILD_REVISION => 4676, BUILD_DATE => "2023-05-14", };