mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 15:29:32 +01:00
Update plugins to use subroutine signatures
This commit is contained in:
parent
cd60ac9fc7
commit
c6db4b1e6b
@ -10,8 +10,7 @@ use parent 'PBot::Plugin::Base';
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
sub initialize {
|
sub initialize($self, %conf) {
|
||||||
my ($self, %conf) = @_;
|
|
||||||
$self->{pbot}->{functions}->register(
|
$self->{pbot}->{functions}->register(
|
||||||
'plural',
|
'plural',
|
||||||
{
|
{
|
||||||
@ -22,14 +21,11 @@ sub initialize {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unload {
|
sub unload($self) {
|
||||||
my $self = shift;
|
|
||||||
$self->{pbot}->{functions}->unregister('plural');
|
$self->{pbot}->{functions}->unregister('plural');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub pluralize_word {
|
sub pluralize_word($word) {
|
||||||
my ($word) = @_;
|
|
||||||
|
|
||||||
my @ignore = qw/trout fish tobacco music snow armor police dice caribou moose people sheep/;
|
my @ignore = qw/trout fish tobacco music snow armor police dice caribou moose people sheep/;
|
||||||
|
|
||||||
my %endings = (
|
my %endings = (
|
||||||
@ -83,9 +79,7 @@ sub pluralize_word {
|
|||||||
return $word;
|
return $word;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub pluralize {
|
sub pluralize($string) {
|
||||||
my ($string) = @_;
|
|
||||||
|
|
||||||
if ($string =~ m/(.*?) (containing|packed with|with what appears to be) (.*)/) {
|
if ($string =~ m/(.*?) (containing|packed with|with what appears to be) (.*)/) {
|
||||||
my $word = pluralize_word $1;
|
my $word = pluralize_word $1;
|
||||||
return "$word $2 $3";
|
return "$word $2 $3";
|
||||||
@ -97,10 +91,8 @@ sub pluralize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub func_plural {
|
sub func_plural($self, @text) {
|
||||||
my $self = shift @_;
|
return pluralize("@text");
|
||||||
my $text = "@_";
|
|
||||||
return pluralize($text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -14,8 +14,7 @@ use PBot::Imports;
|
|||||||
use WWW::Google::CustomSearch;
|
use WWW::Google::CustomSearch;
|
||||||
use HTML::Entities;
|
use HTML::Entities;
|
||||||
|
|
||||||
sub initialize {
|
sub initialize($self, %conf) {
|
||||||
my ($self, %conf) = @_;
|
|
||||||
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'api_key', '');
|
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'api_key', '');
|
||||||
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'context', '');
|
$self->{pbot}->{registry}->add_default('text', 'googlesearch', 'context', '');
|
||||||
|
|
||||||
@ -29,13 +28,11 @@ sub initialize {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unload {
|
sub unload($self) {
|
||||||
my ($self) = @_;
|
|
||||||
$self->{pbot}->{commands}->remove('google');
|
$self->{pbot}->{commands}->remove('google');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cmd_googlesearch {
|
sub cmd_googlesearch($self, $context) {
|
||||||
my ($self, $context) = @_;
|
|
||||||
return "Usage: google [-n <number of results>] query\n" if not length $context->{arguments};
|
return "Usage: google [-n <number of results>] query\n" if not length $context->{arguments};
|
||||||
|
|
||||||
my $matches = 3;
|
my $matches = 3;
|
||||||
|
@ -15,9 +15,7 @@ use DBI;
|
|||||||
use Time::Duration qw(ago concise duration);
|
use Time::Duration qw(ago concise duration);
|
||||||
use Time::HiRes qw(time);
|
use Time::HiRes qw(time);
|
||||||
|
|
||||||
sub initialize {
|
sub initialize($self, %conf) {
|
||||||
my ($self, %conf) = @_;
|
|
||||||
|
|
||||||
# register `remindme` bot command
|
# register `remindme` bot command
|
||||||
$self->{pbot}->{commands}->add(
|
$self->{pbot}->{commands}->add(
|
||||||
name => 'remindme',
|
name => 'remindme',
|
||||||
@ -38,9 +36,7 @@ sub initialize {
|
|||||||
$self->enqueue_reminders;
|
$self->enqueue_reminders;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unload {
|
sub unload($self) {
|
||||||
my ($self) = @_;
|
|
||||||
|
|
||||||
# close database
|
# close database
|
||||||
$self->dbi_end;
|
$self->dbi_end;
|
||||||
|
|
||||||
@ -52,9 +48,7 @@ sub unload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# `remindme` bot command
|
# `remindme` bot command
|
||||||
sub cmd_remindme {
|
sub cmd_remindme($self, $context) {
|
||||||
my ($self, $context) = @_;
|
|
||||||
|
|
||||||
if (not $self->{dbh}) {
|
if (not $self->{dbh}) {
|
||||||
return "Internal error.";
|
return "Internal error.";
|
||||||
}
|
}
|
||||||
@ -272,9 +266,7 @@ sub cmd_remindme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# invoked whenever a reminder event is ready
|
# invoked whenever a reminder event is ready
|
||||||
sub do_reminder {
|
sub do_reminder($self, $id, $event) {
|
||||||
my ($self, $id, $event) = @_;
|
|
||||||
|
|
||||||
my $reminder = $self->get_reminder($id);
|
my $reminder = $self->get_reminder($id);
|
||||||
|
|
||||||
if (not defined $reminder) {
|
if (not defined $reminder) {
|
||||||
@ -359,9 +351,7 @@ sub do_reminder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# add a single reminder to the PBot event queue
|
# add a single reminder to the PBot event queue
|
||||||
sub enqueue_reminder {
|
sub enqueue_reminder($self, $reminder, $timeout) {
|
||||||
my ($self, $reminder, $timeout) = @_;
|
|
||||||
|
|
||||||
$self->{pbot}->{event_queue}->enqueue_event(
|
$self->{pbot}->{event_queue}->enqueue_event(
|
||||||
sub {
|
sub {
|
||||||
my ($event) = @_;
|
my ($event) = @_;
|
||||||
@ -373,9 +363,7 @@ sub enqueue_reminder {
|
|||||||
|
|
||||||
# load all reminders from SQLite database and add them
|
# load all reminders from SQLite database and add them
|
||||||
# to PBot's event queue. typically used once at PBot start-up.
|
# to PBot's event queue. typically used once at PBot start-up.
|
||||||
sub enqueue_reminders {
|
sub enqueue_reminders($self) {
|
||||||
my ($self) = @_;
|
|
||||||
|
|
||||||
return if not $self->{dbh};
|
return if not $self->{dbh};
|
||||||
|
|
||||||
my $reminders = eval {
|
my $reminders = eval {
|
||||||
@ -403,9 +391,7 @@ sub enqueue_reminders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub create_database {
|
sub create_database($self) {
|
||||||
my ($self) = @_;
|
|
||||||
|
|
||||||
return if not $self->{dbh};
|
return if not $self->{dbh};
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
@ -427,8 +413,7 @@ SQL
|
|||||||
$self->{pbot}->{logger}->log("RemindMe: create database failed: $@") if $@;
|
$self->{pbot}->{logger}->log("RemindMe: create database failed: $@") if $@;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dbi_begin {
|
sub dbi_begin($self) {
|
||||||
my ($self) = @_;
|
|
||||||
eval {
|
eval {
|
||||||
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", {RaiseError => 1, PrintError => 0, AutoInactiveDestroy => 1, sqlite_unicode => 1})
|
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", {RaiseError => 1, PrintError => 0, AutoInactiveDestroy => 1, sqlite_unicode => 1})
|
||||||
or die $DBI::errstr;
|
or die $DBI::errstr;
|
||||||
@ -443,17 +428,14 @@ sub dbi_begin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dbi_end {
|
sub dbi_end($self) {
|
||||||
my ($self) = @_;
|
|
||||||
return if not $self->{dbh};
|
return if not $self->{dbh};
|
||||||
$self->{dbh}->disconnect;
|
$self->{dbh}->disconnect;
|
||||||
delete $self->{dbh};
|
delete $self->{dbh};
|
||||||
}
|
}
|
||||||
|
|
||||||
# add a reminder, to SQLite and the PBot event queue
|
# add a reminder, to SQLite and the PBot event queue
|
||||||
sub add_reminder {
|
sub add_reminder($self, %args) {
|
||||||
my ($self, %args) = @_;
|
|
||||||
|
|
||||||
# add reminder to SQLite database
|
# add reminder to SQLite database
|
||||||
my $id = eval {
|
my $id = eval {
|
||||||
my $sth = $self->{dbh}->prepare('INSERT INTO Reminders (account, channel, 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 (?, ?, ?, ?, ?, ?, ?, ?)');
|
||||||
@ -491,9 +473,7 @@ sub add_reminder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# delete a reminder by its id, from SQLite and the PBot event queue
|
# delete a reminder by its id, from SQLite and the PBot event queue
|
||||||
sub delete_reminder {
|
sub delete_reminder($self, $id, $dont_dequeue) {
|
||||||
my ($self, $id, $dont_dequeue) = @_;
|
|
||||||
|
|
||||||
return if not $self->{dbh};
|
return if not $self->{dbh};
|
||||||
|
|
||||||
# remove from SQLite database
|
# remove from SQLite database
|
||||||
@ -518,9 +498,7 @@ sub delete_reminder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# update a reminder's data, in SQLite
|
# update a reminder's data, in SQLite
|
||||||
sub update_reminder {
|
sub update_reminder($self, $id, $data) {
|
||||||
my ($self, $id, $data) = @_;
|
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $sql = 'UPDATE Reminders SET ';
|
my $sql = 'UPDATE Reminders SET ';
|
||||||
|
|
||||||
@ -549,9 +527,7 @@ sub update_reminder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# get a single reminder by its id, from SQLite
|
# get a single reminder by its id, from SQLite
|
||||||
sub get_reminder {
|
sub get_reminder($self, $id) {
|
||||||
my ($self, $id) = @_;
|
|
||||||
|
|
||||||
my $reminder = eval {
|
my $reminder = eval {
|
||||||
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE id = ?');
|
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE id = ?');
|
||||||
$sth->execute($id);
|
$sth->execute($id);
|
||||||
@ -567,9 +543,7 @@ sub get_reminder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# get all reminders belonging to an account id, from SQLite
|
# get all reminders belonging to an account id, from SQLite
|
||||||
sub get_reminders {
|
sub get_reminders($self, $account) {
|
||||||
my ($self, $account) = @_;
|
|
||||||
|
|
||||||
my $reminders = eval {
|
my $reminders = eval {
|
||||||
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE account = ? ORDER BY id');
|
my $sth = $self->{dbh}->prepare('SELECT * FROM Reminders WHERE account = ? ORDER BY id');
|
||||||
$sth->execute($account);
|
$sth->execute($account);
|
||||||
|
@ -25,7 +25,7 @@ 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 => 4646,
|
BUILD_REVISION => 4647,
|
||||||
BUILD_DATE => "2023-04-13",
|
BUILD_DATE => "2023-04-13",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user