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

Plugins/RemindMe: fix -c option

This commit is contained in:
Pragmatic Software 2021-06-23 20:21:08 -07:00
parent 7dbfd03c10
commit 8ea3fab219

View File

@ -15,7 +15,7 @@ use PBot::Imports;
use DBI; use DBI;
use Time::Duration qw/concise duration/; use Time::Duration qw/concise duration/;
use Time::HiRes qw/time/; use Time::HiRes qw/time/;
use Getopt::Long qw(GetOptionsFromArray); use Getopt::Long qw/GetOptionsFromArray/;
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
@ -194,7 +194,7 @@ sub cmd_remindme {
my $admininfo = $self->{pbot}->{users}->loggedin_admin($channel ? $channel : $context->{from}, $context->{hostmask}); my $admininfo = $self->{pbot}->{users}->loggedin_admin($channel ? $channel : $context->{from}, $context->{hostmask});
# option -c was provided; ensure user is an admin and bot is in targeted channel # option -c was provided; ensure user is an admin and bot is in channel
if ($channel) { if ($channel) {
if (not defined $admininfo) { if (not defined $admininfo) {
return "Only admins can create channel reminders."; return "Only admins can create channel reminders.";
@ -272,14 +272,9 @@ sub do_reminder {
return; return;
} }
# nick of person being reminded # ensures we get the current nick of the person being reminded
my $nick;
# ensure person is available to receive reminder
if (not defined $reminder->{target}) {
# ensures we get the current nick of the person
my $hostmask = $self->{pbot}->{messagehistory}->{database}->find_most_recent_hostmask($reminder->{account}); my $hostmask = $self->{pbot}->{messagehistory}->{database}->find_most_recent_hostmask($reminder->{account});
($nick) = $hostmask =~ /^([^!]+)!/; my ($nick) = $hostmask =~ /^([^!]+)!/;
# try again in 30 seconds if the person isn't around yet # try again in 30 seconds if the person isn't around yet
if (not $self->{pbot}->{nicklist}->is_present_any_channel($nick)) { if (not $self->{pbot}->{nicklist}->is_present_any_channel($nick)) {
@ -287,10 +282,9 @@ sub do_reminder {
$event->{repeating} = 1; $event->{repeating} = 1;
return; return;
} }
}
# send reminder text to person # send reminder text to person
my $target = $reminder->{target} // $nick; my $target = $reminder->{channel} // $nick;
my $text = $reminder->{text}; my $text = $reminder->{text};
# if sending reminder to channel, highlight person being reminded # if sending reminder to channel, highlight person being reminded
@ -298,10 +292,10 @@ sub do_reminder {
$text = "$nick: $text"; $text = "$nick: $text";
} }
$self->{pbot}->{conn}->privmsg($target, $reminder->{text}); $self->{pbot}->{conn}->privmsg($target, $text);
# log event # log event
$self->{pbot}->{logger}->log("Reminded $target about \"$reminder->{text}\"\n"); $self->{pbot}->{logger}->log("Reminded $target about \"$text\"\n");
# update repeats or delete reminder # update repeats or delete reminder
if ($reminder->{repeats} > 0) { if ($reminder->{repeats} > 0) {
@ -371,7 +365,7 @@ sub create_database {
CREATE TABLE IF NOT EXISTS Reminders ( CREATE TABLE IF NOT EXISTS Reminders (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
account TEXT, account TEXT,
target TEXT, channel TEXT,
text TEXT, text TEXT,
alarm NUMERIC, alarm NUMERIC,
repeats INTEGER, repeats INTEGER,
@ -413,11 +407,11 @@ sub add_reminder {
my ($self, %args) = @_; my ($self, %args) = @_;
my $id = eval { my $id = eval {
my $sth = $self->{dbh}->prepare('INSERT INTO Reminders (account, target, text, alarm, interval, repeats, created_on, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'); my $sth = $self->{dbh}->prepare('INSERT INTO Reminders (account, channel, text, alarm, interval, repeats, created_on, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$sth->execute( $sth->execute(
$args{account}, $args{account},
$args{target}, $args{channel},
$args{text}, $args{text},
$args{alarm}, $args{alarm},
$args{interval}, $args{interval},