mirror of https://github.com/pragma-/pbot.git
Move command modules out of PBot.pm and into their respective modules
E.g., FactoidCommands.pm is now loaded inside Factoids.pm, etc. Misc reformatting/refactoring of PBot.pm
This commit is contained in:
parent
d955bfa06c
commit
e07df35cbf
|
@ -362,7 +362,7 @@ sub check_flood {
|
||||||
|
|
||||||
my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30;
|
my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30;
|
||||||
|
|
||||||
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
|
$self->{pbot}->ignorelist->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
|
||||||
$length = duration($length);
|
$length = duration($length);
|
||||||
$self->{pbot}->logger->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n");
|
$self->{pbot}->logger->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n");
|
||||||
$self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length.");
|
$self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length.");
|
||||||
|
|
|
@ -9,12 +9,13 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use PBot::DualIndexHashObject;
|
use PBot::DualIndexHashObject;
|
||||||
|
use PBot::BotAdminCommands;
|
||||||
|
|
||||||
use Carp ();
|
use Carp ();
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
if(ref($_[1]) eq 'HASH') {
|
if(ref($_[1]) eq 'HASH') {
|
||||||
Carp::croak("Options to BotAdmins should be key/value pairs, not hash reference");
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($class, %conf) = @_;
|
my ($class, %conf) = @_;
|
||||||
|
@ -30,13 +31,8 @@ sub initialize {
|
||||||
my $filename = delete $conf{filename};
|
my $filename = delete $conf{filename};
|
||||||
my $export_path = delete $conf{export_path};
|
my $export_path = delete $conf{export_path};
|
||||||
my $export_site = delete $conf{export_site};
|
my $export_site = delete $conf{export_site};
|
||||||
|
|
||||||
my $pbot = delete $conf{pbot};
|
|
||||||
if(not defined $pbot) {
|
|
||||||
Carp::croak("Missing pbot reference to BotAdmins");
|
|
||||||
}
|
|
||||||
|
|
||||||
my $export_timeout = delete $conf{export_timeout};
|
my $export_timeout = delete $conf{export_timeout};
|
||||||
|
|
||||||
if(not defined $export_timeout) {
|
if(not defined $export_timeout) {
|
||||||
if(defined $export_path) {
|
if(defined $export_path) {
|
||||||
$export_timeout = 300; # every 5 minutes
|
$export_timeout = 300; # every 5 minutes
|
||||||
|
@ -45,12 +41,14 @@ sub initialize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
||||||
$self->{admins} = PBot::DualIndexHashObject->new(name => 'Admins', filename => $filename);
|
$self->{admins} = PBot::DualIndexHashObject->new(name => 'Admins', filename => $filename);
|
||||||
|
$self->{commands} = PBot::BotAdminCommands->new(pbot => $self->{pbot});
|
||||||
$self->{export_path} = $export_path;
|
$self->{export_path} = $export_path;
|
||||||
$self->{export_site} = $export_site;
|
$self->{export_site} = $export_site;
|
||||||
$self->{export_timeout} = $export_timeout;
|
$self->{export_timeout} = $export_timeout;
|
||||||
|
|
||||||
$self->{pbot} = $pbot;
|
$self->load_admins;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_admin {
|
sub add_admin {
|
||||||
|
|
|
@ -8,6 +8,7 @@ package PBot::ChanOps;
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
use PBot::ChanOpCommands;
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -38,6 +39,8 @@ sub initialize {
|
||||||
$self->{op_commands} = {};
|
$self->{op_commands} = {};
|
||||||
$self->{is_opped} = {};
|
$self->{is_opped} = {};
|
||||||
|
|
||||||
|
$self->{commands} = PBot::ChanOpCommands->new(pbot => $pbot);
|
||||||
|
|
||||||
$pbot->timer->register(sub { $self->check_opped_timeouts }, 10);
|
$pbot->timer->register(sub { $self->check_opped_timeouts }, 10);
|
||||||
$pbot->timer->register(sub { $self->check_unban_timeouts }, 10);
|
$pbot->timer->register(sub { $self->check_unban_timeouts }, 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ use Carp ();
|
||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
|
|
||||||
use PBot::PBot qw($VERSION);
|
use PBot::PBot qw($VERSION);
|
||||||
|
use PBot::FactoidCommands;
|
||||||
use PBot::FactoidModuleLauncher;
|
use PBot::FactoidModuleLauncher;
|
||||||
use PBot::DualIndexHashObject;
|
use PBot::DualIndexHashObject;
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ sub initialize {
|
||||||
$self->{export_site} = $export_site;
|
$self->{export_site} = $export_site;
|
||||||
|
|
||||||
$self->{pbot} = $pbot;
|
$self->{pbot} = $pbot;
|
||||||
|
$self->{commands} = PBot::FactoidCommands->new(pbot => $pbot);
|
||||||
$self->{factoidmodulelauncher} = PBot::FactoidModuleLauncher->new(pbot => $pbot);
|
$self->{factoidmodulelauncher} = PBot::FactoidModuleLauncher->new(pbot => $pbot);
|
||||||
|
|
||||||
$self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; });
|
$self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; });
|
||||||
|
@ -341,7 +343,7 @@ sub interpreter {
|
||||||
# if a non-nick argument was supplied, e.g., a sentence using the bot's nick, don't say anything
|
# if a non-nick argument was supplied, e.g., a sentence using the bot's nick, don't say anything
|
||||||
return "" if length $arguments and $arguments !~ /^[^.+-, ]{1,20}$/;
|
return "" if length $arguments and $arguments !~ /^[^.+-, ]{1,20}$/;
|
||||||
|
|
||||||
my $matches = $self->{pbot}->{factoidcmds}->factfind($from, $nick, $user, $host, quotemeta $original_keyword);
|
my $matches = $self->{commands}->factfind($from, $nick, $user, $host, quotemeta $original_keyword);
|
||||||
|
|
||||||
# found factfind matches
|
# found factfind matches
|
||||||
if($matches !~ m/^No factoids/) {
|
if($matches !~ m/^No factoids/) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ package PBot::IgnoreList;
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
use PBot::IgnoreListCommands;
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -32,6 +33,8 @@ sub initialize {
|
||||||
$self->{ignore_flood_counter} = {};
|
$self->{ignore_flood_counter} = {};
|
||||||
$self->{last_timestamp} = {};
|
$self->{last_timestamp} = {};
|
||||||
|
|
||||||
|
$self->{commands} = PBot::IgnoreListCommands->new(pbot => $self->{pbot});
|
||||||
|
|
||||||
$self->load_ignores;
|
$self->load_ignores;
|
||||||
|
|
||||||
$self->{pbot}->timer->register(sub { $self->check_ignore_timeouts }, 10);
|
$self->{pbot}->timer->register(sub { $self->check_ignore_timeouts }, 10);
|
||||||
|
@ -146,7 +149,7 @@ sub check_ignore {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exists $self->{ignore_flood_counter}->{$channel} and $self->{ignore_flood_counter}->{$channel} > 5) {
|
if(exists $self->{ignore_flood_counter}->{$channel} and $self->{ignore_flood_counter}->{$channel} > 5) {
|
||||||
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
|
$self->{commands}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
|
||||||
$self->{ignore_flood_counter}->{$channel} = 0;
|
$self->{ignore_flood_counter}->{$channel} = 0;
|
||||||
if($channel =~ /^#/) {
|
if($channel =~ /^#/) {
|
||||||
$pbot->conn->me($channel, "has been overwhelmed.");
|
$pbot->conn->me($channel, "has been overwhelmed.");
|
||||||
|
@ -183,7 +186,7 @@ sub check_ignore_timeouts {
|
||||||
next if($self->{ignore_list}->{$hostmask}{$channel} == -1); #permanent ignore
|
next if($self->{ignore_list}->{$hostmask}{$channel} == -1); #permanent ignore
|
||||||
|
|
||||||
if($self->{ignore_list}->{$hostmask}{$channel} < $now) {
|
if($self->{ignore_list}->{$hostmask}{$channel} < $now) {
|
||||||
$self->{pbot}->{ignorelistcmds}->unignore_user("", "floodcontrol", "", "", "$hostmask $channel");
|
$self->{commands}->unignore_user("", "floodcontrol", "", "", "$hostmask $channel");
|
||||||
if($hostmask eq ".*") {
|
if($hostmask eq ".*") {
|
||||||
$self->{pbot}->conn->me($channel, "awakens.");
|
$self->{pbot}->conn->me($channel, "awakens.");
|
||||||
}
|
}
|
||||||
|
|
61
PBot/PBot.pm
61
PBot/PBot.pm
|
@ -26,40 +26,23 @@ STDOUT->autoflush(1);
|
||||||
|
|
||||||
use Carp ();
|
use Carp ();
|
||||||
use PBot::Logger;
|
use PBot::Logger;
|
||||||
|
|
||||||
use PBot::Registry;
|
use PBot::Registry;
|
||||||
|
|
||||||
use PBot::SelectHandler;
|
use PBot::SelectHandler;
|
||||||
use PBot::StdinReader;
|
use PBot::StdinReader;
|
||||||
|
|
||||||
use PBot::IRC;
|
use PBot::IRC;
|
||||||
use PBot::IRCHandlers;
|
use PBot::IRCHandlers;
|
||||||
use PBot::Channels;
|
use PBot::Channels;
|
||||||
|
|
||||||
use PBot::BanTracker;
|
use PBot::BanTracker;
|
||||||
|
|
||||||
use PBot::LagChecker;
|
use PBot::LagChecker;
|
||||||
use PBot::MessageHistory;
|
use PBot::MessageHistory;
|
||||||
use PBot::AntiFlood;
|
use PBot::AntiFlood;
|
||||||
|
|
||||||
use PBot::Interpreter;
|
use PBot::Interpreter;
|
||||||
use PBot::Commands;
|
use PBot::Commands;
|
||||||
|
|
||||||
use PBot::ChanOps;
|
use PBot::ChanOps;
|
||||||
use PBot::ChanOpCommands;
|
|
||||||
|
|
||||||
use PBot::Factoids;
|
use PBot::Factoids;
|
||||||
use PBot::FactoidCommands;
|
|
||||||
|
|
||||||
use PBot::BotAdmins;
|
use PBot::BotAdmins;
|
||||||
use PBot::BotAdminCommands;
|
|
||||||
|
|
||||||
use PBot::IgnoreList;
|
use PBot::IgnoreList;
|
||||||
use PBot::IgnoreListCommands;
|
|
||||||
|
|
||||||
use PBot::Quotegrabs;
|
use PBot::Quotegrabs;
|
||||||
# no PBot::QuotegrabsCommands (bundled inside PBot::Quotegrabs for a change)
|
|
||||||
|
|
||||||
use PBot::Timer;
|
use PBot::Timer;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -99,13 +82,13 @@ sub initialize {
|
||||||
$self->{registry}->add_default('text', 'irc', 'port', delete $conf{port} // 6667);
|
$self->{registry}->add_default('text', 'irc', 'port', delete $conf{port} // 6667);
|
||||||
$self->{registry}->add_default('text', 'irc', 'SSL', delete $conf{SSL} // 0);
|
$self->{registry}->add_default('text', 'irc', 'SSL', delete $conf{SSL} // 0);
|
||||||
$self->{registry}->add_default('text', 'irc', 'SSL_ca_file', delete $conf{SSL_ca_file} // 'none');
|
$self->{registry}->add_default('text', 'irc', 'SSL_ca_file', delete $conf{SSL_ca_file} // 'none');
|
||||||
$self->{registry}->set('irc', 'SSL_ca_file', 'private', 1);
|
|
||||||
$self->{registry}->add_default('text', 'irc', 'SSL_ca_path', delete $conf{SSL_ca_path} // 'none');
|
$self->{registry}->add_default('text', 'irc', 'SSL_ca_path', delete $conf{SSL_ca_path} // 'none');
|
||||||
$self->{registry}->set('irc', 'SSL_ca_path', 'private', 1);
|
|
||||||
$self->{registry}->add_default('text', 'irc', 'botnick', delete $conf{botnick} // "pbot3");
|
$self->{registry}->add_default('text', 'irc', 'botnick', delete $conf{botnick} // "pbot3");
|
||||||
$self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3");
|
$self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3");
|
||||||
$self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/");
|
$self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/");
|
||||||
$self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // "");
|
$self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // "");
|
||||||
|
$self->{registry}->set('irc', 'SSL_ca_file', 'private', 1);
|
||||||
|
$self->{registry}->set('irc', 'SSL_ca_path', 'private', 1);
|
||||||
$self->{registry}->set('irc', 'identify_password', 'private', 1);
|
$self->{registry}->set('irc', 'identify_password', 'private', 1);
|
||||||
|
|
||||||
$self->{registry}->add_trigger('irc', 'botnick', sub { $self->change_botnick_trigger(@_) });
|
$self->{registry}->add_trigger('irc', 'botnick', sub { $self->change_botnick_trigger(@_) });
|
||||||
|
@ -114,7 +97,6 @@ sub initialize {
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'max_chat_flood', delete $conf{max_chat_flood} // 4);
|
$self->{registry}->add_default('text', 'antiflood', 'max_chat_flood', delete $conf{max_chat_flood} // 4);
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'max_enter_flood', delete $conf{max_enter_flood} // 4);
|
$self->{registry}->add_default('text', 'antiflood', 'max_enter_flood', delete $conf{max_enter_flood} // 4);
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'max_nick_flood', delete $conf{max_nick_flood} // 3);
|
$self->{registry}->add_default('text', 'antiflood', 'max_nick_flood', delete $conf{max_nick_flood} // 3);
|
||||||
|
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_lines', delete $conf{enter_abuse_max_lines} // 4);
|
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_lines', delete $conf{enter_abuse_max_lines} // 4);
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_seconds', delete $conf{enter_abuse_max_seconds} // 20);
|
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_seconds', delete $conf{enter_abuse_max_seconds} // 20);
|
||||||
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_offenses', delete $conf{enter_abuse_max_offenses} // 3);
|
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_offenses', delete $conf{enter_abuse_max_offenses} // 3);
|
||||||
|
@ -123,9 +105,20 @@ sub initialize {
|
||||||
|
|
||||||
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self);
|
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self);
|
||||||
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self);
|
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self);
|
||||||
|
|
||||||
$self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file});
|
$self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file});
|
||||||
$self->admins->load_admins();
|
$self->{bantracker} = PBot::BanTracker->new(pbot => $self);
|
||||||
|
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self);
|
||||||
|
$self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => delete $conf{messagehistory_file});
|
||||||
|
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self);
|
||||||
|
$self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file});
|
||||||
|
$self->{irc} = PBot::IRC->new();
|
||||||
|
$self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self);
|
||||||
|
$self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file});
|
||||||
|
$self->{chanops} = PBot::ChanOps->new(pbot => $self);
|
||||||
|
|
||||||
|
$self->interpreter(PBot::Interpreter->new(pbot => $self));
|
||||||
|
$self->interpreter->register(sub { return $self->commands->interpreter(@_); });
|
||||||
|
$self->interpreter->register(sub { return $self->factoids->interpreter(@_); });
|
||||||
|
|
||||||
$self->{factoids} = PBot::Factoids->new(
|
$self->{factoids} = PBot::Factoids->new(
|
||||||
pbot => $self,
|
pbot => $self,
|
||||||
|
@ -134,30 +127,6 @@ sub initialize {
|
||||||
export_site => delete $conf{export_factoids_site},
|
export_site => delete $conf{export_factoids_site},
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{bantracker} = PBot::BanTracker->new(pbot => $self);
|
|
||||||
|
|
||||||
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self);
|
|
||||||
$self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => delete $conf{messagehistory_file});
|
|
||||||
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self);
|
|
||||||
|
|
||||||
$self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file});
|
|
||||||
|
|
||||||
$self->interpreter(PBot::Interpreter->new(pbot => $self));
|
|
||||||
$self->interpreter->register(sub { return $self->commands->interpreter(@_); });
|
|
||||||
$self->interpreter->register(sub { return $self->factoids->interpreter(@_); });
|
|
||||||
|
|
||||||
$self->{botadmincmds} = PBot::BotAdminCommands->new(pbot => $self);
|
|
||||||
$self->{factoidcmds} = PBot::FactoidCommands->new(pbot => $self);
|
|
||||||
$self->{ignorelistcmds} = PBot::IgnoreListCommands->new(pbot => $self);
|
|
||||||
|
|
||||||
$self->{irc} = PBot::IRC->new();
|
|
||||||
$self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self);
|
|
||||||
|
|
||||||
$self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file});
|
|
||||||
|
|
||||||
$self->{chanops} = PBot::ChanOps->new(pbot => $self);
|
|
||||||
$self->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self);
|
|
||||||
|
|
||||||
$self->{quotegrabs} = PBot::Quotegrabs->new(
|
$self->{quotegrabs} = PBot::Quotegrabs->new(
|
||||||
pbot => $self,
|
pbot => $self,
|
||||||
filename => delete $conf{quotegrabs_file},
|
filename => delete $conf{quotegrabs_file},
|
||||||
|
|
|
@ -13,7 +13,7 @@ use warnings;
|
||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 582,
|
BUILD_REVISION => 583,
|
||||||
BUILD_DATE => "2014-05-17",
|
BUILD_DATE => "2014-05-17",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue