mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-16 21:40:46 +01:00
Plugin/ActionTrigger: handle QUIT triggers per-channel
This commit is contained in:
parent
58ac29c4db
commit
d4cc3bf7f2
@ -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;
|
$cap = lc $cap;
|
||||||
|
|
||||||
if (not defined $subcap) {
|
if (not defined $subcap) {
|
||||||
|
@ -313,14 +313,7 @@ sub delete_trigger($self, $channel, $trigger) {
|
|||||||
sub list_triggers($self, $channel) {
|
sub list_triggers($self, $channel) {
|
||||||
my $triggers = eval {
|
my $triggers = eval {
|
||||||
my $sth;
|
my $sth;
|
||||||
|
$sth = $self->{dbh}->prepare('SELECT * FROM Triggers WHERE channel = ?');
|
||||||
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->execute(lc $channel);
|
$sth->execute(lc $channel);
|
||||||
return $sth->fetchall_arrayref({});
|
return $sth->fetchall_arrayref({});
|
||||||
};
|
};
|
||||||
@ -456,8 +449,20 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
|
|||||||
$channel = lc $channel;
|
$channel = lc $channel;
|
||||||
|
|
||||||
# TODO: cache these instead of loading them again every message
|
# TODO: cache these instead of loading them again every message
|
||||||
my @triggers = $self->list_triggers($channel);
|
my @triggers;
|
||||||
my @globals = $self->list_triggers('global');
|
|
||||||
|
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;
|
push @triggers, @globals;
|
||||||
|
|
||||||
$text = "$nick!$user\@$host $text";
|
$text = "$nick!$user\@$host $text";
|
||||||
@ -479,13 +484,12 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
|
|||||||
my $i;
|
my $i;
|
||||||
map { ++$i; $action =~ s/\$$i/$_/g; } @stuff;
|
map { ++$i; $action =~ s/\$$i/$_/g; } @stuff;
|
||||||
|
|
||||||
my ($n, $u, $h) = $trigger->{owner} =~ /^([^!]+)!([^@]+)\@(.*)$/;
|
|
||||||
|
|
||||||
my $command = {
|
my $command = {
|
||||||
nick => $n,
|
nick => $nick,
|
||||||
user => $u,
|
user => $user,
|
||||||
host => $h,
|
host => $host,
|
||||||
hostmask => "$n!$u\@$host",
|
hostmask => "$nick!$user\@$host",
|
||||||
command => $action,
|
command => $action,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -493,11 +497,19 @@ sub check_trigger($self, $nick, $user, $host, $channel, $text) {
|
|||||||
$command->{'cap-override'} = $trigger->{cap_override};
|
$command->{'cap-override'} = $trigger->{cap_override};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $target_channel;
|
||||||
|
|
||||||
|
if ($trigger->{channel} eq 'global') {
|
||||||
|
$target_channel = $channel;
|
||||||
|
} else {
|
||||||
|
$target_channel = $trigger->{channel};
|
||||||
|
}
|
||||||
|
|
||||||
my $cap = '';
|
my $cap = '';
|
||||||
$cap = " (capability=$command->{'cap-override'})" if exists $command->{'cap-override'};
|
$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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ 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 => 4680,
|
BUILD_REVISION => 4681,
|
||||||
BUILD_DATE => "2023-06-13",
|
BUILD_DATE => "2023-07-19",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user