mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Add %conf to all module creation; add deop timeout registry entry
This commit is contained in:
parent
40b2393d05
commit
548b4681ac
@ -13,11 +13,10 @@ use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub new {
|
||||
if(ref($_[1]) eq 'HASH') {
|
||||
Carp::croak("Options to ChanOps 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 $self = bless {}, $class;
|
||||
$self->initialize(%conf);
|
||||
return $self;
|
||||
@ -26,23 +25,25 @@ sub new {
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
||||
my $pbot = delete $conf{pbot};
|
||||
if(not defined $pbot) {
|
||||
Carp::croak("Missing pbot reference to ChanOps");
|
||||
}
|
||||
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to ChanOps");
|
||||
|
||||
$self->{pbot} = $pbot;
|
||||
$self->{unban_timeout} = PBot::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Unban Timeouts',
|
||||
filename => $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/unban_timeouts'
|
||||
);
|
||||
|
||||
$self->{unban_timeout} = PBot::DualIndexHashObject->new(pbot => $pbot, name => 'Unban Timeouts', filename => $pbot->{registry}->get_value('general', 'data_dir') . '/unban_timeouts');
|
||||
$self->{unban_timeout}->load;
|
||||
|
||||
$self->{op_commands} = {};
|
||||
$self->{is_opped} = {};
|
||||
|
||||
$self->{commands} = PBot::ChanOpCommands->new(pbot => $pbot);
|
||||
$self->{commands} = PBot::ChanOpCommands->new(pbot => $self->{pbot});
|
||||
|
||||
$pbot->{timer}->register(sub { $self->check_opped_timeouts }, 10);
|
||||
$pbot->{timer}->register(sub { $self->check_unban_timeouts }, 10);
|
||||
$self->{pbot}->{registry}->add_default('text', 'general', 'deop_timeout', $conf{'deop_timeout'} // 300);
|
||||
|
||||
$self->{pbot}->{timer}->register(sub { $self->check_opped_timeouts }, 10);
|
||||
$self->{pbot}->{timer}->register(sub { $self->check_unban_timeouts }, 10);
|
||||
}
|
||||
|
||||
sub gain_ops {
|
||||
@ -51,7 +52,7 @@ sub gain_ops {
|
||||
|
||||
if(not exists $self->{is_opped}->{$channel}) {
|
||||
$self->{pbot}->{conn}->privmsg("chanserv", "op $channel");
|
||||
$self->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # assume we're going to be opped
|
||||
$self->{is_opped}->{$channel}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('general', 'deop_timeout'); # assume we're going to be opped
|
||||
} else {
|
||||
$self->perform_op_commands($channel);
|
||||
}
|
||||
|
32
PBot/PBot.pm
32
PBot/PBot.pm
@ -18,7 +18,7 @@ BEGIN {
|
||||
our @EXPORT = qw($VERSION);
|
||||
|
||||
our $VERSION = PBot::VERSION::BUILD_NAME . " revision " . PBot::VERSION::BUILD_REVISION . " " . PBot::VERSION::BUILD_DATE;
|
||||
print "PBot version $VERSION\n";
|
||||
print "$VERSION\n";
|
||||
}
|
||||
|
||||
# unbuffer stdout
|
||||
@ -61,16 +61,16 @@ sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
||||
# logger created first to allow other modules to log things
|
||||
$self->{logger} = PBot::Logger->new(log_file => delete $conf{log_file});
|
||||
$self->{logger} = PBot::Logger->new(log_file => delete $conf{log_file}, %conf);
|
||||
|
||||
$self->{atexit} = PBot::Registerable->new();
|
||||
$self->{timer} = PBot::Timer->new(timeout => 10);
|
||||
$self->{commands} = PBot::Commands->new(pbot => $self);
|
||||
$self->{atexit} = PBot::Registerable->new(%conf);
|
||||
$self->{timer} = PBot::Timer->new(timeout => 10, %conf);
|
||||
$self->{commands} = PBot::Commands->new(pbot => $self, %conf);
|
||||
|
||||
my $config_dir = delete $conf{config_dir} // "$ENV{HOME}/pbot/config";
|
||||
|
||||
# registry created, but not yet loaded, to allow modules to create default values and triggers
|
||||
$self->{registry} = PBot::Registry->new(pbot => $self, filename => delete $conf{registry_file} // "$config_dir/registry");
|
||||
$self->{registry} = PBot::Registry->new(pbot => $self, filename => delete $conf{registry_file} // "$config_dir/registry", %conf);
|
||||
|
||||
$self->{registry}->add_default('text', 'general', 'config_dir', $config_dir);
|
||||
$self->{registry}->add_default('text', 'general', 'data_dir', delete $conf{data_dir} // "$ENV{HOME}/pbot/data");
|
||||
@ -94,20 +94,20 @@ sub initialize {
|
||||
|
||||
$self->{registry}->add_trigger('irc', 'botnick', sub { $self->change_botnick_trigger(@_) });
|
||||
|
||||
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self);
|
||||
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self);
|
||||
$self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file});
|
||||
$self->{bantracker} = PBot::BanTracker->new(pbot => $self);
|
||||
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self, %conf);
|
||||
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self, %conf);
|
||||
$self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file}, %conf);
|
||||
$self->{bantracker} = PBot::BanTracker->new(pbot => $self, %conf);
|
||||
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self, %conf);
|
||||
$self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => delete $conf{messagehistory_file}, %conf);
|
||||
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self, %conf);
|
||||
$self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file});
|
||||
$self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file}, %conf);
|
||||
$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->{irchandlers} = PBot::IRCHandlers->new(pbot => $self, %conf);
|
||||
$self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file}, %conf);
|
||||
$self->{chanops} = PBot::ChanOps->new(pbot => $self, %conf);
|
||||
|
||||
$self->{interpreter} = PBot::Interpreter->new(pbot => $self);
|
||||
$self->{interpreter} = PBot::Interpreter->new(pbot => $self, %conf);
|
||||
$self->{interpreter}->register(sub { return $self->{commands}->interpreter(@_); });
|
||||
$self->{interpreter}->register(sub { return $self->{factoids}->interpreter(@_); });
|
||||
|
||||
@ -116,6 +116,7 @@ sub initialize {
|
||||
filename => delete $conf{factoids_file},
|
||||
export_path => delete $conf{export_factoids_path},
|
||||
export_site => delete $conf{export_factoids_site},
|
||||
%conf
|
||||
);
|
||||
|
||||
$self->{quotegrabs} = PBot::Quotegrabs->new(
|
||||
@ -123,6 +124,7 @@ sub initialize {
|
||||
filename => delete $conf{quotegrabs_file},
|
||||
export_path => delete $conf{export_quotegrabs_path},
|
||||
export_site => delete $conf{export_quotegrabs_site},
|
||||
%conf
|
||||
);
|
||||
|
||||
# load registry entries from file to overwrite defaults
|
||||
|
@ -13,7 +13,7 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 592,
|
||||
BUILD_REVISION => 593,
|
||||
BUILD_DATE => "2014-05-19",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user