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

BlackList: minor clean-up

This commit is contained in:
Pragmatic Software 2020-02-01 22:16:21 -08:00
parent b2a26100c0
commit 4e0e39ea52

View File

@ -21,12 +21,8 @@ use Carp ();
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
sub new { sub new {
if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref($_[1]) eq 'HASH';
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
}
my ($class, %conf) = @_; my ($class, %conf) = @_;
my $self = bless {}, $class; my $self = bless {}, $class;
$self->initialize(%conf); $self->initialize(%conf);
return $self; return $self;
@ -34,20 +30,15 @@ sub new {
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__); $self->{filename} = $conf{filename};
$self->{filename} = delete $conf{filename};
$self->{blacklist} = {}; $self->{blacklist} = {};
$self->{pbot}->{commands}->register(sub { $self->blacklist(@_) }, "blacklist", 10);
$self->{pbot}->{commands}->register(sub { return $self->blacklist(@_) }, "blacklist", 10);
$self->load_blacklist; $self->load_blacklist;
} }
sub add { sub add {
my ($self, $channel, $hostmask) = @_; my ($self, $channel, $hostmask) = @_;
$self->{blacklist}->{lc $channel}->{lc $hostmask} = 1; $self->{blacklist}->{lc $channel}->{lc $hostmask} = 1;
$self->save_blacklist(); $self->save_blacklist();
} }
@ -66,7 +57,6 @@ sub remove {
delete $self->{blacklist}->{$channel}; delete $self->{blacklist}->{$channel};
} }
} }
$self->save_blacklist(); $self->save_blacklist();
} }
@ -78,11 +68,10 @@ sub clear_blacklist {
sub load_blacklist { sub load_blacklist {
my $self = shift; my $self = shift;
my $filename; my $filename;
if (@_) { $filename = shift; } else { $filename = $self->{filename}; } if (@_) { $filename = shift; } else { $filename = $self->{filename}; }
if (not defined $filename) { if (not defined $filename) {
Carp::carp "No blacklist path specified -- skipping loading of blacklist"; $self->{pbot}->{logger}->log("No blacklist path specified -- skipping loading of blacklist");
return; return;
} }
@ -121,7 +110,7 @@ sub save_blacklist {
if (@_) { $filename = shift; } else { $filename = $self->{filename}; } if (@_) { $filename = shift; } else { $filename = $self->{filename}; }
if (not defined $filename) { if (not defined $filename) {
Carp::carp "No blacklist path specified -- skipping saving of blacklist\n"; $self->{pbot}->{logger}->log("No blacklist path specified -- skipping saving of blacklist\n");
return; return;
} }