# 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 PBot::Plugin::RemindMe; use parent 'PBot::Plugin::Base'; use PBot::Imports; use DBI; use Time::Duration qw(ago concise duration); use Time::HiRes qw(time); sub initialize { my ($self, %conf) = @_; # register `remindme` bot command $self->{pbot}->{commands}->add( name => 'remindme', help => 'Manage personal reminder notifications', subref => sub { $self->cmd_remindme(@_) }, ); # 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}->remove('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