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

Plugins: use Plugin parent class

This commit is contained in:
Pragmatic Software 2020-02-08 19:48:05 -08:00
parent e58044f2f1
commit 59af6e944d
25 changed files with 98 additions and 353 deletions

View File

@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::ActionTrigger; package Plugins::ActionTrigger;
use parent 'Plugins::Plugin';
# purpose: provides interface to set/remove/modify regular expression triggers # purpose: provides interface to set/remove/modify regular expression triggers
# to execute a command. # to execute a command.
@ -26,31 +27,18 @@ package Plugins::ActionTrigger;
# #
# These are basic examples; more complex examples can be crafted. # These are basic examples; more complex examples can be crafted.
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use Carp ();
use DBI; use DBI;
use Time::Duration qw/duration/; use Time::Duration qw/duration/;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->actiontrigger(@_) }, 'actiontrigger', 1); $self->{pbot}->{commands}->register(sub { $self->actiontrigger(@_) }, 'actiontrigger', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-actiontrigger', 1); $self->{pbot}->{capabilities}->add('admin', 'can-actiontrigger', 1);

View File

@ -8,26 +8,13 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiAway; package Plugins::AntiAway;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_nicks', $conf{bad_nicks} // '([[:punct:]](afk|brb|bbl|away|sleep|z+|work|gone|study|out|home|busy|off)[[:punct:]]*$|.+\[.*\]$)'); $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_nicks', $conf{bad_nicks} // '([[:punct:]](afk|brb|bbl|away|sleep|z+|work|gone|study|out|home|busy|off)[[:punct:]]*$|.+\[.*\]$)');
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me (is (away|gone)|.*auto.?away)'); $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me (is (away|gone)|.*auto.?away)');
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'kick_msg', 'http://sackheads.org/~bnaylor/spew/away_msgs.html'); $self->{pbot}->{registry}->add_default('text', 'antiaway', 'kick_msg', 'http://sackheads.org/~bnaylor/spew/away_msgs.html');

View File

@ -8,28 +8,16 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiKickAutoRejoin; package Plugins::AntiKickAutoRejoin;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use Time::Duration; use Time::Duration;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('array', 'antikickautorejoin', 'punishment', '300,900,1800,3600,28800'); $self->{pbot}->{registry}->add_default('array', 'antikickautorejoin', 'punishment', '300,900,1800,3600,28800');
$self->{pbot}->{registry}->add_default('text', 'antikickautorejoin', 'threshold', '4'); $self->{pbot}->{registry}->add_default('text', 'antikickautorejoin', 'threshold', '4');

View File

