# File: RemindMe.pm # # Purpose: Users can use `remindme` to set up reminders. Reminders are # sent to the user (or to a channel, if option -c is used). # SPDX-FileCopyrightText: 2021 Pragmatic Software # SPDX-License-Identifier: MIT package Plugins::RemindMe; use parent 'Plugins::Plugin'; use PBot::Imports; use DBI; use Time::Duration qw/ago concise duration/; use Time::HiRes qw/time/; use Getopt::Long qw/GetOptionsFromArray/; sub initialize { my ($self, %conf) = @_; # register `remindme` bot command $self->{pbot}->{commands}->register(sub { $self->cmd_remindme(@_) }, 'remindme', 0); # set location of sqlite database $self->{filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/reminders.sqlite3'; # open the database $self->dbi_begin; # create tables, etc $self->create_database; # add saved reminders to event queue $self->enqueue_reminders; } sub unload { my ($self) = @_; # close database $self->dbi_end; # unregister `remindme` command $self->{pbot}->{commands}->unregister('remindme'); # remove all reminder events from event queue $self->{pbot}->{event_queue}->dequeue_event('reminder .*'); } # `remindme` bot command sub cmd_remindme { my ($self, $context) = @_; if (not $self->{dbh}) { return "Internal error."; } my $usage = "Usage: remindme -t