3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 03:02:47 +01:00

Update plugins to use subroutine signatures

This commit is contained in:
Pragmatic Software 2023-04-13 17:08:27 -07:00
parent cd60ac9fc7
commit c6db4b1e6b
4 changed files with 24 additions and 61 deletions

View File

@ -10,8 +10,7 @@ use parent 'PBot::Plugin::Base';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;
sub initialize($self, %conf) {
$self->{pbot}->{functions}->register(
'plural',
{
@ -22,14 +21,11 @@ sub initialize {
);
}
sub unload {
my $self = shift;
sub unload($self) {
$self->{pbot}->{functions}->unregister('plural');
}
sub pluralize_word {
my ($word) = @_;
sub pluralize_word($word) {
my @ignore = qw/trout fish tobacco music snow armor police dice caribou moose people sheep/;
my %endings = (
@ -83,9 +79,7 @@ sub pluralize_word {
return $word;
}
sub pluralize {
my ($string) = @_;
sub pluralize($string) {
if ($string =~ m/(.*?) (containing|packed with|with what appears to be) (.*)/) {
my $word = pluralize_word $1;
return "$word $2 $3";
@ -97,10 +91,8 @@ sub pluralize {
}
}
sub func_plural {
my $self = shift @_;
my $text = "@_";
return pluralize($text);
sub func_plural($self, @text) {
return pluralize("@text");
}
1;

View File

@ -14,8 +14,7 @@ use PBot::Imports;
use WWW::Google::CustomSearch;
use HTML::Entities;
sub initialize {
my ($self, %conf) = @_;
sub initialize($self, %conf) {
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'api_key', '');
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'context', '');
@ -29,13 +28,11 @@ sub initialize {
);
}
sub unload {
my ($self) = @_;
sub unload($self) {
$self->{pbot}->{commands}->remove('google');
}
sub cmd_googlesearch {
my ($self, $context) = @_;
sub cmd_googlesearch($self, $context) {
return "Usage: google [-n <number of results>] query\n" if not length $context->{arguments};
my $matches = 3;

View File

@ -15,9 +15,7 @@ use DBI;
use Time::Duration qw(ago concise duration);
use Time::HiRes qw(time);
sub initialize {
my ($self, %conf) = @_;
sub initialize($self, %conf) {
# register `remindme` bot command
$self->{pbot}->{commands}->add(
name => 'remindme',
@ -38,9 +36,7 @@ sub initialize {
$self->enqueue_reminders;
}
sub unload {
my ($self) = @_;
sub unload($self) {
# close database
$self->dbi_end;
@ -52,9 +48,7 @@ sub unload {
}
# `remindme` bot command
sub cmd_remindme {
my ($self, $context) = @_;
sub cmd_remindme($self, $context) {
if (not $self->{dbh}) {
return "Internal error.";
}
@ -272,9 +266,7 @@ sub cmd_remindme {
}
# invoked whenever a reminder event is ready
sub do_reminder {
my ($self, $id, $event) = @_;
sub do_reminder($self, $id, $event) {
my $reminder = $self->get_reminder($id);
if (not defined $reminder) {
@ -359,9 +351,7 @@ sub do_reminder {
}
# add a single reminder to the PBot event queue
sub enqueue_reminder {
my ($self, $reminder, $timeout) = @_;
sub enqueue_reminder($self, $reminder, $timeout) {
$self->{pbot}->{event_queue}->enqueue_event(
sub {
my ($event) = @_;
@ -373,9 +363,7 @@ sub enqueue_reminder {
# load all reminders from SQLite database and add them
# to PBot's event queue. typically used once at PBot start-up.
sub enqueue_reminders {
my ($self) = @_;
sub enqueue_reminders($self) {
return if not $self->{dbh};
my $reminders = eval {
@ -403,9 +391,7 @@ sub enqueue_reminders {
}
}
sub create_database {
my ($self) = @_;
sub create_database($self) {
return if not $self->{dbh};
eval {
@ -427,8 +413,7 @@ SQL
$self->{pbot}->{logger}->log("RemindMe: create database failed: $@") if $@;
}
sub dbi_begin {
my ($self) = @_;
sub dbi_begin($self) {
eval {
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", {RaiseError => 1, PrintError => 0, AutoInactiveDestroy => 1, sqlite_unicode => 1})
or die $DBI::errstr;
@ -443,17 +428,14 @@ sub dbi_begin {
}
}
sub dbi_end {
my ($self) = @_;
sub dbi_end($self) {
return if not $self->{dbh};
$self->{dbh}->disconnect;
delete $self->{dbh};
}
# add a reminder, to SQLite and the PBot event queue
sub add_reminder {
my ($self, %args) = @_;
sub add_reminder($self, %args) {
# add reminder to SQLite database
my $id = eval {
my $sth = $self->{dbh}->prepare('INSERT INTO Reminders (account, channel, text, alarm, interval, repeats, created_on, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
@ -491,9 +473,7 @@ sub add_reminder {
}
# delete a reminder by its id, from SQLite and the PBot event queue
sub delete_reminder {
my ($self, $id, $dont_dequeue) = @_;
sub delete_reminder($self, $id, $dont_dequeue) {
return if not $self->{dbh};
# remove from SQLite database
@ -518,9 +498,7 @@ sub delete_reminder {
}
# update a reminder's data, in SQLite
sub update_reminder {
my ($self, $id, $data) = @_;
sub update_reminder($self, $id, $data) {
eval {
my $sql = 'UPDATE Reminders SET ';
@ -549,9 +527,7 @@ sub update_reminder {
}
# get a single reminder by its id, from SQLite
sub get_reminder {
my ($self, $id) = @_;
sub get_reminder($self, $id) {
my $reminder = eval {
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE id = ?');
$sth->execute($id);
@ -567,9 +543,7 @@ sub get_reminder {
}
# get all reminders belonging to an account id, from SQLite
sub get_reminders {
my ($self, $account) = @_;
sub get_reminders($self, $account) {
my $reminders = eval {
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE account = ? ORDER BY id');
$sth->execute($account);

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4646,
BUILD_REVISION => 4647,
BUILD_DATE => "2023-04-13",
};