@ -9,27 +9,16 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiNickSpam; package Plugins::AntiNickSpam;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::Duration qw/duration/; use Time::Duration qw/duration/;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) });
$self->{nicks} = {}; $self->{nicks} = {};
@ -61,7 +50,6 @@ sub on_public {
sub check_flood { sub check_flood {
my ($self, $nick, $user, $host, $channel, $msg) = @_; my ($self, $nick, $user, $host, $channel, $msg) = @_;
return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel); return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel);
$channel = lc $channel; $channel = lc $channel;
@ -86,9 +74,7 @@ sub check_flood {
sub clear_old_nicks { sub clear_old_nicks {
my ($self, $channel) = @_; my ($self, $channel) = @_;
my $now = gettimeofday; my $now = gettimeofday;
return if not exists $self->{nicks}->{$channel}; return if not exists $self->{nicks}->{$channel};
while (1) { while (1) {

View File

@ -3,33 +3,20 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiRepeat; package Plugins::AntiRepeat;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict; use feature 'unicode_strings';
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings';
use Carp ();
use String::LCSS qw/lcss/; use String::LCSS qw/lcss/;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use POSIX qw/strftime/; use POSIX qw/strftime/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat', $conf{antirepeat} // 1); $self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat', $conf{antirepeat} // 1);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat_threshold', $conf{antirepeat_threshold} // 2.5); $self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat_threshold', $conf{antirepeat_threshold} // 2.5);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat_match', $conf{antirepeat_match} // 0.5); $self->{pbot}->{registry}->add_default('text', 'antiflood', 'antirepeat_match', $conf{antirepeat_match} // 0.5);

View File

@ -9,30 +9,19 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiTwitter; package Plugins::AntiTwitter;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use Time::Duration qw/duration/; use Time::Duration qw/duration/;
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
$self->{pbot}->{timer}->register(sub { $self->adjust_offenses }, 60 * 60 * 1, 'antitwitter'); $self->{pbot}->{timer}->register(sub { $self->adjust_offenses }, 60 * 60 * 1, 'antitwitter');
$self->{offenses} = {}; $self->{offenses} = {};

View File

@ -8,30 +8,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AutoRejoin; package Plugins::AutoRejoin;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use Time::Duration; use Time::Duration;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('array', 'autorejoin', 'rejoin_delay', '900,1800,3600'); $self->{pbot}->{registry}->add_default('array', 'autorejoin', 'rejoin_delay', '900,1800,3600');
$self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_part(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_part(@_) });
$self->{rejoins} = {}; $self->{rejoins} = {};

View File

@ -3,34 +3,22 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Battleship; package Plugins::Battleship;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict; use feature 'unicode_strings';
use utf8;
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings';
use utf8;
use Carp ();
use Time::Duration qw/concise duration/; use Time::Duration qw/concise duration/;
use Data::Dumper; use Data::Dumper;
$Data::Dumper::Useqq = 1; $Data::Dumper::Useqq = 1;
$Data::Dumper::Sortkeys = 1; $Data::Dumper::Sortkeys = 1;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->battleship_cmd(@_) }, 'battleship', 0); $self->{pbot}->{commands}->register(sub { $self->battleship_cmd(@_) }, 'battleship', 0);
$self->{pbot}->{timer}->register(sub { $self->battleship_timer }, 1, 'battleship timer'); $self->{pbot}->{timer}->register(sub { $self->battleship_timer }, 1, 'battleship timer');

View File

@ -3,34 +3,22 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Connect4; package Plugins::Connect4;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict; use feature 'unicode_strings';
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings';
use Carp ();
use Time::Duration qw/concise duration/; use Time::Duration qw/concise duration/;
use Data::Dumper; use Data::Dumper;
use List::Util qw[min max]; use List::Util qw[min max];
$Data::Dumper::Useqq = 1; $Data::Dumper::Useqq = 1;
$Data::Dumper::Sortkeys = 1; $Data::Dumper::Sortkeys = 1;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot};
$self->{pbot}->{commands}->register(sub { $self->connect4_cmd(@_) }, 'connect4', 0); $self->{pbot}->{commands}->register(sub { $self->connect4_cmd(@_) }, 'connect4', 0);
$self->{pbot}->{timer}->register(sub { $self->connect4_timer }, 1, 'connect4 timer'); $self->{pbot}->{timer}->register(sub { $self->connect4_timer }, 1, 'connect4 timer');

View File

@ -3,32 +3,20 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Counter; package Plugins::Counter;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict; use feature 'unicode_strings';
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings';
use Carp ();
use DBI; use DBI;
use Time::Duration qw/duration/; use Time::Duration qw/duration/;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->counteradd(@_) }, 'counteradd', 0); $self->{pbot}->{commands}->register(sub { $self->counteradd(@_) }, 'counteradd', 0);
$self->{pbot}->{commands}->register(sub { $self->counterdel(@_) }, 'counterdel', 0); $self->{pbot}->{commands}->register(sub { $self->counterdel(@_) }, 'counterdel', 0);
$self->{pbot}->{commands}->register(sub { $self->counterreset(@_) }, 'counterreset', 0); $self->{pbot}->{commands}->register(sub { $self->counterreset(@_) }, 'counterreset', 0);

