mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-08 21:19:35 +01:00
74 lines
1.6 KiB
Perl
74 lines
1.6 KiB
Perl
# File: IgnoreList.pm
|
|
# Authoer: pragma_
|
|
#
|
|
# Purpose: Manages ignore list.
|
|
|
|
package PBot::IgnoreList;
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
use vars qw($VERSION);
|
|
$VERSION = $PBot::PBot::VERSION;
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
sub new {
|
|
if(ref($_[1]) eq 'HASH') {
|
|
Carp::croak("Options to Commands should be key/value pairs, not hash reference");
|
|
}
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
my $self = bless {}, $class;
|
|
$self->initialize(%conf);
|
|
return $self;
|
|
}
|
|
|
|
sub initialize {
|
|
my ($self, %conf) = @_;
|
|
|
|
my $pbot = delete $conf{pbot};
|
|
if(not defined $pbot) {
|
|
Carp::croak("Missing pbot reference to Channels");
|
|
}
|
|
|
|
$self->{pbot} = $pbot;
|
|
$self->{ignore_list} = {};
|
|
}
|
|
|
|
sub add {
|
|
my $self = shift;
|
|
my ($hostmask, $channel, $length) = @_;
|
|
|
|
${ $self->{ignore_list} }{$hostmask}{$channel} = gettimeofday + $length;
|
|
}
|
|
|
|
sub remove {
|
|
my $self = shift;
|
|
my ($hostmask, $channel) = @_;
|
|
|
|
delete ${ $self->{ignore_list} }{$hostmask}{$channel};
|
|
}
|
|
|
|
sub check_ignore {
|
|
my $self = shift;
|
|
my ($nick, $user, $host, $channel) = @_;
|
|
$channel = lc $channel;
|
|
|
|
my $hostmask = "$nick!$user\@$host";
|
|
|
|
foreach my $ignored (keys %{ $self->{ignore_list} }) {
|
|
foreach my $ignored_channel (keys %{ ${ $self->{ignore_list} }{$ignored} }) {
|
|
$self->{pbot}->logger->log("check_ignore: comparing '$hostmask' against '$ignored' for channel '$channel'\n");
|
|
if(($channel =~ /$ignored_channel/i) && ($hostmask =~ /$ignored/i)) {
|
|
$self->{pbot}->logger->log("$nick!$user\@$host message ignored in channel $channel (matches [$ignored] host and [$ignored_channel] channel)\n");
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
1;
|