Consolidate imports into PBot::Imports

This commit is contained in:
Pragmatic Software 2021-06-18 21:23:34 -07:00
parent 9b114006e0
commit 1c2b4da9ab
75 changed files with 363 additions and 514 deletions

View File

@ -1,5 +1,4 @@
# File: AntiFlood.pm
# Author: pragma_
#
# Purpose: Tracks message and nickserv statistics to enforce anti-flooding and
# ban-evasion detection.
@ -14,12 +13,7 @@
package PBot::AntiFlood;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use Time::HiRes qw(gettimeofday tv_interval);
use Time::Duration;

View File

@ -1,5 +1,4 @@
# File: AntiSpam.pm
# Author: pragma_
#
# Purpose: Checks if a message is spam
@ -10,12 +9,7 @@
package PBot::AntiSpam;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use Time::HiRes qw(gettimeofday);
use POSIX qw/strftime/;

View File

@ -1,5 +1,4 @@
# File: BanList.pm
# Author: pragma_
#
# Purpose: Populates and maintains channel banlists by checking mode +b/+q on
# joining channels and by tracking modes +b/+q and -b/-q in channels. Keeps
@ -13,17 +12,12 @@ package PBot::BanList;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;
use Time::Duration;
use Data::Dumper;
use POSIX qw/strftime/;
$Data::Dumper::Sortkeys = 1;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: BlackList.pm
# Author: pragma_
#
# Purpose: Manages list of hostmasks that are not allowed to join a channel.
@ -10,12 +9,7 @@
package PBot::BlackList;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use Time::HiRes qw(gettimeofday);

View File

@ -1,3 +1,7 @@
# File: Capabilites.pm
#
# Purpose: Fine-grained user permissions.
# 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/.
@ -5,16 +9,7 @@
package PBot::Capabilities;
use parent 'PBot::Class';
# purpose: provides interface to set/remove/modify/query user capabilities.
#
# Examples: See doc/Admin.md for examples.
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: ChanOpCommands.pm
# Author: pragma_
#
# Purpose: Channel operator command subroutines.
@ -8,12 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::ChanOpCommands;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration;
use Time::HiRes qw/gettimeofday/;

View File

@ -1,5 +1,4 @@
# File: ChanOps.pm
# Author: pragma_
#
# Purpose: Provides channel operator status tracking and commands.
@ -8,14 +7,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::ChanOps;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use PBot::ChanOpCommands;
use Time::HiRes qw(gettimeofday);
use Time::Duration qw(concise duration);

View File

@ -1,5 +1,4 @@
# File: Channels.pm
# Author: pragma_
#
# Purpose: Manages list of channels and auto-joins.
@ -10,9 +9,7 @@
package PBot::Channels;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,34 +1,33 @@
# File: Class.pm
#
# Purpose: Base class for PBot classes. This prevents each PBot class from
# needing to define the new() constructor and other boilerplate.
#
# 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 PBot::Class;
# purpose: base class for all PBot classes
#
# This prevents each PBot class from needing to define the new() subroutine
# and such boilerplate.
use warnings;
use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my ($class, %args) = @_;
my $self = bless {}, $class;
if (not exists $conf{pbot}) {
# ensure class was passed a PBot instance
if (not exists $args{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->{pbot} = $args{pbot};
$self->{pbot}->{logger}->log("Initializing $class\n");
$self->initialize(%conf);
$self->initialize(%args);
return $self;
}

View File

@ -1,7 +1,5 @@
# File: Commands.pm
#
# Author: pragma_
#
# Purpose: Registers commands. Invokes commands with user capability
# validation.
@ -12,9 +10,7 @@
package PBot::Commands;
use parent 'PBot::Class', 'PBot::Registerable';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration qw/duration/;

View File

@ -1,11 +1,11 @@
# File: DualIndexHashObject.pm
# Author: pragma_
#
# Purpose: Provides a hash-table object with an abstracted API that includes
# setting and deleting values, saving to and loading from files, etc. This
# extends the HashObject with an additional index key. Provides case-insensitive
# access to both index keys, while preserving original case when displaying the
# keys.
# setting and deleting values, saving to and loading from files, etc.
#
# DualIndexHashObject extends the HashObject with an additional index key.
# Provides case-insensitive access to both index keys, while preserving
# original case when displaying the keys.
#
# Data is stored in working memory for lightning fast performance. If you have
# a huge amount of data, consider DualIndexSQLiteObject instead.
@ -16,29 +16,26 @@
package PBot::DualIndexHashObject;
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Text::Levenshtein qw(fastdistance);
use JSON;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot};
$self->{pbot} = $conf{pbot};
$self->initialize(%conf);
my ($class, %args) = @_;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $args{pbot};
$self->{pbot} = delete $args{pbot};
$self->initialize(%args);
return $self;
}
sub initialize {
my ($self, %conf) = @_;
$self->{name} = $conf{name} // 'Dual Index hash object';
$self->{name} = $conf{name} // 'unnamed';
$self->{filename} = $conf{filename} // Carp::carp("Missing filename to DualIndexHashObject, will not be able to save to or load from file.");
$self->{save_queue_timeout} = $conf{save_queue_timeout} // 0;
$self->{hash} = {};
$self->{hash} = {};
}
sub load {

View File

@ -1,5 +1,4 @@
# File: DualIndexSQLiteObject.pm
# Author: pragma_
#
# Purpose: Provides a dual-indexed SQLite object with an abstracted API that includes
# setting and deleting values, caching, displaying nearest matches, etc. Designed to
@ -11,20 +10,17 @@
package PBot::DualIndexSQLiteObject;
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use DBI;
use Text::Levenshtein qw(fastdistance);
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot};
$self->{pbot} = $conf{pbot};
$self->initialize(%conf);
my ($class, %args) = @_;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $args{pbot};
$self->{pbot} = delete $args{pbot};
$self->initialize(%args);
return $self;
}