View File

@ -8,26 +8,16 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Date; package Plugins::Date;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Getopt::Long qw(GetOptionsFromString); use Getopt::Long qw(GetOptionsFromString);
use Carp (); Getopt::Long::Configure("bundling");
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('text', 'date', 'default_timezone', 'UTC'); $self->{pbot}->{registry}->add_default('text', 'date', 'default_timezone', 'UTC');
$self->{pbot}->{commands}->register(sub { $self->datecmd(@_) }, "date", 0); $self->{pbot}->{commands}->register(sub { $self->datecmd(@_) }, "date", 0);
} }
@ -39,10 +29,7 @@ sub unload {
sub datecmd { sub datecmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $usage = "date [-u <user account>] [timezone]"; my $usage = "date [-u <user account>] [timezone]";
Getopt::Long::Configure("bundling");
my $getopt_error; my $getopt_error;
local $SIG{__WARN__} = sub { local $SIG{__WARN__} = sub {
$getopt_error = shift; $getopt_error = shift;

View File

@ -3,24 +3,13 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Example; package Plugins::Example;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
} }

View File

@ -5,29 +5,16 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::GoogleSearch; package Plugins::GoogleSearch;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use WWW::Google::CustomSearch; use WWW::Google::CustomSearch;
use HTML::Entities; use HTML::Entities;
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$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', '');
@ -44,16 +31,10 @@ sub unload {
sub googlesearch { sub googlesearch {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return "Usage: google [number of results] query\n" if not length $arguments;
if (not length $arguments) {
return "Usage: google [number of results] query\n";
}
my $matches = 1; my $matches = 1;
$matches = $1 if $arguments =~ s/^-n\s+([0-9]+)\s*//;
if ($arguments =~ s/^([0-9]+)//) {
$matches = $1;
}
my $api_key = $self->{pbot}->{registry}->get_value('googlesearch', 'api_key'); # https://developers.google.com/custom-search/v1/overview my $api_key = $self->{pbot}->{registry}->get_value('googlesearch', 'api_key'); # https://developers.google.com/custom-search/v1/overview
my $cx = $self->{pbot}->{registry}->get_value('googlesearch', 'context'); # https://cse.google.com/all my $cx = $self->{pbot}->{registry}->get_value('googlesearch', 'context'); # https://cse.google.com/all

View File

@ -8,24 +8,13 @@
# command). # command).
package Plugins::MagicCommand; package Plugins::MagicCommand;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { return $self->magic(@_)}, "mc", 90); $self->{pbot}->{commands}->register(sub { return $self->magic(@_)}, "mc", 90);
} }

View File

@ -5,26 +5,15 @@
# Just a quick interface to test/play with PBot::Utils::ParseDate # Just a quick interface to test/play with PBot::Utils::ParseDate
package Plugins::ParseDate; package Plugins::ParseDate;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::Duration qw/duration/; use Time::Duration qw/duration/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { return $self->pd(@_)}, "pd", 0); $self->{pbot}->{commands}->register(sub { return $self->pd(@_)}, "pd", 0);
} }

39
Plugins/Plugin.pm Normal file
View File

@ -0,0 +1,39 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Plugin;
# purpose: base class for PBot plugins
use warnings; use strict;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
if (not exists $conf{pbot}) {
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing pbot reference to " . $class . ", created by $subroutine at $filename:$line");
}
$self->{pbot} = $conf{pbot};
$self->initialize(%conf);
return $self;
}
sub initialize {
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing initialize subroutine in $subroutine at $filename:$line");
}
sub unload {
my ($package, $filename, $line) = caller(0);
my (undef, undef, undef, $subroutine) = caller(1);
Carp::croak("Missing unload subroutine in $subroutine at $filename:$line");
}
1;

View File

