mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 07:19:23 +01:00
Perform anti-flood checking on NOTICEs to channels
This commit is contained in:
parent
48daaa91ca
commit
8934936658
@ -10,6 +10,8 @@ package PBot::Core::Handlers::Chat;
|
|||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use parent 'PBot::Core::Class';
|
use parent 'PBot::Core::Class';
|
||||||
|
|
||||||
|
use PBot::Core::MessageHistory::Constants ':all';
|
||||||
|
|
||||||
sub initialize($self, %conf) {
|
sub initialize($self, %conf) {
|
||||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.notice', sub { $self->on_notice (@_) });
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.notice', sub { $self->on_notice (@_) });
|
||||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public (@_) });
|
$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
|
# log notice
|
||||||
$self->{pbot}->{logger}->log("NOTICE from $nick!$user\@$host to $to: $text\n");
|
$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
|
# nothing further to do with NOTICEs
|
||||||
return undef;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub on_public($self, $event_type, $event) {
|
sub on_public($self, $event_type, $event) {
|
||||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4675,
|
BUILD_REVISION => 4676,
|
||||||
BUILD_DATE => "2023-05-14",
|
BUILD_DATE => "2023-05-14",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user