View File

@ -1,3 +1,7 @@
# File: EventDispatcher.pm
#
# Purpose: Registers event handlers and dispatches events to them.
# 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/.
@ -5,11 +9,7 @@
package PBot::EventDispatcher;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use IO::Select;
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: FactoidCommands.pm
# Author: pragma_
#
# Purpose: Factoid command subroutines.
@ -8,12 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::FactoidCommands;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration;
use Time::HiRes qw(gettimeofday);

View File

@ -1,7 +1,6 @@
# File: Factoids.pm
# Author: pragma_
#
# Purpose: Provides functionality for factoids and a type of external module execution.
# Purpose: Provides functionality for factoids.
# 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
@ -10,12 +9,7 @@
package PBot::Factoids;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use HTML::Entities;
use Time::HiRes qw(gettimeofday);

View File

@ -1,6 +1,4 @@
# File: Functions.pm
# Author: pragma_
#
# Purpose: Special `func` command that executes built-in functions with
# optional arguments. Usage: func <identifier> [arguments].
@ -22,9 +20,7 @@
package PBot::Functions;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: HashObject.pm
# Author: pragma_
#
# Purpose: Provides a hash-table object with an abstracted API that includes
# setting and deleting values, saving to and loading from files, etc. Provides
@ -12,38 +11,39 @@
package PBot::HashObject;
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Text::Levenshtein qw(fastdistance);
use JSON;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my ($class, %args) = @_;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot};
$self->{pbot} = $conf{pbot};
$self->initialize(%conf);
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $args{pbot};
$self->{pbot} = delete $args{pbot};
$self->initialize(%args);
return $self;
}
sub initialize {
my ($self, %conf) = @_;
$self->{name} = $conf{name} // 'hash object';
$self->{filename} = $conf{filename} // Carp::carp("Missing filename to HashObject, will not be able to save to or load from file.");
$self->{name} = $conf{name} // 'unnammed';
$self->{hash} = {};
$self->{filename} = $conf{filename};
if (not defined $self->{filename}) {
Carp::carp("Missing filename for $self->{name} HashObject, will not be able to save to or load from file.");
}
}
sub load {
my $self = shift;
my $filename;
if (@_) { $filename = shift; }
else { $filename = $self->{filename}; }
my ($self, $filename) = @_;
$self->clear;
# allow overriding $self->{filename} with $filename parameter
$filename //= $self->{filename};
# no filename? nothing to load
if (not defined $filename) {
Carp::carp "No $self->{name} filename specified -- skipping loading from file";
return;
@ -56,37 +56,55 @@ sub load {
return;
}
# slurp file into $contents
my $contents = do {
local $/;
<FILE>;
};
$self->{hash} = decode_json $contents;
close FILE;
# update existing entries to use _name to preserve case
# and lowercase any non-lowercased entries
foreach my $index (keys %{$self->{hash}}) {
if (not exists $self->{hash}->{$index}->{_name}) {
if ($index ne lc $index) {
if (exists $self->{hash}->{lc $index}) {
Carp::croak "Cannot update $self->{name} object $index; duplicate object found";
}
eval {
# first try to deocde json, throws exception on misparse/errors
my $newhash = decode_json $contents;
my $data = delete $self->{hash}->{$index};
$data->{_name} = $index;
$self->{hash}->{lc $index} = $data;
# clear current hash only if decode succeeded
$self->clear;
# update internal hash
$self->{hash} = $newhash;
# update existing entries to use _name to preserve typographical casing
# e.g., when someone edits a config file by hand, they might add an
# entry with uppercase characters in its name.
foreach my $index (keys %{$self->{hash}}) {
if (not exists $self->{hash}->{$index}->{_name}) {
if ($index ne lc $index) {
if (exists $self->{hash}->{lc $index}) {
Carp::croak "Cannot update $self->{name} object $index; duplicate object found";
}
my $data = delete $self->{hash}->{$index};
$data->{_name} = $index; # _name is original typographical case
$self->{hash}->{lc $index} = $data; # index key is lowercased
}
}
}
};
if ($@) {
# json parse error or such
$self->{pbot}->{logger}->log("Warning: failed to load $filename: $@\n");
}
}
sub save {
my $self = shift;
my $filename;
if (@_) { $filename = shift; }
else { $filename = $self->{filename}; }
my ($self, $filename) = @_;
# allow parameter overriding internal field
$filename //= $self->{filename};
# no filename? nothing to save
if (not defined $filename) {
Carp::carp "No $self->{name} filename specified -- skipping saving to file.\n";
return;
@ -94,42 +112,53 @@ sub save {
$self->{pbot}->{logger}->log("Saving $self->{name} to $filename\n");
# add update_version to metadata
if (not $self->get_data('$metadata$', 'update_version')) {
$self->add('$metadata$', { update_version => PBot::VERSION::BUILD_REVISION });
}
# ensure `name` metadata is current
$self->set('$metadata$', 'name', $self->{name}, 1);
# encode hash as JSON
my $json = JSON->new;
my $json_text = $json->pretty->canonical->utf8->encode($self->{hash});
# print JSON to file
open(FILE, "> $filename") or die "Couldn't open $filename: $!\n";
print FILE "$json_text\n";
close(FILE);
}
sub clear {
my $self = shift;
my ($self) = @_;
$self->{hash} = {};
}
sub levenshtein_matches {
my ($self, $keyword) = @_;
my $comma = '';
my $result = "";
my @matches;
foreach my $index (sort keys %{$self->{hash}}) {
my $distance = fastdistance($keyword, $index);
my $length = (length $keyword > length $index) ? length $keyword : length $index;
my $length_a = length $keyword;
my $length_b = length $index;
my $length = $length_a > $length_b ? $length_a : $length_b;
if ($length != 0 && $distance / $length < 0.50) {
$result .= $comma . $index;
$comma = ", ";
push @matches, $index;
}
}
return 'none' if not @matches;
my $result = join ', ', @matches;
# "a, b, c, d" -> "a, b, c or d"
$result =~ s/(.*), /$1 or /;
$result = "none" if $comma eq '';
return $result;
}
@ -137,29 +166,41 @@ sub set {
my ($self, $index, $key, $value, $dont_save) = @_;
my $lc_index = lc $index;
# find similarly named keys
if (not exists $self->{hash}->{$lc_index}) {
my $result = "$self->{name}: $index not found; similiar matches: ";
my $result = "$self->{name}: $index not found; similar matches: ";
$result .= $self->levenshtein_matches($index);
return $result;
}
if (not defined $key) {
# if no key provided, then list all keys and values
my $result = "[$self->{name}] " . $self->get_key_name($lc_index) . " keys: ";
my $comma = '';
foreach my $k (sort grep { $_ ne '_name' } keys %{$self->{hash}->{$lc_index}}) {
$result .= $comma . "$k: " . $self->{hash}->{$lc_index}->{$k};
$comma = ";\n";
my @entries;
foreach my $key (sort grep { $_ ne '_name' } keys %{$self->{hash}->{$lc_index}}) {
push @entries, "$key: $self->{hash}->{$lc_index}->{$key}";
}
$result .= "none" if ($comma eq '');
if (@entries) {
$result .= join ";\n", @entries;
} else {
$result .= 'none';
}
return $result;
}
if (not defined $value) {
# if no value provided, then show this key's value
$value = $self->{hash}->{$lc_index}->{$key};
} else {
# otherwise update the value belonging to key
$self->{hash}->{$lc_index}->{$key} = $value;
$self->save unless $dont_save;
}
return "[$self->{name}] " . $self->get_key_name($lc_index) . ": $key " . (defined $value ? "set to $value" : "is not set.");
}
@ -168,7 +209,7 @@ sub unset {
my $lc_index = lc $index;
if (not exists $self->{hash}->{$lc_index}) {
my $result = "$self->{name}: $index not found; similiar matches: ";
my $result = "$self->{name}: $index not found; similar matches: ";
$result .= $self->levenshtein_matches($index);
return $result;
}
@ -227,7 +268,7 @@ sub remove {
my $lc_index = lc $index;
if (not exists $self->{hash}->{$lc_index}) {
my $result = "$self->{name}: $index not found; similiar matches: ";
my $result = "$self->{name}: $index not found; similar matches: ";
$result .= $self->levenshtein_matches($lc_index);
return $result;
}

View File

@ -22,8 +22,7 @@ use PBot::IRC::EventQueue; # pragma_ 2011/01/21
use IO::Select;
use Carp;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
# grab the drop-in replacement for time() from Time::HiRes, if it's available
BEGIN { Time::HiRes->import('time') if eval "require Time::HiRes"; }

View File

@ -1,5 +1,4 @@
# File: IRCHandlers.pm
# Author: pragma_
#
# Purpose: Subroutines to handle IRC events
@ -8,12 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::IRCHandlers;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw(gettimeofday);
use Data::Dumper;

View File

@ -1,5 +1,4 @@
# File: IgnoreList.pm
# Author: pragma_
#
# Purpose: Manages ignore list.
@ -10,9 +9,7 @@
package PBot::IgnoreList;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration qw/concise duration/;

35
PBot/Imports.pm Normal file
View File

@ -0,0 +1,35 @@
# File: Imports.pm
#
# Purpose: Boilerplate imports for PBot packages.
# 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 PBot::Imports;
use Import::Into;
sub import {
my $target = caller;
# use strict
strict->import::into($target);
# use warnings
warnings->import::into($target);
# use feature ':5.16'
feature->import::into($target, ':5.16');
# use utf8
utf8->import::into($target);
# no if $] >= 5.018, warnings => 'experimental';
warnings->unimport::out_of($target, 'experimental') if $] >= 5.018
}
sub unimport {
}
1;

View File

@ -1,5 +1,4 @@
# File: Interpreter.pm
# Author: pragma_
#
# Purpose: Main entry point to parse and interpret a string into bot
# commands and dispatch the commands to registered interpreters.
@ -12,12 +11,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Interpreter;
use parent 'PBot::Class', 'PBot::Registerable';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;
use Time::Duration;

View File

@ -1,5 +1,4 @@
# File: LagChecker.pm
# Author: pragma_
#
# Purpose: sends PING command to IRC server and times duration for PONG reply in
# order to maintain lag history and average.
@ -9,12 +8,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::LagChecker;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw(gettimeofday tv_interval);
use Time::Duration;

View File

@ -1,25 +1,26 @@
# File: Logger.pm
#
# Purpose: Logs text to file and STDOUT.
# 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 PBot::Logger;
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Scalar::Util qw/openhandle/;
use File::Basename;
use File::Copy;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot};
$self->{pbot} = $conf{pbot};
my ($class, %args) = @_;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $args{pbot};
$self->{pbot} = delete $args{pbot};
print "Initializing " . __PACKAGE__ . "\n" unless $self->{pbot}->{overrides}->{'general.daemon'};
$self->initialize(%conf);
$self->initialize(%args);
return $self;
}

View File

@ -1,5 +1,4 @@
# File: MessageHistory.pm
# Author: pragma_
#
# Purpose: Keeps track of who has said what and when, as well as their
# nickserv accounts and alter-hostmasks.
@ -12,12 +11,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::MessageHistory;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Getopt::Long qw(GetOptionsFromArray);
use Time::HiRes qw(gettimeofday tv_interval);

View File

@ -1,19 +1,19 @@
# File: MessageHistory_SQLite.pm
# Author: pragma_
#
# Purpose: SQLite backend for storing/retreiving a user's message history
# Purpose: SQLite backend for storing/retreiving a user's message history.
# Peforms intelligent hostmask and nickserv heuristics to link nicknames
# in order to ensure message history is stored in the right user account
# ids. This is also extremely useful for detecting ban-evasions and listing
# also-known-as data for a nickname (see the !aka bot command).
# 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 PBot::MessageHistory_SQLite;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use DBI;
use Carp qw(shortmess);

View File

@ -1,8 +1,7 @@
# File: MiscCommands.pm
#
# Author: pragma_
#
# Purpose: Registers misc PBot commands.
# Purpose: Registers misc PBot commands that don't really belong in any
# other file.
# 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
@ -11,9 +10,7 @@
package PBot::MiscCommands;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration qw/duration/;

View File

@ -1,6 +1,5 @@
# File: Modules.pm
# Author: pragma_
#
# Purpose: Modules are command-line programs and scripts that can be loaded
# via PBot factoids. Command arguments are passed as command-line arguments.
# The standard output from the script is returned as the bot command result.
@ -12,12 +11,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Modules;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use IPC::Run qw/run timeout/;
use Encode;

View File

@ -1,5 +1,4 @@
# File: NickList.pm
# Author: pragma_
#
# Purpose: Maintains lists of nicks currently present in channels.
# Used to retrieve list of channels a nick is present in or to
@ -10,12 +9,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::NickList;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Text::Levenshtein qw/fastdistance/;
use Data::Dumper;

View File

@ -1,5 +1,4 @@
# File: PBot.pm
# Author: pragma_
#
# Purpose: IRC Bot
#
@ -22,9 +21,7 @@
package PBot::PBot;
use strict; use warnings;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Carp ();
use PBot::Logger;
@ -76,10 +73,9 @@ use Encode;
@ARGV = map { decode('UTF-8', $_, 1) } @ARGV;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
$self->initialize(%conf);
my ($class, %args) = @_;
my $self = bless {}, $class;
$self->initialize(%args);
return $self;
}

View File

@ -1,7 +1,6 @@
# File: Plugins.pm
# Author: pragma-
#
# Purpose: Loads and manages plugins.
# Purpose: Loads and manages external plugins.
# 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
@ -10,9 +9,7 @@
package PBot::Plugins;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use File::Basename;

View File

@ -1,19 +1,16 @@
# File: ProcessManager.pm
# Author: pragma_
#
# Purpose: Handles forking and execution of module/subroutine processes
# Purpose: Handles forking and execution of module/subroutine processes.
# Provides commands to list running processes and to kill them.
# 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 PBot::ProcessManager;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration qw/concise duration/;
use Time::HiRes qw/gettimeofday/;

View File

@ -1,5 +1,4 @@
# File: Refresher.pm
# Author: pragma_
#
# Purpose: Refreshes/reloads module subroutines. Does not refresh/reload
# module member data, only subroutines. TODO: reinitialize modules in order
@ -12,17 +11,17 @@
package PBot::Refresher;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Module::Refresh;
use File::Basename;
sub initialize {
my ($self, %conf) = @_;
$self->{refresher} = Module::Refresh->new;
$self->{pbot}->{commands}->register(sub { $self->cmd_refresh(@_) }, "refresh", 1);
$self->{refresher} = Module::Refresh->new;
}
sub cmd_refresh {

View File

@ -1,5 +1,4 @@
# File: Registerable.pm
# Author: pragma_
#
# Purpose: Provides functionality to register and execute one or more subroutines.
@ -9,17 +8,14 @@
package PBot::Registerable;
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my ($class, %args) = @_;
my $self = bless {}, $class;
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot};
$self->{pbot} = $conf{pbot};
$self->initialize(%conf);
Carp::croak("Missing pbot reference to " . __FILE__) unless exists $args{pbot};
$self->{pbot} = delete $args{pbot};
$self->initialize(%args);
return $self;
}

View File

@ -1,5 +1,4 @@
# File: Registry.pm
# Author: pragma_
#
# Purpose: Provides a centralized registry of configuration settings that can
# easily be examined and updated via getters and setters.
@ -9,12 +8,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Registry;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw(gettimeofday);
use PBot::RegistryCommands;

View File

@ -1,5 +1,4 @@
# File: RegistryCommands.pm
# Author: pragma_
#
# Purpose: Bot commands to manipulate Registry entries.
@ -10,9 +9,7 @@
package PBot::RegistryCommands;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: SQLiteLogger
# Author: pragma_
#
# Purpose: Logs SQLite trace messages to Logger.pm with profiling of elapsed
# time between messages.
@ -10,23 +9,25 @@
package PBot::SQLiteLogger;
use strict; use warnings;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw(gettimeofday);
sub new {
my ($class, %conf) = @_;
my $self = {};
$self->{buf} = '';
$self->{timestamp} = gettimeofday;
$self->{pbot} = $conf{pbot};
my ($class, %args) = @_;
my $self = {
pbot => $args{pbot},
buf => '',
timestamp => scalar gettimeofday,
};
return bless $self, $class;
}
sub log {
my $self = shift;
$self->{buf} .= shift;
# DBI feeds us pieces at a time, so accumulate a complete line
@ -38,17 +39,26 @@ sub log {
}
sub log_message {
my $self = shift;
my ($self) = @_;
my $now = gettimeofday;
my $elapsed = $now - $self->{timestamp};
# log SQL statements that take more than 100ms since the last log
if ($elapsed >= 0.100) { $self->{pbot}->{logger}->log("^^^ SLOW SQL ^^^\n"); }
# log SQL statement and elapsed duration since last statement
$elapsed = sprintf '%10.3f', $elapsed;
$self->{pbot}->{logger}->log("$elapsed : $self->{buf}");
# update timestamp
$self->{timestamp} = $now;
}
sub close {
my $self = shift;
my ($self) = @_;
# log anything left in buf when closing
if ($self->{buf}) {
$self->log_message;
$self->{buf} = '';

View File

@ -1,7 +1,6 @@
# File: SQLiteLoggerLayer
# Author: pragma_
#
# Purpose: PerlIO::via layer to log DBI trace messages
# Purpose: PerlIO::via layer to log DBI trace messages.
# 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
@ -9,11 +8,7 @@
package PBot::SQLiteLoggerLayer;
use strict;
use warnings;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub PUSHED {
my ($class, $mode, $fh) = @_;
@ -23,20 +18,18 @@ sub PUSHED {
sub OPEN {
my ($self, $path, $mode, $fh) = @_;
# $path is our logger object
$$self = $path;
$$self = $path; # path is our PBot::Logger object
return 1;
}
sub WRITE {
my ($self, $buf, $fh) = @_;
$$self->log($buf);
$$self->log($buf); # log message
return length($buf);
}
sub CLOSE {
my $self = shift;
my ($self) = @_;
$$self->close();
return 0;
}

View File

@ -1,3 +1,7 @@
# File: SelectHandler.pm
#
# Purpose: Invokes select() system call and handles its events.
# 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/.
@ -5,9 +9,7 @@
package PBot::SelectHandler;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use IO::Select;

View File

@ -1,3 +1,7 @@
# File: StdinReader.pm
#
# Purpose: Reads input from STDIN.
# 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/.
@ -5,9 +9,7 @@
package PBot::StdinReader;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use POSIX qw(tcgetpgrp getpgrp); # to check whether process is in background or foreground

View File

@ -1,5 +1,4 @@
# File: Timer.pm
# Author: pragma_
#
# Purpose: Provides functionality to register subroutines/events to be invoked
# at a future time, optionally recurring.
@ -19,9 +18,7 @@
package PBot::Timer;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::Duration qw/concise duration/;

View File

@ -1,7 +1,8 @@
# File: Updater.pm
# Author: pragma_
#
# Purpose: Updates data/configration files to new locations/formats based
# Purpose: Migrates data files from older versions to newer versions.
#
# Updates data/configration files to new locations/formats based
# on versioning information. Ensures data/configuration files are in the
# proper location and using the latest data structure.
@ -12,9 +13,7 @@
package PBot::Updater;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use File::Basename;

View File

@ -1,5 +1,4 @@
# File: Users.pm
# Author: pragma_
#
# Purpose: Manages list of bot users/admins and their metadata.
@ -10,9 +9,7 @@
package PBot::Users;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;
@ -28,11 +25,12 @@ sub initialize {
$self->{pbot}->{commands}->register(sub { $self->cmd_my(@_) }, "my", 0);
$self->{pbot}->{commands}->register(sub { $self->cmd_id(@_) }, "id", 0);
$self->{pbot}->{capabilities}->add('admin', 'can-useradd', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userdel', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userset', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userunset', 1);
$self->{pbot}->{capabilities}->add('can-modify-admins', undef, 1);
$self->{pbot}->{capabilities}->add('admin', 'can-useradd', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userdel', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userset', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-userunset', 1);
$self->{pbot}->{capabilities}->add('can-modify-admins', undef, 1);
$self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure(@_) });

View File

@ -1,8 +1,7 @@
# File: VERSION.pm
# Author: pragma_
#
# Purpose: Keeps track of bot version. Can compare current version against
# latest version on github or version.check_url site.
# latest version on github or URL in `version.check_url` registry entry.
# 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
@ -11,9 +10,7 @@
package PBot::VERSION;
use parent 'PBot::Class';
use strict; use warnings;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use LWP::UserAgent;

View File

@ -1,5 +1,4 @@
# File: WebPaste.pm
# Author: pragma_
#
# Purpose: Pastes text to a cycling list of web paste sites.
@ -8,12 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::WebPaste;
use parent 'PBot::Class';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;
use Time::Duration;

View File

@ -31,11 +31,7 @@ use parent 'Plugins::Plugin';
#
# TODO: share actually useful examples from personal bot
use warnings; use strict;
use feature 'unicode_strings';
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use DBI;
use Time::Duration qw/duration/;

View File

@ -1,5 +1,4 @@
# File: AntiAway.pm
# Author: pragma_
#
# Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes
@ -10,8 +9,7 @@
package Plugins::AntiAway;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: AntiKickAutoRejoin.pm
# Author: pragma_
#
# Purpose: Temporarily bans people who immediately auto-rejoin after a kick.
@ -8,11 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiKickAutoRejoin;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;
use Time::Duration;

View File

@ -1,5 +1,4 @@
# File: AntiNickSpam.pm
# Author: pragma_
#
# Purpose: Temporarily mutes $~a in channel if too many nicks were
# mentioned within a time period; used to combat botnet spam
@ -9,11 +8,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AntiNickSpam;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Time::Duration qw/duration/;
use Time::HiRes qw/gettimeofday/;

View File

@ -5,11 +5,7 @@
package Plugins::AntiRepeat;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use String::LCSS qw/lcss/;
use Time::HiRes qw/gettimeofday/;

View File

@ -1,29 +1,20 @@
# File: AntiTwitter.pm
# Author: pragma_
#
# Purpose: Warns people off from using @nick style addressing. Temp-bans if they
# persist.
# Purpose: Warns people off from using @nick style addressing. Temp-bans
# if they persist.
# 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::AntiTwitter;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;
use Time::Duration qw/duration/;
use feature 'switch';
use utf8;
no if $] >= 5.018, warnings => "experimental::smartmatch";
sub initialize {
my ($self, %conf) = @_;
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });

View File

@ -1,5 +1,4 @@
# File: AutoRejoin.pm
# Author: pragma_
#
# Purpose: Auto-rejoin channels after kick or whatever.
@ -8,12 +7,8 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::AutoRejoin;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use Time::HiRes qw/gettimeofday/;
use Time::Duration;

View File

@ -3,16 +3,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Battleship;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use Time::Duration qw/concise duration/;
use Data::Dumper;

View File

@ -5,11 +5,7 @@
package Plugins::Connect4;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use Time::Duration qw/concise duration/;
use Data::Dumper;

View File

@ -5,11 +5,7 @@
package Plugins::Counter;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use DBI;
use Time::Duration qw/duration/;

View File

@ -1,5 +1,4 @@
# File: Date.pm
# Author: pragma-
#
# Purpose: Adds command to display time and date for timezones.
@ -10,8 +9,7 @@
package Plugins::Date;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Getopt::Long qw(GetOptionsFromArray);

View File

@ -1,3 +1,7 @@
# File: Example.pm
#
# Purpose: Example plugin boilerplate.
# 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/.
@ -5,8 +9,7 @@
package Plugins::Example;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: FuncBuiltins.pm
# Author: pragma-
#
# Purpose: Registers the basic built-in Functions
@ -10,8 +9,7 @@
package Plugins::FuncBuiltins;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: FuncGrep.pm
# Author: pragma-
#
# Purpose: Registers the grep Function
@ -10,8 +9,7 @@
package Plugins::FuncGrep;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,7 +1,6 @@
# File: FuncPlural.pm
# Author: pragma-
#
# Purpose: Registers the plural Function
# Purpose: Registers the plural Function.
# 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
@ -10,8 +9,7 @@
package Plugins::FuncPlural;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;
@ -51,8 +49,13 @@ sub pluralize_word {
'us' => 'uses',
'x' => 'xes',
'ium' => 'ia',
'um' => 'a', 'stomach' => 'stomachs' , 'cactus' => 'cacti' , 'cactus' => 'cacti' , 'knoif' => 'knoives' , 'sheaf' =>
'sheaves' , 'dwarf' => 'dwarves' ,
'um' => 'a',
'stomach' => 'stomachs',
'cactus' => 'cacti',
'cactus' => 'cacti',
'knoif' => 'knoives',
'sheaf' => 'sheaves',
'dwarf' => 'dwarves',
'loaf' => 'loaves',
'louse' => 'lice',
'die' => 'dice',

View File

@ -1,5 +1,4 @@
# File: FuncSed.pm
# Author: pragma-
#
# Purpose: Registers the sed Function
@ -10,8 +9,7 @@
package Plugins::FuncSed;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;
@ -32,7 +30,6 @@ sub unload {
# near-verbatim insertion of krok's `sed` factoid
no warnings;
sub func_sed {
my $self = shift;
my $text = "@_";

View File

@ -1,15 +1,11 @@
#!/usr/bin/perl
# 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::GoogleSearch;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use WWW::Google::CustomSearch;
use HTML::Entities;

View File

@ -1,33 +0,0 @@
# 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/.
# This module is intended to provide a "magic" command that allows
# the bot owner to trigger special arbitrary code (by editing this
# module and refreshing loaded modules before running the magical
# command).
package Plugins::MagicCommand;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
sub initialize {
my ($self, %conf) = @_;
$self->{pbot}->{commands}->register(sub { return $self->cmd_magic(@_) }, "mc", 90);
}
sub unload {
my $self = shift;
$self->{pbot}->{commands}->unregister("mc");
}
sub cmd_magic {
my ($self, $context) = @_;
# do something magical!
return "Did something magical.";
}
1;

View File

@ -7,8 +7,7 @@
package Plugins::ParseDate;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Time::Duration qw/duration/;

View File

@ -1,5 +1,4 @@
# File: Plang.pm
# Author: pragma-
#
# Purpose: Scripting language for creating advanced PBot factoids
# and interacting with various internal PBot APIs.
@ -11,8 +10,7 @@
package Plugins::Plang;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Getopt::Long qw(GetOptionsFromArray);

View File

@ -1,26 +1,28 @@
# File: Plugin.pm
#
# Purpose: Base class for PBot plugins.
# 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;
use PBot::Imports;
sub new {
my ($proto, %conf) = @_;
my $class = ref($proto) || $proto;
my ($class, %args) = @_;
my $self = bless {}, $class;
if (not exists $conf{pbot}) {
if (not exists $args{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);
$self->{pbot} = $args{pbot};
$self->initialize(%args);
return $self;
}

View File

@ -1,18 +1,18 @@
# File: Quotegrabs.pm
# Author: pragma_
#
# Purpose: Allows users to "grab" quotes from message history and store them for later retrieval.
# Purpose: Allows users to "grab" quotes from message history and store them
# for later retrieval. Can grab a quote from any point in the message history,
# not just the most recent message. Can grab multiple distinct messages with
# one `grab` command.
# 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::Quotegrabs;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use HTML::Entities;
use Time::Duration;

View File

@ -1,9 +1,11 @@
# 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::RelayUnreg;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Time::HiRes qw/gettimeofday/;

View File

@ -5,11 +5,7 @@
package Plugins::RemindMe;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use DBI;
use Time::Duration qw/concise duration/;
@ -281,6 +277,9 @@ sub cmd_remindme {
Getopt::Long::Configure("bundling");
my @opt_args = $self->{pbot}->{interpreter}->split_line($context->{arguments}, strip_quotes => 1);
use Data::Dumper;
print "args: [$context->{arguments}]\n";
print Dumper \@opt_args;
GetOptionsFromArray(
\@opt_args,
'r:i' => \$repeat,

View File

@ -1,3 +1,11 @@
# File: RestrictedMod.pm
#
# Purpose: Provides restricted moderation abilities to voiced users.
# They are allowed to ban/mute/kick only users that are not admins,
# whitelisted, or autoop/autovoice. This is useful for, e.g., IRCnet
# configurations where +v users are recognized as "semi-trusted" in
# order to provide assistance in combating heavy spam and drone traffic.
# 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/.
@ -5,14 +13,7 @@
package Plugins::RestrictedMod;
use parent 'Plugins::Plugin';
# purpose: provides restricted moderation abilities to voiced users.
# They are allowed to ban/mute/kick only users that are not admins,
# whitelisted, or autoop/autovoice. This is useful for, e.g., IRCnet
# configurations where +v users are recognized as "semi-trusted" in
# order to provide assistance in combating heavy spam and drone traffic.
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use Storable qw/dclone/;

View File

@ -3,18 +3,13 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Spinach;
use parent 'Plugins::Plugin';
use warnings; use strict;
use PBot::Imports;
use PBot::HashObject;
use FindBin;
use lib "$FindBin::RealBin/../..";
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use feature 'unicode_strings';
use Plugins::Spinach::Stats;
use Plugins::Spinach::Rank;
use JSON;
@ -34,13 +29,9 @@ use Data::Dumper;
$Data::Dumper::Sortkeys = sub {
my ($h) = @_; my @a = sort grep { not /^(?:seen_questions|alternativeSpellings)$/ } keys %$h; \@a;
};
$Data::Dumper::Useqq = 1;
use PBot::HashObject;
use Plugins::Spinach::Stats;
use Plugins::Spinach::Rank;
sub initialize {
my ($self, %conf) = @_;
$self->{pbot}->{commands}->register(sub { $self->cmd_spinach(@_) }, 'spinach', 0);

View File

@ -1,11 +1,6 @@
# 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::TypoSub;
use parent 'Plugins::Plugin';
# purpose: Replaces "typos" with "corrections".
# File: TypoSub.pm
#
# Purpose: Replaces "typos" with "corrections".
#
# Examples:
#
@ -17,8 +12,15 @@ use parent 'Plugins::Plugin';
# <alice> s/like/love/
# <PBot> alice meant to say: i love candy
use warnings; use strict;
use feature 'unicode_strings';
#
# 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::TypoSub;
use parent 'Plugins::Plugin';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: UrlTitles.pm
# Author: pragma-
#
# Purpose: Display titles of URLs in channel messages.
@ -10,8 +9,7 @@
package Plugins::UrlTitles;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;

View File

@ -1,5 +1,4 @@
# File: Weather.pm
# Author: pragma-
#
# Purpose: Weather command.
@ -8,11 +7,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Weather;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use PBot::Imports;
use PBot::Utils::LWPUserAgentCached;
use XML::LibXML;

View File

@ -1,5 +1,4 @@
# File: Wttr.pm
# Author: pragma-
#
# Purpose: Weather command using Wttr.in.
@ -8,18 +7,11 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package Plugins::Wttr;
use parent 'Plugins::Plugin';
use warnings; use strict;
use feature 'unicode_strings';
use utf8;
use feature 'switch';
no if $] >= 5.018, warnings => "experimental::smartmatch";
use PBot::Imports;
use PBot::Utils::LWPUserAgentCached;
use JSON;
use URI::Escape qw/uri_escape_utf8/;
use Getopt::Long qw(GetOptionsFromArray);