From 0fb4cd7fa7dce2037f5f5f36cb1209d45d3e3329 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 4 Sep 2025 10:29:29 -0700 Subject: [PATCH] Plugin/ActionTrigger: enable triggering on bot messages --- lib/PBot/Plugin/ActionTrigger.pm | 49 +++++++++++++++++++++++--------- lib/PBot/VERSION.pm | 2 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/PBot/Plugin/ActionTrigger.pm b/lib/PBot/Plugin/ActionTrigger.pm index a31d884a..aea534e9 100644 --- a/lib/PBot/Plugin/ActionTrigger.pm +++ b/lib/PBot/Plugin/ActionTrigger.pm @@ -56,12 +56,14 @@ sub initialize($self, %conf) { $self->{pbot}->{capabilities}->add('admin', 'can-actiontrigger', 1); # register IRC handlers - $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); - $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) }); - $self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) }); - $self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure(@_) }); - $self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_departure(@_) }); - $self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_departure(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('pbot.public', sub { $self->on_pbotpublic(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('pbot.caction', sub { $self->on_pbotaction(@_) }); # database file $self->{filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/triggers.sqlite3'; @@ -88,6 +90,8 @@ sub unload($self) { $self->{pbot}->{event_dispatcher}->remove_handler('irc.part'); $self->{pbot}->{event_dispatcher}->remove_handler('irc.quit'); $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick'); + $self->{pbot}->{event_dispatcher}->remove_handler('pbot.public'); + $self->{pbot}->{event_dispatcher}->remove_handler('pbot.caction'); } sub cmd_actiontrigger($self, $context) { @@ -386,6 +390,32 @@ sub on_kick($self, $event_type, $event) { return 0; } +sub on_pbotaction($self, $event_type, $event) { + my ($nick, $user, $host, $channel, $msg) = ( + $self->{pbot}->{conn}->nick, + 'pbot3', + 'pbot', + $event->{to}, + $event->{msg} + ); + + $self->check_trigger($nick, $user, $host, $channel, "ACTION $msg"); + return 0; +} + +sub on_pbotpublic($self, $event_type, $event) { + my ($nick, $user, $host, $channel, $msg) = ( + $self->{pbot}->{conn}->nick, + 'pbot3', + 'pbot', + $event->{to}, + $event->{msg} + ); + + $self->check_trigger($nick, $user, $host, $channel, "PRIVMSG $msg"); + return 0; +} + sub on_action($self, $event_type, $event) { # don't handle this event if it was processed by a bot command return 0 if $event->{interpreted}; @@ -459,13 +489,6 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) { if ($channel =~ /^#/) { @triggers = $self->list_triggers($channel); - } else { - my $channels = $self->{pbot}->{nicklist}->get_channels($nick); - - foreach my $c (@$channels) { - next if not $self->{pbot}->{channels}->is_active($c); - push @triggers, $self->list_triggers($c); - } } my @globals = $self->list_triggers('global'); diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 3e34c5a8..e13009c1 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 => 4887, + BUILD_REVISION => 4888, BUILD_DATE => "2025-09-04", };