3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 03:49:29 +01:00

Plugin/ActionTrigger: handle QUIT triggers per-channel

This commit is contained in:
Pragmatic Software 2023-07-19 00:23:54 -07:00
parent 58ac29c4db
commit d4cc3bf7f2
3 changed files with 32 additions and 20 deletions

View File

@ -98,7 +98,7 @@ sub add($self, $cap, $subcap, $dontsave = 0) {
}
}
sub remove($self, $cap, $subcap) {
sub remove($self, $cap, $subcap = undef) {
$cap = lc $cap;
if (not defined $subcap) {

View File

@ -313,14 +313,7 @@ sub delete_trigger($self, $channel, $trigger) {
sub list_triggers($self, $channel) {
my $triggers = eval {
my $sth;
if ($channel eq '*') {
$channel = 'global';
$sth = $self->{dbh}->prepare('SELECT * FROM Triggers WHERE channel != ?');
} else {
$sth = $self->{dbh}->prepare('SELECT * FROM Triggers WHERE channel = ?');
}
$sth = $self->{dbh}->prepare('SELECT * FROM Triggers WHERE channel = ?');
$sth->execute(lc $channel);
return $sth->fetchall_arrayref({});
};
@ -456,8 +449,20 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
$channel = lc $channel;
# TODO: cache these instead of loading them again every message
my @triggers = $self->list_triggers($channel);
my @globals = $self->list_triggers('global');
my @triggers;
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');
push @triggers, @globals;
$text = "$nick!$user\@$host $text";
@ -479,13 +484,12 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
my $i;
map { ++$i; $action =~ s/\$$i/$_/g; } @stuff;
my ($n, $u, $h) = $trigger->{owner} =~ /^([^!]+)!([^@]+)\@(.*)$/;
my $command = {
nick => $n,
user => $u,
host => $h,
hostmask => "$n!$u\@$host",
nick => $nick,
user => $user,
host => $host,
hostmask => "$nick!$user\@$host",
command => $action,
};
@ -493,11 +497,19 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
$command->{'cap-override'} = $trigger->{cap_override};
}
my $target_channel;
if ($trigger->{channel} eq 'global') {
$target_channel = $channel;
} else {
$target_channel = $trigger->{channel};
}
my $cap = '';
$cap = " (capability=$command->{'cap-override'})" if exists $command->{'cap-override'};
$self->{pbot}->{logger}->log("ActionTrigger: ($channel) $trigger->{trigger} -> $action$cap\n");
$self->{pbot}->{logger}->log("ActionTrigger: ($target_channel) $trigger->{trigger} -> $action$cap\n");
$self->{pbot}->{interpreter}->add_to_command_queue($channel, $command);
$self->{pbot}->{interpreter}->add_to_command_queue($target_channel, $command);
}
};

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4680,
BUILD_DATE => "2023-06-13",
BUILD_REVISION => 4681,
BUILD_DATE => "2023-07-19",
};
sub initialize {}