@ -8,10 +8,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Quotegrabs; package Plugins::Quotegrabs;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use HTML::Entities; use HTML::Entities;
@ -25,17 +24,8 @@ use PBot::Utils::ValidateString;
use POSIX qw(strftime); use POSIX qw(strftime);
sub new {
Carp::croak("Options to Quotegrabs should be key/value pairs, not hash reference") if ref($_[1]) eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference in Quotegrabs");
$self->{filename} = $conf{quotegrabs_file} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/quotegrabs.sqlite3'; $self->{filename} = $conf{quotegrabs_file} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/quotegrabs.sqlite3';
$self->{database} = Plugins::Quotegrabs::Quotegrabs_SQLite->new(pbot => $self->{pbot}, filename => $self->{filename}); $self->{database} = Plugins::Quotegrabs::Quotegrabs_SQLite->new(pbot => $self->{pbot}, filename => $self->{filename});

View File

@ -1,26 +1,14 @@
package Plugins::RelayUnreg; package Plugins::RelayUnreg;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
$self->{queue} = []; $self->{queue} = [];
$self->{notified} = {}; $self->{notified} = {};

View File

@ -3,34 +3,22 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::RemindMe; package Plugins::RemindMe;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use Carp ();
use DBI; use DBI;
use Time::Duration qw/concise duration/; use Time::Duration qw/concise duration/;
use Time::HiRes qw/gettimeofday/; use Time::HiRes qw/gettimeofday/;
use Getopt::Long qw(GetOptionsFromString); use Getopt::Long qw(GetOptionsFromString);
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->remindme(@_) }, 'remindme', 0); $self->{pbot}->{commands}->register(sub { $self->remindme(@_) }, 'remindme', 0);
$self->{filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/reminders.sqlite3'; $self->{filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/reminders.sqlite3';
$self->{pbot}->{timer}->register(sub { $self->check_reminders(@_) }, 1, 'RemindMe'); $self->{pbot}->{timer}->register(sub { $self->check_reminders(@_) }, 1, 'RemindMe');

View File

@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::RestrictedMod; package Plugins::RestrictedMod;
use parent 'Plugins::Plugin';
# purpose: provides restricted moderation abilities to voiced users. # purpose: provides restricted moderation abilities to voiced users.
# They are allowed to ban/mute/kick only users that are not admins, # They are allowed to ban/mute/kick only users that are not admins,
@ -10,25 +11,13 @@ package Plugins::RestrictedMod;
# configurations where +v users are recognized as "semi-trusted" in # configurations where +v users are recognized as "semi-trusted" in
# order to provide assistance in combating heavy spam and drone traffic. # order to provide assistance in combating heavy spam and drone traffic.
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use Storable qw/dclone/; use Storable qw/dclone/;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->modcmd(@_) }, 'mod', 0); $self->{pbot}->{commands}->register(sub { $self->modcmd(@_) }, 'mod', 0);
$self->{pbot}->{commands}->set_meta('mod', 'help', 'Provides restricted moderation abilities to voiced users. They can kick/ban/etc only users that are not admins, whitelisted, voiced or opped.'); $self->{pbot}->{commands}->set_meta('mod', 'help', 'Provides restricted moderation abilities to voiced users. They can kick/ban/etc only users that are not admins, whitelisted, voiced or opped.');

View File

@ -3,19 +3,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Spinach; package Plugins::Spinach;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use FindBin; use FindBin;
use lib "$FindBin::RealBin/../.."; use lib "$FindBin::RealBin/../..";
use feature 'switch'; use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
use JSON; use JSON;
use Lingua::EN::Fractions qw/fraction2words/; use Lingua::EN::Fractions qw/fraction2words/;
@ -38,18 +36,8 @@ use PBot::HashObject;
use Plugins::Spinach::Stats; use Plugins::Spinach::Stats;
use Plugins::Spinach::Rank; use Plugins::Spinach::Rank;
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->spinach_cmd(@_) }, 'spinach', 0); $self->{pbot}->{commands}->register(sub { $self->spinach_cmd(@_) }, 'spinach', 0);
$self->{pbot}->{timer}->register(sub { $self->spinach_timer }, 1, 'spinach timer'); $self->{pbot}->{timer}->register(sub { $self->spinach_timer }, 1, 'spinach timer');

