From 6240aee0a09ac446df41cb2f6f981abb2d8e9964 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 31 Jan 2023 05:44:34 -0800 Subject: [PATCH] Simplify arguments for IRC handlers --- lib/PBot/Core/AntiFlood.pm | 16 +++--- lib/PBot/Core/Commands/ChanOp.pm | 6 +-- lib/PBot/Core/EventDispatcher.pm | 33 ++++++------ lib/PBot/Core/Handlers/BanList.pm | 24 ++++----- lib/PBot/Core/Handlers/Cap.pm | 20 +++---- lib/PBot/Core/Handlers/Channel.pm | 78 +++++++++++++-------------- lib/PBot/Core/Handlers/Chat.pm | 38 ++++++------- lib/PBot/Core/Handlers/NickList.pm | 18 +++---- lib/PBot/Core/Handlers/NickServ.pm | 16 +++--- lib/PBot/Core/Handlers/SASL.pm | 20 +++---- lib/PBot/Core/Handlers/Server.pm | 28 +++++----- lib/PBot/Core/Handlers/Users.pm | 14 ++--- lib/PBot/Core/IRC/Connection.pm | 27 ++-------- lib/PBot/Core/IRC/Event.pm | 8 ++- lib/PBot/Core/IRCHandlers.pm | 11 ++-- lib/PBot/Plugin/ActionTrigger.pm | 54 +++++++++---------- lib/PBot/Plugin/AntiAway.pm | 22 +++++++- lib/PBot/Plugin/AntiKickAutoRejoin.pm | 9 ++-- lib/PBot/Plugin/AntiNickSpam.pm | 8 +-- lib/PBot/Plugin/AntiRepeat.pm | 11 +++- lib/PBot/Plugin/AntiTwitter.pm | 3 +- lib/PBot/Plugin/AutoRejoin.pm | 20 +++---- lib/PBot/Plugin/Connect4.pm | 15 +++--- lib/PBot/Plugin/Counter.pm | 4 +- lib/PBot/Plugin/Example.pm | 17 ++++-- lib/PBot/Plugin/RelayUnreg.pm | 17 ++---- lib/PBot/Plugin/Spinach.pm | 10 ++-- lib/PBot/Plugin/TypoSub.pm | 7 ++- lib/PBot/Plugin/UrlTitles.pm | 15 ++++-- lib/PBot/VERSION.pm | 4 +- 30 files changed, 300 insertions(+), 273 deletions(-) diff --git a/lib/PBot/Core/AntiFlood.pm b/lib/PBot/Core/AntiFlood.pm index cf5cf391..be5bc875 100644 --- a/lib/PBot/Core/AntiFlood.pm +++ b/lib/PBot/Core/AntiFlood.pm @@ -6,7 +6,7 @@ # The nickserv/ban-evasion stuff probably ought to be in BanTracker or some # such suitable class. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::AntiFlood; @@ -845,7 +845,7 @@ sub check_bans { sub on_endofwhois { my ($self, $event_type, $event) = @_; - my $nick = $event->{event}->{args}[1]; + my $nick = $event->{args}[1]; delete $self->{whois_pending}->{$nick}; @@ -869,8 +869,8 @@ sub on_endofwhois { sub on_whoisuser { my ($self, $event_type, $event) = @_; - my $nick = $event->{event}->{args}[1]; - my $gecos = lc $event->{event}->{args}[5]; + my $nick = $event->{args}[1]; + my $gecos = lc $event->{args}[5]; my ($id) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($nick); @@ -881,8 +881,8 @@ sub on_whoisuser { sub on_whoisaccount { my ($self, $event_type, $event) = @_; - my $nick = $event->{event}->{args}[1]; - my $account = lc $event->{event}->{args}[2]; + my $nick = $event->{args}[1]; + my $account = lc $event->{args}[2]; $self->{pbot}->{logger}->log("[MH] $nick is using NickServ account [$account]\n"); @@ -902,9 +902,9 @@ sub on_whoisaccount { sub on_accountnotify { my ($self, $event_type, $event) = @_; - my $mask = $event->{event}->{from}; + my $mask = $event->{from}; my ($nick, $user, $host) = $mask =~ m/^([^!]+)!([^@]+)@(.*)/; - my $account = $event->{event}{args}[0]; + my $account = $event->{args}[0]; my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host); $self->{pbot}->{messagehistory}->{database}->update_hostmask_data($mask, {last_seen => scalar gettimeofday}); diff --git a/lib/PBot/Core/Commands/ChanOp.pm b/lib/PBot/Core/Commands/ChanOp.pm index 1d519cd3..66b956c2 100644 --- a/lib/PBot/Core/Commands/ChanOp.pm +++ b/lib/PBot/Core/Commands/ChanOp.pm @@ -90,7 +90,7 @@ sub initialize { sub on_inviting { my ($self, $event_type, $event) = @_; - my ($botnick, $target, $channel) = $event->{event}->args; + my ($botnick, $target, $channel) = $event->args; $self->{pbot}->{logger}->log("User $target invited to channel $channel.\n"); @@ -107,7 +107,7 @@ sub on_inviting { sub on_useronchannel { my ($self, $event_type, $event) = @_; - my ($botnick, $target, $channel) = $event->{event}->args; + my ($botnick, $target, $channel) = $event->args; $self->{pbot}->{logger}->log("User $target is already on channel $channel.\n"); @@ -124,7 +124,7 @@ sub on_useronchannel { sub on_nosuchnick { my ($self, $event_type, $event) = @_; - my ($botnick, $target, $msg) = $event->{event}->args; + my ($botnick, $target, $msg) = $event->args; $self->{pbot}->{logger}->log("$target: $msg\n"); diff --git a/lib/PBot/Core/EventDispatcher.pm b/lib/PBot/Core/EventDispatcher.pm index 35d4fad9..bdbb48e2 100644 --- a/lib/PBot/Core/EventDispatcher.pm +++ b/lib/PBot/Core/EventDispatcher.pm @@ -30,14 +30,15 @@ sub initialize { # NickList reserves 0 and 100 to ensure its list is populated by JOINs, etc, # before any handlers need to consult its list, or depopulated by PARTs, QUITs, # KICKs, etc, after any other handlers need to consult its list. + sub register_handler { - my ($self, $event_name, $subref, $priority) = @_; + my ($self, $name, $subref, $priority) = @_; # get the package of the calling subroutine my ($package) = caller(0); # internal identifier to find calling package's event handler - my $handler_id = "$package-$event_name"; + my $handler_id = "$package-$name"; my $entry = { priority => $priority // 50, @@ -46,12 +47,12 @@ sub register_handler { }; # create new priority-queue for event-name if one doesn't exist - if (not exists $self->{handlers}->{$event_name}) { - $self->{handlers}->{$event_name} = PBot::Core::Utils::PriorityQueue->new(pbot => $self->{pbot}); + if (not exists $self->{handlers}->{$name}) { + $self->{handlers}->{$name} = PBot::Core::Utils::PriorityQueue->new(pbot => $self->{pbot}); } # add the event handler - $self->{handlers}->{$event_name}->add($entry); + $self->{handlers}->{$name}->add($entry); # debugging if ($self->{pbot}->{registry}->get_value('eventdispatcher', 'debug')) { @@ -61,17 +62,17 @@ sub register_handler { # remove an event handler sub remove_handler { - my ($self, $event_name) = @_; + my ($self, $name) = @_; # get the package of the calling subroutine my ($package) = caller(0); # internal identifier to find calling package's event handler - my $handler_id = "$package-$event_name"; + my $handler_id = "$package-$name"; # remove the event handler - if (exists $self->{handlers}->{$event_name}) { - my $handlers = $self->{handlers}->{$event_name}; + if (exists $self->{handlers}->{$name}) { + my $handlers = $self->{handlers}->{$name}; for (my $i = 0; $i < $handlers->count; $i++) { my $handler = $handlers->get($i); @@ -82,8 +83,8 @@ sub remove_handler { } # remove root event-name key if it has no more handlers - if (not $self->{handlers}->{$event_name}->count) { - delete $self->{handlers}->{$event_name}; + if (not $self->{handlers}->{$name}->count) { + delete $self->{handlers}->{$name}; } } @@ -95,7 +96,7 @@ sub remove_handler { # send an event to its handlers sub dispatch_event { - my ($self, $event_name, $event_data) = @_; + my ($self, $name, $data) = @_; # debugging flag my $debug = $self->{pbot}->{registry}->get_value('eventdispatcher', 'debug') // 0; @@ -104,17 +105,17 @@ sub dispatch_event { my $dispatch_result= undef; # if the event-name has handlers - if (exists $self->{handlers}->{$event_name}) { + if (exists $self->{handlers}->{$name}) { # then dispatch the event to each one - foreach my $handler ($self->{handlers}->{$event_name}->entries) { + foreach my $handler ($self->{handlers}->{$name}->entries) { # debugging if ($debug) { - $self->{pbot}->{logger}->log("Dispatching $event_name to handler $handler->{id}\n"); + $self->{pbot}->{logger}->log("Dispatching $name to handler $handler->{id}\n"); } # invoke an event handler. a handler may return undef to indicate # that it decided not to handle this event. - my $handler_result = eval { $handler->{subref}->($event_name, $event_data) }; + my $handler_result = eval { $handler->{subref}->($name, $data) }; # check for exception if (my $exception = $@) { diff --git a/lib/PBot/Core/Handlers/BanList.pm b/lib/PBot/Core/Handlers/BanList.pm index 20321a51..b8d40187 100644 --- a/lib/PBot/Core/Handlers/BanList.pm +++ b/lib/PBot/Core/Handlers/BanList.pm @@ -3,7 +3,7 @@ # Purpose: Populates and maintains channel banlists by checking mode +b/+q # when joining channels and by tracking modes +b/+q and -b/-q in channels. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::BanList; @@ -30,7 +30,7 @@ sub initialize { sub on_endofnames { my ($self, $event_type, $event) = @_; - my $channel = lc $event->{event}->{args}[1]; + my $channel = lc $event->{args}[1]; $self->{pbot}->{logger}->log("Retrieving banlist for $channel.\n"); @@ -52,10 +52,10 @@ sub on_endofnames { sub on_banlist_entry { my ($self, $event_type, $event) = @_; - my $channel = lc $event->{event}->{args}[1]; - my $target = lc $event->{event}->{args}[2]; - my $source = lc $event->{event}->{args}[3]; - my $timestamp = $event->{event}->{args}[4]; + my $channel = lc $event->{args}[1]; + my $target = lc $event->{args}[2]; + my $source = lc $event->{args}[3]; + my $timestamp = $event->{args}[4]; my $ago = concise ago(gettimeofday - $timestamp); $self->{pbot}->{logger}->log("Ban List: [banlist entry] $channel: $target banned by $source $ago.\n"); @@ -66,10 +66,10 @@ sub on_banlist_entry { sub on_quietlist_entry { my ($self, $event_type, $event) = @_; - my $channel = lc $event->{event}->{args}[1]; - my $target = lc $event->{event}->{args}[3]; - my $source = lc $event->{event}->{args}[4]; - my $timestamp = $event->{event}->{args}[5]; + my $channel = lc $event->{args}[1]; + my $target = lc $event->{args}[3]; + my $source = lc $event->{args}[4]; + my $timestamp = $event->{args}[5]; my $ago = concise ago(gettimeofday - $timestamp); $self->{pbot}->{logger}->log("Ban List: [quietlist entry] $channel: $target quieted by $source $ago.\n"); @@ -80,7 +80,7 @@ sub on_quietlist_entry { sub on_endofbanlist { my ($self, $event_type, $event) = @_; - my $channel = lc $event->{event}->{args}[1]; + my $channel = lc $event->{args}[1]; # first check for saved bans no longer in channel foreach my $mask ($self->{pbot}->{banlist}->{banlist}->get_keys($channel)) { @@ -142,7 +142,7 @@ sub on_endofbanlist { sub on_endofquietlist { my ($self, $event_type, $event) = @_; - my $channel = lc $event->{event}->{args}[1]; + my $channel = lc $event->{args}[1]; my $mute_char = $self->{mute_char}; diff --git a/lib/PBot/Core/Handlers/Cap.pm b/lib/PBot/Core/Handlers/Cap.pm index 1fc3b04c..9e4a03ad 100644 --- a/lib/PBot/Core/Handlers/Cap.pm +++ b/lib/PBot/Core/Handlers/Cap.pm @@ -2,7 +2,7 @@ # # Purpose: Handles IRCv3 CAP event. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::Cap; @@ -24,17 +24,17 @@ sub initialize { sub on_cap { my ($self, $event_type, $event) = @_; - if ($event->{event}->{args}->[0] eq 'LS') { + if ($event->{args}[0] eq 'LS') { my $capabilities; my $caps_listed = 0; - if ($event->{event}->{args}->[1] eq '*') { + if ($event->{args}[1] eq '*') { # more CAP LS messages coming - $capabilities = $event->{event}->{args}->[2]; + $capabilities = $event->{args}[2]; } else { # final CAP LS message $caps_listed = 1; - $capabilities = $event->{event}->{args}->[1]; + $capabilities = $event->{args}[1]; } $self->{pbot}->{logger}->log("Client capabilities available: $capabilities\n"); @@ -57,10 +57,10 @@ sub on_cap { $self->request_caps($event); } } - elsif ($event->{event}->{args}->[0] eq 'ACK') { - $self->{pbot}->{logger}->log("Client capabilities granted: $event->{event}->{args}->[1]\n"); + elsif ($event->{args}[0] eq 'ACK') { + $self->{pbot}->{logger}->log("Client capabilities granted: $event->{args}[1]\n"); - my @caps = split /\s+/, $event->{event}->{args}->[1]; + my @caps = split /\s+/, $event->{args}[1]; foreach my $cap (@caps) { my ($key, $val) = split '=', $cap; @@ -76,8 +76,8 @@ sub on_cap { } } } - elsif ($event->{event}->{args}->[0] eq 'NAK') { - $self->{pbot}->{logger}->log("Client capabilities rejected: $event->{event}->{args}->[1]\n"); + elsif ($event->{args}[0] eq 'NAK') { + $self->{pbot}->{logger}->log("Client capabilities rejected: $event->{args}[1]\n"); } else { $self->{pbot}->{logger}->log("Unknown CAP event:\n"); diff --git a/lib/PBot/Core/Handlers/Channel.pm b/lib/PBot/Core/Handlers/Channel.pm index bda9fb55..4bb497b6 100644 --- a/lib/PBot/Core/Handlers/Channel.pm +++ b/lib/PBot/Core/Handlers/Channel.pm @@ -3,7 +3,7 @@ # Purpose: Handlers for general channel-related IRC events that aren't handled # by any specialized Handler modules. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::Channel; @@ -36,11 +36,11 @@ sub on_mode { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $mode_string, $channel) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->{args}->[0], - lc $event->{event}->{to}->[0], + $event->nick, + $event->user, + $event->host, + $event->{args}[0], + lc $event->{to}[0], ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -60,7 +60,7 @@ sub on_mode { } $mode = $modifier . $flag; - $target = $event->{event}->{args}->[++$i]; + $target = $event->{args}[++$i]; $self->{pbot}->{logger}->log("[MODE] $channel $mode" . (length $target ? " $target" : '') . " by $source\n"); @@ -112,10 +112,10 @@ sub on_join { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - lc $event->{event}->{to}->[0], + $event->nick, + $event->user, + $event->host, + lc $event->{to}[0], ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -131,8 +131,8 @@ sub on_join { # IRCv3 extended-join capability provides more details about user if (exists $self->{pbot}->{irc_capabilities}->{'extended-join'}) { my ($nickserv, $gecos) = ( - $event->{event}->{args}->[0], - $event->{event}->{args}->[1], + $event->{args}[0], + $event->{args}[1], ); $msg .= " $nickserv :$gecos"; @@ -147,7 +147,7 @@ sub on_join { $self->{pbot}->{messagehistory}->{database}->set_current_nickserv_account($message_account, ''); } - $self->{pbot}->{antiflood}->check_bans($message_account, $event->{event}->from, $channel); + $self->{pbot}->{antiflood}->check_bans($message_account, $event->from, $channel); } $self->{pbot}->{antiflood}->check_flood( @@ -164,11 +164,11 @@ sub on_invite { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $target, $channel) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - lc $event->{event}->{args}->[0] + $event->nick, + $event->user, + $event->host, + $event->to, + lc $event->{args}[0] ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -189,12 +189,12 @@ sub on_kick { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $target, $channel, $reason) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - lc $event->{event}->{args}->[0], - $event->{event}->{args}->[1] + $event->nick, + $event->user, + $event->host, + $event->to, + lc $event->{args}[0], + $event->{args}[1] ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -248,16 +248,16 @@ sub on_departure { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel, $args) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - lc $event->{event}->{to}->[0], - $event->{event}->args + $event->nick, + $event->user, + $event->host, + lc $event->{to}[0], + $event->args ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); - my $text = uc ($event->{event}->type) . ' ' . $args; + my $text = uc ($event->type) . ' ' . $args; my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host); @@ -295,7 +295,7 @@ sub on_departure { sub on_channelmodeis { my ($self, $event_type, $event) = @_; - my (undef, $channel, $modes) = $event->{event}->args; + my (undef, $channel, $modes) = $event->args; $self->{pbot}->{logger}->log("Channel $channel modes: $modes\n"); @@ -306,7 +306,7 @@ sub on_channelmodeis { sub on_channelcreate { my ($self, $event_type, $event) = @_; - my ($owner, $channel, $timestamp) = $event->{event}->args; + my ($owner, $channel, $timestamp) = $event->args; $self->{pbot}->{logger}->log("Channel $channel created by $owner on " . localtime($timestamp) . "\n"); @@ -318,16 +318,16 @@ sub on_channelcreate { sub on_topic { my ($self, $event_type, $event) = @_; - if (not length $event->{event}->{to}->[0]) { + if (not length $event->{to}[0]) { # on join - my (undef, $channel, $topic) = $event->{event}->args; + my (undef, $channel, $topic) = $event->args; $self->{pbot}->{logger}->log("Topic for $channel: $topic\n"); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC', $topic, 1); } else { # user changing topic - my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); - my $channel = $event->{event}->{to}->[0]; - my $topic = $event->{event}->{args}->[0]; + my ($nick, $user, $host) = ($event->nick, $event->user, $event->host); + my $channel = $event->{to}[0]; + my $topic = $event->{args}[0]; $self->{pbot}->{logger}->log("$nick!$user\@$host changed topic for $channel to: $topic\n"); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC', $topic, 1); @@ -340,7 +340,7 @@ sub on_topic { sub on_topicinfo { my ($self, $event_type, $event) = @_; - my (undef, $channel, $by, $timestamp) = $event->{event}->args; + my (undef, $channel, $by, $timestamp) = $event->args; $self->{pbot}->{logger}->log("Topic for $channel set by $by on " . localtime($timestamp) . "\n"); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_BY', $by, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_ON', $timestamp, 1); diff --git a/lib/PBot/Core/Handlers/Chat.pm b/lib/PBot/Core/Handlers/Chat.pm index 44c04bbf..99f79538 100644 --- a/lib/PBot/Core/Handlers/Chat.pm +++ b/lib/PBot/Core/Handlers/Chat.pm @@ -2,7 +2,7 @@ # # Purpose: IRC handlers for chat/message events. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::Chat; @@ -23,11 +23,11 @@ sub on_notice { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $to, $text) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - $event->{event}->{args}->[0], + $event->nick, + $event->user, + $event->host, + $event->to, + $event->{args}[0], ); # don't handle non-chat NOTICE @@ -39,7 +39,7 @@ sub on_notice { # if NOTICE is sent to the bot then replace the `to` field with the # sender's nick instead so when we pass it on to on_public ... if ($to eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { - $event->{event}->{to}->[0] = $nick; + $event->{to}[0] = $nick; } # handle this NOTICE as a public message @@ -53,12 +53,12 @@ sub on_public { my ($self, $event_type, $event) = @_; my ($from, $nick, $user, $host, $text, $tags) = ( - $event->{event}->{to}->[0], - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->{args}->[0], - $event->{event}->{args}->[1], + $event->{to}[0], + $event->nick, + $event->user, + $event->host, + $event->{args}[0], + $event->{args}[1], ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -73,7 +73,7 @@ sub on_action { my ($self, $event_type, $event) = @_; # prepend "/me " to the message text - $event->{event}->{args}->[0] = "/me " . $event->{event}->{args}->[0]; + $event->{args}[0] = "/me " . $event->{args}[0]; # pass this along to on_public $self->on_public($event_type, $event); @@ -84,11 +84,11 @@ sub on_msg { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $text, $tags) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->{args}->[0], - $event->{event}->{args}->[1], + $event->nick, + $event->user, + $event->host, + $event->{args}[0], + $event->{args}[1], ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); diff --git a/lib/PBot/Core/Handlers/NickList.pm b/lib/PBot/Core/Handlers/NickList.pm index 2818e70f..d020f0b4 100644 --- a/lib/PBot/Core/Handlers/NickList.pm +++ b/lib/PBot/Core/Handlers/NickList.pm @@ -2,7 +2,7 @@ # # Purpose: Maintains lists of nicks currently present in channels. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::NickList; @@ -23,7 +23,7 @@ sub initialize { $self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) }, 0); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_activity(@_) }, 0); $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_activity(@_) }, 0); - $self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag(@_) }, 0); + $self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag(@_) }, 0); # lowest priority so these get handled by NickList after all other handlers # (all other handlers should be given a priority < 100) @@ -39,7 +39,7 @@ sub initialize { sub on_namreply { my ($self, $event_type, $event) = @_; - my ($channel, $nicks) = ($event->{event}->{args}[2], $event->{event}->{args}[3]); + my ($channel, $nicks) = ($event->{args}[2], $event->{args}[3]); foreach my $nick (split ' ', $nicks) { my $stripped_nick = $nick; @@ -70,7 +70,7 @@ sub on_namreply { sub on_activity { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{to}[0]); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->{to}[0]); $self->{pbot}->{nicklist}->update_timestamp($channel, $nick); @@ -80,7 +80,7 @@ sub on_activity { sub on_join { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); $self->{pbot}->{nicklist}->add_nick($channel, $nick); @@ -95,7 +95,7 @@ sub on_join { sub on_part { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); $self->{pbot}->{nicklist}->remove_nick($channel, $nick); @@ -105,7 +105,7 @@ sub on_part { sub on_quit { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); + my ($nick, $user, $host) = ($event->nick, $event->user, $event->host); foreach my $channel (keys %{$self->{pbot}->{nicklist}->{nicklist}}) { if ($self->{pbot}->{nicklist}->is_present($channel, $nick)) { @@ -119,7 +119,7 @@ sub on_quit { sub on_kick { my ($self, $event_type, $event) = @_; - my ($nick, $channel) = ($event->{event}->to, $event->{event}->{args}[0]); + my ($nick, $channel) = ($event->to, $event->{args}[0]); $self->{pbot}->{nicklist}->remove_nick($channel, $nick); @@ -128,7 +128,7 @@ sub on_kick { sub on_nickchange { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); + my ($nick, $user, $host, $newnick) = ($event->nick, $event->user, $event->host, $event->args); foreach my $channel (keys %{$self->{pbot}->{nicklist}->{nicklist}}) { if ($self->{pbot}->{nicklist}->is_present($channel, $nick)) { diff --git a/lib/PBot/Core/Handlers/NickServ.pm b/lib/PBot/Core/Handlers/NickServ.pm index 7bdca7ed..96082f3e 100644 --- a/lib/PBot/Core/Handlers/NickServ.pm +++ b/lib/PBot/Core/Handlers/NickServ.pm @@ -2,7 +2,7 @@ # # Purpose: Handles NickServ-related IRC events. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::NickServ; @@ -61,11 +61,11 @@ sub on_notice { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $to, $text) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - $event->{event}->{args}->[0], + $event->nick, + $event->user, + $event->host, + $event->to, + $event->{args}[0], ); my $nickserv = $self->{pbot}->{registry}->get_value('general', 'identify_nick') // 'NickServ'; @@ -110,8 +110,8 @@ sub on_notice { sub on_nicknameinuse { my ($self, $event_type, $event) = @_; - my (undef, $nick, $msg) = $event->{event}->args; - my $from = $event->{event}->from; + my (undef, $nick, $msg) = $event->args; + my $from = $event->from; $self->{pbot}->{logger}->log("Received nicknameinuse for nick $nick from $from: $msg\n"); diff --git a/lib/PBot/Core/Handlers/SASL.pm b/lib/PBot/Core/Handlers/SASL.pm index bde5f9c6..5150a6aa 100644 --- a/lib/PBot/Core/Handlers/SASL.pm +++ b/lib/PBot/Core/Handlers/SASL.pm @@ -2,7 +2,7 @@ # # Purpose: Handles IRCv3 SASL events. Currently only PLAIN is supported. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::SASL; @@ -60,57 +60,57 @@ sub on_sasl_authenticate { sub on_rpl_loggedin { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[3] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[3] . "\n"); return 1; } sub on_rpl_loggedout { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); return 1; } sub on_err_nicklocked { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); $self->{pbot}->exit(EXIT_FAILURE); } sub on_rpl_saslsuccess { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); $event->{conn}->sl("CAP END"); return 1; } sub on_err_saslfail { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); $self->{pbot}->exit(EXIT_FAILURE); } sub on_err_sasltoolong { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); $self->{pbot}->exit(EXIT_FAILURE); } sub on_err_saslaborted { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); $self->{pbot}->exit(EXIT_FAILURE); } sub on_err_saslalready { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log($event->{event}->{args}->[1] . "\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); return 1; } sub on_rpl_saslmechs { my ($self, $event_type, $event) = @_; $self->{pbot}->{logger}->log("SASL mechanism not available.\n"); - $self->{pbot}->{logger}->log("Available mechanisms are: $event->{event}->{args}->[1]\n"); + $self->{pbot}->{logger}->log("Available mechanisms are: $event->{args}[1]\n"); $self->{pbot}->exit(EXIT_FAILURE); } diff --git a/lib/PBot/Core/Handlers/Server.pm b/lib/PBot/Core/Handlers/Server.pm index f8219f34..48d02c0f 100644 --- a/lib/PBot/Core/Handlers/Server.pm +++ b/lib/PBot/Core/Handlers/Server.pm @@ -2,7 +2,7 @@ # # Purpose: Handles server-related IRC events. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::Server; @@ -76,8 +76,8 @@ sub on_motd { my ($self, $event_type, $event) = @_; if ($self->{pbot}->{registry}->get_value('irc', 'show_motd')) { - my $from = $event->{event}->{from}; - my $msg = $event->{event}->{args}->[1]; + my $from = $event->{from}; + my $msg = $event->{args}[1]; $self->{pbot}->{logger}->log("MOTD from $from :: $msg\n"); } @@ -88,9 +88,9 @@ sub on_notice { my ($self, $event_type, $event) = @_; my ($server, $to, $text) = ( - $event->{event}->nick, - $event->{event}->to, - $event->{event}->{args}->[0], + $event->nick, + $event->to, + $event->{args}[0], ); # don't handle non-server NOTICE @@ -107,12 +107,12 @@ sub on_isupport { # remove and discard first and last arguments # (first arg is botnick, last arg is "are supported by this server") - shift @{$event->{event}->{args}}; - pop @{$event->{event}->{args}}; + shift @{$event->{args}}; + pop @{$event->{args}}; - my $logmsg = "$event->{event}->{from} supports:"; + my $logmsg = "$event->{from} supports:"; - foreach my $arg (@{$event->{event}->{args}}) { + foreach my $arg (@{$event->{args}}) { my ($key, $value) = split /=/, $arg; if ($key =~ s/^-//) { @@ -132,7 +132,7 @@ sub on_isupport { sub on_nickchange { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); + my ($nick, $user, $host, $newnick) = ($event->nick, $event->user, $event->host, $event->args); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -169,7 +169,7 @@ sub on_nickchange { sub on_nononreg { my ($self, $event_type, $event) = @_; - my $target = $event->{event}->{args}->[1]; + my $target = $event->{args}[1]; $self->{pbot}->{logger}->log("Cannot send private /msg to $target; they are blocking unidentified /msgs.\n"); @@ -178,13 +178,13 @@ sub on_nononreg { sub log_first_arg { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log("$event->{event}->{args}->[1]\n"); + $self->{pbot}->{logger}->log("$event->{args}[1]\n"); return 1; } sub log_third_arg { my ($self, $event_type, $event) = @_; - $self->{pbot}->{logger}->log("$event->{event}->{args}->[3]\n"); + $self->{pbot}->{logger}->log("$event->{args}[3]\n"); return 1; } diff --git a/lib/PBot/Core/Handlers/Users.pm b/lib/PBot/Core/Handlers/Users.pm index 63da2e30..55dbb4c4 100644 --- a/lib/PBot/Core/Handlers/Users.pm +++ b/lib/PBot/Core/Handlers/Users.pm @@ -2,7 +2,7 @@ # # Purpose: Handles IRC events related to PBot user accounts and user metadata. -# SPDX-FileCopyrightText: 2021 Pragmatic Software +# SPDX-FileCopyrightText: 2021-2023 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Core::Handlers::Users; @@ -23,10 +23,10 @@ sub on_join { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to + $event->nick, + $event->user, + $event->host, + $event->to ); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); @@ -67,7 +67,7 @@ sub on_join { sub on_departure { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); $self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host"); return 1; @@ -75,7 +75,7 @@ sub on_departure { sub on_kick { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{args}[0]); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->{args}[0]); ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); $self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host"); return 1; diff --git a/lib/PBot/Core/IRC/Connection.pm b/lib/PBot/Core/IRC/Connection.pm index 548ae05b..dbf23038 100644 --- a/lib/PBot/Core/IRC/Connection.pm +++ b/lib/PBot/Core/IRC/Connection.pm @@ -998,7 +998,6 @@ sub parse { if ($itype eq "ctcp") { # it's got CTCP in it! $self->parse_ctcp($type, $from, $stuff[0], $line); next; - } elsif ($type eq "public" or $type eq "msg" or $type eq "notice" @@ -1008,9 +1007,9 @@ sub parse { or $type eq "topic" or $type eq "invite" or $type eq "whoisaccount" + or $type eq "chghost" or $type eq "cap") # IRCv3 client capabilities pragma- { - $ev = PBot::Core::IRC::Event->new( $type, # pragma_ 2011/21/01 $from, @@ -1019,7 +1018,6 @@ sub parse { @stuff, ); } elsif ($type eq "quit" or $type eq "nick" or $type eq "account") { - $ev = PBot::Core::IRC::Event->new( $type, # pragma_ 2011/21/01 $from, @@ -1028,7 +1026,6 @@ sub parse { @stuff, ); } elsif ($type eq "kick") { - $ev = PBot::Core::IRC::Event->new( $type, # pragma_ 2011/21/01 $from, @@ -1036,8 +1033,10 @@ sub parse { $type, @stuff[0, 2 .. $#stuff], ); - - } elsif ($type eq "kill") { + } elsif ($type eq "kill" + or $type eq "wallops" + or $type eq "pong") + { $ev = PBot::Core::IRC::Event->new( $type, # pragma_ 2011/21/01 $from, @@ -1045,22 +1044,6 @@ sub parse { $type, $line ); # Ahh, what the hell. - } elsif ($type eq "wallops") { - $ev = PBot::Core::IRC::Event->new( - $type, # pragma_ 2011/21/01 - $from, - '', - $type, - $line - ); - } elsif ($type eq "pong") { - $ev = PBot::Core::IRC::Event->new( - $type, # pragma_ 2011/21/01 - $from, - '', - $type, - $line - ); } else { carp "Unknown event type: $type"; } diff --git a/lib/PBot/Core/IRC/Event.pm b/lib/PBot/Core/IRC/Event.pm index 12e7f52b..a2eea333 100644 --- a/lib/PBot/Core/IRC/Event.pm +++ b/lib/PBot/Core/IRC/Event.pm @@ -56,8 +56,11 @@ sub new { bless $self, $class; - if ($self->type !~ /\D/) { $self->type($self->trans($self->type)); } - else { $self->type(lc($self->type)); } + if ($self->type !~ /\D/) { + $self->type($self->trans($self->type)); + } else { + $self->type(lc($self->type)); + } $self->from($from); # sets nick, user, and host $self->args($args); # strips colons from args @@ -487,6 +490,7 @@ sub trans { 'cap' => 'cap', 'account' => 'account', 'authenticate' => 'authenticate', + 'chghost' => 'chghost', ); 1; diff --git a/lib/PBot/Core/IRCHandlers.pm b/lib/PBot/Core/IRCHandlers.pm index 6382b590..e96715a9 100644 --- a/lib/PBot/Core/IRCHandlers.pm +++ b/lib/PBot/Core/IRCHandlers.pm @@ -17,18 +17,18 @@ sub initialize { # nothing to do here } -# this default handler prepends 'irc.' to the event-type and then dispatches +# this default handler prepends 'irc.' to the event-name and then dispatches # the event to the rest of PBot via PBot::Core::EventDispatcher. sub default_handler { my ($self, $conn, $event) = @_; + # add conn to event object so we can access it within handlers + $event->{conn} = $conn; + my $result = $self->{pbot}->{event_dispatcher}->dispatch_event( "irc.$event->{type}", - { - conn => $conn, - event => $event - } + $event ); # log event if it was not handled and logging is requested @@ -36,6 +36,7 @@ sub default_handler { $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 2; $Data::Dumper::Useqq = 1; + delete $event->{conn}; # don't include conn in dump $self->{pbot}->{logger}->log(Dumper $event); } } diff --git a/lib/PBot/Plugin/ActionTrigger.pm b/lib/PBot/Plugin/ActionTrigger.pm index 9cef0982..62c7eb6c 100644 --- a/lib/PBot/Plugin/ActionTrigger.pm +++ b/lib/PBot/Plugin/ActionTrigger.pm @@ -399,17 +399,17 @@ sub on_kick { return 0 if $event->{interpreted}; my ($nick, $user, $host) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host + $event->nick, + $event->user, + $event->host ); my ($victim, $reason) = ( - $event->{event}->to, - $event->{event}->{args}[1] + $event->to, + $event->{args}[1] ); - my $channel = $event->{event}->{args}[0]; + my $channel = $event->{args}[0]; $self->check_trigger($nick, $user, $host, $channel, "KICK $victim $reason"); return 0; @@ -419,13 +419,13 @@ sub on_action { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $msg) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->args + $event->nick, + $event->user, + $event->host, + $event->args ); - my $channel = $event->{event}->{to}[0]; + my $channel = $event->{to}[0]; $msg =~ s/^\/me\s+//; @@ -437,12 +437,12 @@ sub on_public { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $msg) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->args); + $event->nick, + $event->user, + $event->host, + $event->args); - my $channel = $event->{event}->{to}[0]; + my $channel = $event->{to}[0]; $self->check_trigger($nick, $user, $host, $channel, "PRIVMSG $msg"); return 0; @@ -452,11 +452,11 @@ sub on_join { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel, $args) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - $event->{event}->args + $event->nick, + $event->user, + $event->host, + $event->to, + $event->args ); $self->check_trigger($nick, $user, $host, $channel, "JOIN"); @@ -467,14 +467,14 @@ sub on_departure { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel, $args) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - $event->{event}->args + $event->nick, + $event->user, + $event->host, + $event->to, + $event->args ); - $self->check_trigger($nick, $user, $host, $channel, (uc $event->{event}->type) . " $args"); + $self->check_trigger($nick, $user, $host, $channel, (uc $event->type) . " $args"); return 0; } diff --git a/lib/PBot/Plugin/AntiAway.pm b/lib/PBot/Plugin/AntiAway.pm index cbab9f80..8a2ae887 100644 --- a/lib/PBot/Plugin/AntiAway.pm +++ b/lib/PBot/Plugin/AntiAway.pm @@ -12,9 +12,11 @@ use PBot::Imports; sub initialize { my ($self, %conf) = @_; + $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_nicks', $conf{bad_nicks} // '([[:punct:]](afk|brb|bbl|away|sleep|z+|work|gone|study|out|home|busy|off)[[:punct:]]*$|.+\[.*\]$)' ); + $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me (is (away|gone)|.*auto.?away)'); $self->{pbot}->{registry}->add_default('text', 'antiaway', 'kick_msg', 'http://sackheads.org/~bnaylor/spew/away_msgs.html'); @@ -30,12 +32,20 @@ sub unload { sub on_nickchange { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); + + my ($nick, $user, $host, $newnick) = ( + $event->nick, + $event->user, + $event->host, + $event->args + ); my $bad_nicks = $self->{pbot}->{registry}->get_value('antiaway', 'bad_nicks'); + if ($newnick =~ m/$bad_nicks/i) { my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg'); my $channels = $self->{pbot}->{nicklist}->get_channels($newnick); + foreach my $chan (@$channels) { next if not $self->{pbot}->{chanops}->can_gain_ops($chan); @@ -52,7 +62,14 @@ sub on_nickchange { sub on_action { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{args}[0], $event->{event}->{to}[0]); + + my ($nick, $user, $host, $msg, $channel) = ( + $event->nick, + $event->user, + $event->host, + $event->{args}[0], + $event->{to}[0], + ); return 0 if $channel !~ /^#/; return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel); @@ -61,6 +78,7 @@ sub on_action { return 0 if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted'); my $bad_actions = $self->{pbot}->{registry}->get_value('antiaway', 'bad_actions'); + if ($msg =~ m/$bad_actions/i) { $self->{pbot}->{logger}->log("$nick $msg matches bad away actions regex, kicking...\n"); my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg'); diff --git a/lib/PBot/Plugin/AntiKickAutoRejoin.pm b/lib/PBot/Plugin/AntiKickAutoRejoin.pm index d801c0a2..75c98f34 100644 --- a/lib/PBot/Plugin/AntiKickAutoRejoin.pm +++ b/lib/PBot/Plugin/AntiKickAutoRejoin.pm @@ -31,12 +31,12 @@ sub unload { sub on_kick { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); - my ($target, $channel, $reason) = ($event->{event}->to, $event->{event}->{args}[0], $event->{event}->{args}[1]); + my ($nick, $user, $host) = ($event->nick, $event->user, $event->host); + my ($target, $channel, $reason) = ($event->to, $event->{args}[0], $event->{args}[1]); $channel = lc $channel; return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel); - return 0 if $reason eq '*BANG!*'; # roulette + return 0 if $reason eq '*BANG!*'; # roulette if (not exists $self->{kicks}->{$channel} or not exists $self->{kicks}->{$channel}->{$target}) { $self->{kicks}->{$channel}->{$target}->{rejoins} = 0; @@ -48,10 +48,11 @@ sub on_kick { sub on_join { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); $channel = lc $channel; return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel); + my $u = $self->{pbot}->{users}->loggedin($channel, "$nick!$user\@$host"); return 0 if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted'); diff --git a/lib/PBot/Plugin/AntiNickSpam.pm b/lib/PBot/Plugin/AntiNickSpam.pm index fead37b1..93c193d4 100644 --- a/lib/PBot/Plugin/AntiNickSpam.pm +++ b/lib/PBot/Plugin/AntiNickSpam.pm @@ -29,8 +29,8 @@ sub unload { sub on_action { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = $event->{event}->{to}[0]; + my ($nick, $user, $host, $msg) = ($event->nick, $event->user, $event->host, $event->args); + my $channel = $event->{to}[0]; return 0 if $event->{interpreted}; $self->check_flood($nick, $user, $host, $channel, $msg); return 0; @@ -38,8 +38,8 @@ sub on_action { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = $event->{event}->{to}[0]; + my ($nick, $user, $host, $msg) = ($event->nick, $event->user, $event->host, $event->args); + my $channel = $event->{to}[0]; return 0 if $event->{interpreted}; $self->check_flood($nick, $user, $host, $channel, $msg); return 0; diff --git a/lib/PBot/Plugin/AntiRepeat.pm b/lib/PBot/Plugin/AntiRepeat.pm index 0c49919d..9b2b1c9c 100644 --- a/lib/PBot/Plugin/AntiRepeat.pm +++ b/lib/PBot/Plugin/AntiRepeat.pm @@ -36,8 +36,15 @@ sub unload { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = lc $event->{event}->{to}[0]; + + my ($nick, $user, $host, $msg) = ( + $event->nick, + $event->user, + $event->host, + $event->args, + ); + + my $channel = lc $event->{to}[0]; ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); diff --git a/lib/PBot/Plugin/AntiTwitter.pm b/lib/PBot/Plugin/AntiTwitter.pm index dabaed9c..1705f5aa 100644 --- a/lib/PBot/Plugin/AntiTwitter.pm +++ b/lib/PBot/Plugin/AntiTwitter.pm @@ -28,9 +28,10 @@ sub unload { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{to}[0], $event->{event}->args); + my ($nick, $user, $host, $channel, $msg) = ($event->nick, $event->user, $event->host, $event->{to}[0], $event->args); return 0 if $event->{interpreted}; + $channel = lc $channel; return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel); diff --git a/lib/PBot/Plugin/AutoRejoin.pm b/lib/PBot/Plugin/AutoRejoin.pm index 87d1d7ed..98984ce1 100644 --- a/lib/PBot/Plugin/AutoRejoin.pm +++ b/lib/PBot/Plugin/AutoRejoin.pm @@ -49,12 +49,12 @@ sub on_kick { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $target, $channel, $reason) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, - $event->{event}->{args}[0], - $event->{event}->{args}[1], + $event->nick, + $event->user, + $event->host, + $event->to, + $event->{args}[0], + $event->{args}[1], ); return 0 if not $self->{pbot}->{channels}->is_active($channel); @@ -71,10 +71,10 @@ sub on_part { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host, - $event->{event}->to, + $event->nick, + $event->user, + $event->host, + $event->to, ); return 0 if not $self->{pbot}->{channels}->is_active($channel); diff --git a/lib/PBot/Plugin/Connect4.pm b/lib/PBot/Plugin/Connect4.pm index 2c0d9dfa..9cd4623e 100644 --- a/lib/PBot/Plugin/Connect4.pm +++ b/lib/PBot/Plugin/Connect4.pm @@ -12,11 +12,14 @@ use parent 'PBot::Plugin::Base'; use PBot::Imports; use Time::Duration qw/concise duration/; -use Data::Dumper; use List::Util qw[min max]; + +use Data::Dumper; $Data::Dumper::Useqq = 1; $Data::Dumper::Sortkeys = 1; +# This plugin was contributed by mannito, based on an earlier version of Battleship.pm + sub initialize { my ($self, %conf) = @_; @@ -46,9 +49,9 @@ sub unload { sub on_kick { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); - my ($victim, $reason) = ($event->{event}->to, $event->{event}->{args}[1]); - my $channel = $event->{event}->{args}[0]; + my ($nick, $user, $host) = ($event->nick, $event->user, $event->host); + my ($victim, $reason) = ($event->to, $event->{args}[1]); + my $channel = $event->{args}[0]; return 0 if lc $channel ne $self->{channel}; $self->player_left($nick, $user, $host); return 0; @@ -56,8 +59,8 @@ sub on_kick { sub on_departure { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); - my $type = uc $event->{event}->type; + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); + my $type = uc $event->type; return 0 if $type ne 'QUIT' and lc $channel ne $self->{channel}; $self->player_left($nick, $user, $host); return 0; diff --git a/lib/PBot/Plugin/Counter.pm b/lib/PBot/Plugin/Counter.pm index 82e2788d..2d79fa65 100644 --- a/lib/PBot/Plugin/Counter.pm +++ b/lib/PBot/Plugin/Counter.pm @@ -487,8 +487,8 @@ sub cmd_countertrigger { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = $event->{event}->{to}[0]; + my ($nick, $user, $host, $msg) = ($event->nick, $event->user, $event->host, $event->args); + my $channel = $event->{to}[0]; return 0 if $event->{interpreted}; diff --git a/lib/PBot/Plugin/Example.pm b/lib/PBot/Plugin/Example.pm index f433cbe7..980c190c 100644 --- a/lib/PBot/Plugin/Example.pm +++ b/lib/PBot/Plugin/Example.pm @@ -12,7 +12,10 @@ use PBot::Imports; sub initialize { my ($self, %conf) = @_; - $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler( + 'irc.public', + sub { $self->on_public(@_) }, + ); } sub unload { @@ -24,15 +27,21 @@ sub unload { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); + + my ($nick, $user, $host, $msg) = ( + $event->nick, + $event->user, + $event->host, + $event->args, + ); if ($event->{interpreted}) { $self->{pbot}->{logger}->log("Message was already handled by the interpreter.\n"); - return 0; + return 0; # event not handled by plugin } $self->{pbot}->{logger}->log("Example plugin: got message from $nick!$user\@$host: $msg\n"); - return 0; + return 1; # event handled by plugin } 1; diff --git a/lib/PBot/Plugin/RelayUnreg.pm b/lib/PBot/Plugin/RelayUnreg.pm index 663386d6..599854b5 100644 --- a/lib/PBot/Plugin/RelayUnreg.pm +++ b/lib/PBot/Plugin/RelayUnreg.pm @@ -32,8 +32,8 @@ sub unload { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = lc $event->{event}->{to}[0]; + my ($nick, $user, $host, $msg) = ($event->nick, $event->user, $event->host, $event->args); + my $channel = lc $event->{to}[0]; $msg =~ s/^\s+|\s+$//g; return 0 if not length $msg; @@ -56,17 +56,8 @@ sub on_public { return 0 if defined $nickserv && length $nickserv; my @filters = ( - qr{https://bryanostergaard.com/}, - qr{https://encyclopediadramatica.rs/Freenodegate}, - qr{https://MattSTrout.com/}, - qr{Contact me on twitter}, - qr{At the beginning there was only Chaos}, - qr{https://williampitcock.com/}, - qr{Achievement Method}, - qr{perceived death signal}, - qr{efnet}, - qr{https://evestigatorsucks.com}, - qr{eVestigator}, + # qr{list of filters}, + # qr{etc}, ); # don't notify/relay for spammers diff --git a/lib/PBot/Plugin/Spinach.pm b/lib/PBot/Plugin/Spinach.pm index a294fdb6..cff9598d 100644 --- a/lib/PBot/Plugin/Spinach.pm +++ b/lib/PBot/Plugin/Spinach.pm @@ -84,9 +84,9 @@ sub unload { sub on_kick { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); - my ($victim, $reason) = ($event->{event}->to, $event->{event}->{args}[1]); - my $channel = $event->{event}->{args}[0]; + my ($nick, $user, $host) = ($event->nick, $event->user, $event->host); + my ($victim, $reason) = ($event->to, $event->{args}[1]); + my $channel = $event->{args}[0]; return 0 if lc $channel ne $self->{channel}; $self->player_left($nick, $user, $host); return 0; @@ -94,8 +94,8 @@ sub on_kick { sub on_departure { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to); - my $type = uc $event->{event}->type; + my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to); + my $type = uc $event->type; return 0 if $type ne 'QUIT' and lc $channel ne $self->{channel}; $self->player_left($nick, $user, $host); return 0; diff --git a/lib/PBot/Plugin/TypoSub.pm b/lib/PBot/Plugin/TypoSub.pm index 109af311..6e9dfc17 100644 --- a/lib/PBot/Plugin/TypoSub.pm +++ b/lib/PBot/Plugin/TypoSub.pm @@ -34,12 +34,15 @@ sub unload { sub on_public { my ($self, $event_type, $event) = @_; - my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); - my $channel = lc $event->{event}->{to}[0]; + + my ($nick, $user, $host, $msg) = ($event->nick, $event->user, $event->host, $event->args); + + my $channel = lc $event->{to}[0]; ($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host); return 0 if $self->{pbot}->{ignorelist}->is_ignored($channel, "$nick!$user\@$host"); + my $nosubs = $self->{pbot}->{registry}->get_value($channel, 'notyposub'); return 0 if defined $nosubs and $nosubs; diff --git a/lib/PBot/Plugin/UrlTitles.pm b/lib/PBot/Plugin/UrlTitles.pm index 85905270..36fed5da 100644 --- a/lib/PBot/Plugin/UrlTitles.pm +++ b/lib/PBot/Plugin/UrlTitles.pm @@ -52,6 +52,9 @@ sub unload { sub is_ignored_url { my ($self, $url) = @_; + return 1 if $url =~ m{https://asciinema.org}i; + return 1 if $url =~ m{https?://tpcg.io/}i; + return 1 if $url =~ m/bootlin.com/i; return 1 if $url =~ m{https?://matrix\.to}i; return 1 if $url =~ m{https?://.*\.c$}i; return 1 if $url =~ m{https?://.*\.h$}i; @@ -67,6 +70,8 @@ sub is_ignored_url { return 1 if $url =~ m{127}i; return 1 if $url =~ m{192.168}i; return 1 if $url =~ m{file://}i; + return 1 if $url =~ m{/src/}i; + return 1 if $url =~ m{/trunk/}i; return 1 if $url =~ m{\.\.}i; return 1 if $url =~ m{https?://www.irccloud.com/pastebin}i; return 1 if $url =~ m{http://smuj.ca/cl}i; @@ -258,14 +263,14 @@ sub show_url_titles { my ($self, $event_type, $event) = @_; my ($nick, $user, $host) = ( - $event->{event}->nick, - $event->{event}->user, - $event->{event}->host + $event->nick, + $event->user, + $event->host ); my ($channel, $msg) = ( - $event->{event}->{to}[0], - $event->{event}->{args}[0] + $event->{to}[0], + $event->{args}[0] ); # get show_url_titles for channel or true if not defined diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 47e6c8ca..f11584eb 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4609, - BUILD_DATE => "2023-01-30", + BUILD_REVISION => 4610, + BUILD_DATE => "2023-01-31", }; sub initialize {}