2010-03-22 08:33:44 +01:00
|
|
|
# File: IgnoreList.pm
|
2010-03-24 07:47:40 +01:00
|
|
|
# Author: pragma_
|
2010-03-17 07:36:54 +01:00
|
|
|
#
|
2010-03-22 08:33:44 +01:00
|
|
|
# Purpose: Manages ignore list.
|
2010-03-17 07:36:54 +01:00
|
|
|
|
|
|
|
package PBot::IgnoreList;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
use vars qw($VERSION);
|
|
|
|
$VERSION = $PBot::PBot::VERSION;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub new {
|
|
|
|
if(ref($_[1]) eq 'HASH') {
|
|
|
|
Carp::croak("Options to Commands should be key/value pairs, not hash reference");
|
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
my ($class, %conf) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
my $pbot = delete $conf{pbot};
|
|
|
|
if(not defined $pbot) {
|
|
|
|
Carp::croak("Missing pbot reference to Channels");
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
$self->{ignore_list} = {};
|
2010-03-23 04:09:03 +01:00
|
|
|
$self->{ignore_flood_counter} = 0;
|
|
|
|
$self->{last_timestamp} = gettimeofday;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
|
|
|
$pbot->timer->register(sub { $self->check_ignore_timeouts }, 10);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub add {
|
|
|
|
my $self = shift;
|
|
|
|
my ($hostmask, $channel, $length) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
${ $self->{ignore_list} }{$hostmask}{$channel} = gettimeofday + $length;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub remove {
|
|
|
|
my $self = shift;
|
|
|
|
my ($hostmask, $channel) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
delete ${ $self->{ignore_list} }{$hostmask}{$channel};
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub check_ignore {
|
2010-03-22 08:33:44 +01:00
|
|
|
my $self = shift;
|
2010-03-17 07:36:54 +01:00
|
|
|
my ($nick, $user, $host, $channel) = @_;
|
2010-03-23 04:09:03 +01:00
|
|
|
my $pbot = $self->{pbot};
|
2010-03-17 07:36:54 +01:00
|
|
|
$channel = lc $channel;
|
|
|
|
|
|
|
|
my $hostmask = "$nick!$user\@$host";
|
|
|
|
|
2010-03-23 04:09:03 +01:00
|
|
|
my $now = gettimeofday;
|
|
|
|
|
|
|
|
if(defined $channel) { # do not execute following if text is coming from STDIN ($channel undef)
|
|
|
|
if($channel =~ /^#/) {
|
|
|
|
$self->{ignore_flood_counter}++; # TODO: make this per channel, e.g., ${ $self->{ignore_flood_counter} }{$channel}++
|
|
|
|
$pbot->logger->log("flood_msg: $self->{ignore_flood_counter}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if($self->{ignore_flood_counter} > 4) {
|
|
|
|
$pbot->logger->log("flood_msg exceeded! [$self->{ignore_flood_counter}]\n");
|
|
|
|
$self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
|
|
|
|
$self->{ignore_flood_counter} = 0;
|
|
|
|
if($channel =~ /^#/) {
|
|
|
|
$pbot->conn->me($channel, "has been overwhelmed.");
|
|
|
|
$pbot->conn->me($channel, "lies down and falls asleep.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($now - $self->{last_timestamp} >= 15) {
|
|
|
|
$self->{last_timestamp} = $now;
|
|
|
|
if($self->{ignore_flood_counter} > 0) {
|
|
|
|
$pbot->logger->log("flood_msg reset: (was $self->{ignore_flood_counter})\n");
|
|
|
|
$self->{ignore_flood_counter} = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
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");
|
2010-03-17 07:36:54 +01:00
|
|
|
if(($channel =~ /$ignored_channel/i) && ($hostmask =~ /$ignored/i)) {
|
2010-03-22 08:33:44 +01:00
|
|
|
$self->{pbot}->logger->log("$nick!$user\@$host message ignored in channel $channel (matches [$ignored] host and [$ignored_channel] channel)\n");
|
2010-03-17 07:36:54 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2010-03-23 19:24:02 +01:00
|
|
|
sub check_ignore_timeouts {
|
|
|
|
my $self = shift;
|
|
|
|
my $now = gettimeofday();
|
|
|
|
|
|
|
|
foreach my $hostmask (keys %{ $self->{ignore_list} }) {
|
|
|
|
foreach my $channel (keys %{ $self->{ignore_list}->{$hostmask} }) {
|
|
|
|
next if($self->{ignore_list}->{$hostmask}{$channel} == -1); #permanent ignore
|
|
|
|
|
|
|
|
if($self->{ignore_list}->{$hostmask}{$channel} < $now) {
|
|
|
|
$self->{pbot}->{ignorelistcmds}->unignore_user("", "floodcontrol", "", "", "$hostmask $channel");
|
|
|
|
if($hostmask eq ".*") {
|
|
|
|
$self->{pbot}->conn->me($channel, "awakens.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#my $timediff = $ignore_list{$host}{$channel} - $now;
|
|
|
|
#$logger->log "ignore: $host has $timediff seconds remaining\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
1;
|