View File

@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::TypoSub; package Plugins::TypoSub;
use parent 'Plugins::Plugin';
# purpose: Replaces "typos" with "corrections". # purpose: Replaces "typos" with "corrections".
# #
@ -16,23 +17,11 @@ package Plugins::TypoSub;
# <alice> s/like/love/ # <alice> s/like/love/
# <PBot> alice meant to say: i love candy # <PBot> alice meant to say: i love candy
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_public(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_public(@_) });
} }

View File

@ -8,26 +8,14 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::UrlTitles; package Plugins::UrlTitles;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Carp ();
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{registry}->add_default('text', 'general', 'show_url_titles', $conf{show_url_titles} // 1); $self->{pbot}->{registry}->add_default('text', 'general', 'show_url_titles', $conf{show_url_titles} // 1);
$self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_channels', $conf{show_url_titles_channels} // '.*'); $self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_channels', $conf{show_url_titles_channels} // '.*');
$self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_ignore_channels', $conf{show_url_titles_ignore_channels} // 'none'); $self->{pbot}->{registry}->add_default('array', 'general', 'show_url_titles_ignore_channels', $conf{show_url_titles_ignore_channels} // 'none');

View File

@ -8,28 +8,18 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Weather; package Plugins::Weather;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use PBot::Utils::LWPUserAgentCached; use PBot::Utils::LWPUserAgentCached;
use XML::LibXML; use XML::LibXML;
use Getopt::Long qw(GetOptionsFromString); use Getopt::Long qw(GetOptionsFromString);
use Carp (); Getopt::Long::Configure("bundling");
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->weathercmd(@_) }, "weather", 0); $self->{pbot}->{commands}->register(sub { $self->weathercmd(@_) }, "weather", 0);
} }
@ -40,10 +30,7 @@ sub unload {
sub weathercmd { sub weathercmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $usage = "Usage: weather [-u <user account>] [location]"; my $usage = "Usage: weather [-u <user account>] [location]";
Getopt::Long::Configure("bundling");
my $getopt_error; my $getopt_error;
local $SIG{__WARN__} = sub { local $SIG{__WARN__} = sub {
$getopt_error = shift; $getopt_error = shift;

View File

@ -8,10 +8,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Wttr; package Plugins::Wttr;
use parent 'Plugins::Plugin';
use warnings; use warnings; use strict;
use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use utf8; use utf8;
@ -20,21 +19,12 @@ no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Utils::LWPUserAgentCached; use PBot::Utils::LWPUserAgentCached;
use JSON; use JSON;
use Getopt::Long qw(GetOptionsFromString);
use URI::Escape qw/uri_escape_utf8/; use URI::Escape qw/uri_escape_utf8/;
use Carp (); use Getopt::Long qw(GetOptionsFromString);
Getopt::Long::Configure("bundling_override", "ignorecase_always");
sub new {
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
return $self;
}
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot}->{commands}->register(sub { $self->wttrcmd(@_) }, "wttr", 0); $self->{pbot}->{commands}->register(sub { $self->wttrcmd(@_) }, "wttr", 0);
} }
@ -67,8 +57,6 @@ sub wttrcmd {
); );
my $usage = "Usage: wttr [-u <user account>] [location] [" . join(' ', map { "-$_" } @wttr_options) . "]"; my $usage = "Usage: wttr [-u <user account>] [location] [" . join(' ', map { "-$_" } @wttr_options) . "]";
Getopt::Long::Configure("bundling_override", "ignorecase_always");
my $getopt_error; my $getopt_error;
local $SIG{__WARN__} = sub { local $SIG{__WARN__} = sub {
$getopt_error = shift; $getopt_error = shift;