mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 10:59:29 +01:00
Added channel ban tracking
This commit is contained in:
parent
b07306f530
commit
3c6288920e
91
PBot/BanTracker.pm
Normal file
91
PBot/BanTracker.pm
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# File: BanTracker.pm
|
||||||
|
# Author: pragma_
|
||||||
|
#
|
||||||
|
# Purpose: Populates and maintains channel banlists by checking mode +b on
|
||||||
|
# joining channels and by tracking modes +b and -b in channels.
|
||||||
|
#
|
||||||
|
# Does NOT do banning or unbanning.
|
||||||
|
|
||||||
|
package PBot::BanTracker;
|
||||||
|
|
||||||
|
use warnings;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
use vars qw($VERSION);
|
||||||
|
$VERSION = $PBot::PBot::VERSION;
|
||||||
|
|
||||||
|
use Time::HiRes qw/gettimeofday/;
|
||||||
|
use Time::Duration;
|
||||||
|
use Data::Dumper;
|
||||||
|
use Carp ();
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
if(ref($_[1]) eq 'HASH') {
|
||||||
|
Carp::croak("Options to BanTracker 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} // Carp::croak("Missing pbot reference to BanTracker");
|
||||||
|
$self->{pbot} = $pbot;
|
||||||
|
|
||||||
|
$self->{banlist} = {};
|
||||||
|
|
||||||
|
$pbot->commands->register(sub { return $self->dumpbans(@_) }, "dumpbans", 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub dumpbans {
|
||||||
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||||
|
|
||||||
|
my $bans = Dumper($self->{banlist});
|
||||||
|
return $bans;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_banlist {
|
||||||
|
my ($self, $conn, $event) = @_;
|
||||||
|
my $channel = lc $event->{args}[1];
|
||||||
|
|
||||||
|
delete $self->{banlist}->{$channel};
|
||||||
|
|
||||||
|
$self->{pbot}->logger->log("Retrieving banlist for $channel.\n");
|
||||||
|
$conn->sl("mode $channel +b");
|
||||||
|
}
|
||||||
|
|
||||||
|
sub on_banlistentry {
|
||||||
|
my ($self, $conn, $event) = @_;
|
||||||
|
my $channel = lc $event->{args}[1];
|
||||||
|
my $target = lc $event->{args}[2];
|
||||||
|
my $source = lc $event->{args}[3];
|
||||||
|
my $timestamp = $event->{args}[4];
|
||||||
|
|
||||||
|
my $ago = ago(gettimeofday - $timestamp);
|
||||||
|
|
||||||
|
$self->{pbot}->logger->log("ban-tracker: [banlist entry] $channel: $target banned by $source $ago.\n");
|
||||||
|
$self->{banlist}->{$channel}->{$target} = [ $source, $timestamp ];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub track_mode {
|
||||||
|
my $self = shift;
|
||||||
|
my ($source, $mode, $target, $channel) = @_;
|
||||||
|
|
||||||
|
if($mode eq "+b") {
|
||||||
|
$self->{pbot}->logger->log("ban-tracker: $target banned by $source in $channel.\n");
|
||||||
|
$self->{banlist}->{$channel}->{$target} = [ $source, gettimeofday ];
|
||||||
|
}
|
||||||
|
elsif($mode eq "-b") {
|
||||||
|
$self->{pbot}->logger->log("ban-tracker: $target unbanned by $source in $channel.\n");
|
||||||
|
delete $self->{banlist}->{$channel}->{$target};
|
||||||
|
} else {
|
||||||
|
$self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -115,43 +115,59 @@ sub on_action {
|
|||||||
|
|
||||||
sub on_mode {
|
sub on_mode {
|
||||||
my ($self, $conn, $event) = @_;
|
my ($self, $conn, $event) = @_;
|
||||||
my ($nick, $host) = ($event->nick, $event->host);
|
my ($nick, $user, $host) = ($event->nick, $event->user, $event->host);
|
||||||
my $mode = $event->{args}[0];
|
my $mode = $event->{args}[0];
|
||||||
my $target = $event->{args}[1];
|
my $target = $event->{args}[1];
|
||||||
my $channel = $event->{to}[0];
|
my $channel = $event->{to}[0];
|
||||||
$channel = lc $channel;
|
$channel = lc $channel;
|
||||||
|
|
||||||
$self->{pbot}->logger->log("Got mode: nick: $nick, host: $host, mode: $mode, target: " . (defined $target ? $target : "") . ", channel: $channel\n");
|
$self->{pbot}->logger->log("Got mode: source: $nick!$user\@$host, mode: $mode, target: " . (defined $target ? $target : "(undef)") . ", channel: $channel\n");
|
||||||
|
|
||||||
|
if($mode eq "-b" or $mode eq "+b") {
|
||||||
|
$self->{pbot}->bantracker->track_mode("$nick!$user\@$host", $mode, $target, $channel);
|
||||||
|
}
|
||||||
|
|
||||||
if(defined $target && $target eq $self->{pbot}->botnick) { # bot targeted
|
if(defined $target && $target eq $self->{pbot}->botnick) { # bot targeted
|
||||||
if($mode eq "+o") {
|
if($mode eq "+o") {
|
||||||
$self->{pbot}->logger->log("$nick opped me in $channel\n");
|
$self->{pbot}->logger->log("$nick opped me in $channel\n");
|
||||||
|
|
||||||
if(exists $self->{pbot}->chanops->{is_opped}->{$channel}) {
|
if(exists $self->{pbot}->chanops->{is_opped}->{$channel}) {
|
||||||
$self->{pbot}->logger->log("erm, I was already opped?\n");
|
$self->{pbot}->logger->log("erm, I was already opped?\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{pbot}->chanops->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # 5 minutes
|
$self->{pbot}->chanops->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # 5 minutes
|
||||||
$self->{pbot}->chanops->perform_op_commands();
|
$self->{pbot}->chanops->perform_op_commands();
|
||||||
} elsif($mode eq "-o") {
|
}
|
||||||
|
elsif($mode eq "-o") {
|
||||||
$self->{pbot}->logger->log("$nick removed my ops in $channel\n");
|
$self->{pbot}->logger->log("$nick removed my ops in $channel\n");
|
||||||
|
|
||||||
if(not exists $self->{pbot}->chanops->{is_opped}->{$channel}) {
|
if(not exists $self->{pbot}->chanops->{is_opped}->{$channel}) {
|
||||||
$self->{pbot}->logger->log("warning: erm, I wasn't opped?\n");
|
$self->{pbot}->logger->log("warning: erm, I wasn't opped?\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
delete $self->{pbot}->chanops->{is_opped}->{$channel};
|
delete $self->{pbot}->chanops->{is_opped}->{$channel};
|
||||||
}
|
}
|
||||||
} else { # bot not targeted
|
elsif($mode eq "+b") {
|
||||||
|
$self->{pbot}->logger->log("Got banned in $channel, attempting unban.");
|
||||||
|
$conn->privmsg("chanserv", "unban $channel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { # bot not targeted
|
||||||
if($mode eq "+b") {
|
if($mode eq "+b") {
|
||||||
if($nick eq "ChanServ") {
|
if($nick eq "ChanServ") {
|
||||||
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
|
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
|
||||||
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{channel} = $channel;
|
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{channel} = $channel;
|
||||||
$self->{pbot}->chanops->{unban_timeout}->save_hash();
|
$self->{pbot}->chanops->{unban_timeout}->save_hash();
|
||||||
}
|
}
|
||||||
} elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) {
|
}
|
||||||
|
elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) {
|
||||||
foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) {
|
foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) {
|
||||||
if($self->channels->channels->hash->{$chan}{enabled}) {
|
if($self->channels->channels->hash->{$chan}{enabled}) {
|
||||||
$self->{pbot}->logger->log("Joining channel: $chan\n");
|
$self->{pbot}->logger->log("Joining channel: $chan\n");
|
||||||
$self->{pbot}->conn->join($chan);
|
$self->{pbot}->conn->join($chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{pbot}->{joined_channels} = 1;
|
$self->{pbot}->{joined_channels} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
PBot/PBot.pm
12
PBot/PBot.pm
@ -27,6 +27,8 @@ use PBot::IRC;
|
|||||||
use PBot::IRCHandlers;
|
use PBot::IRCHandlers;
|
||||||
use PBot::Channels;
|
use PBot::Channels;
|
||||||
|
|
||||||
|
use PBot::BanTracker;
|
||||||
|
|
||||||
use PBot::LagChecker;
|
use PBot::LagChecker;
|
||||||
use PBot::AntiFlood;
|
use PBot::AntiFlood;
|
||||||
|
|
||||||
@ -115,6 +117,8 @@ sub initialize {
|
|||||||
$self->factoids->load_factoids() if defined $factoids_file;
|
$self->factoids->load_factoids() if defined $factoids_file;
|
||||||
$self->factoids->add_factoid('text', '.*', $self->{botnick}, 'version', "/say $VERSION");
|
$self->factoids->add_factoid('text', '.*', $self->{botnick}, 'version', "/say $VERSION");
|
||||||
|
|
||||||
|
$self->{bantracker} = PBot::BanTracker->new(pbot => $self);
|
||||||
|
|
||||||
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self);
|
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self);
|
||||||
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self);
|
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self);
|
||||||
|
|
||||||
@ -190,6 +194,8 @@ sub connect {
|
|||||||
$self->conn->add_handler('quit' , sub { $self->irchandlers->on_departure(@_) });
|
$self->conn->add_handler('quit' , sub { $self->irchandlers->on_departure(@_) });
|
||||||
$self->conn->add_handler('pong' , sub { $self->lagchecker->on_pong(@_) });
|
$self->conn->add_handler('pong' , sub { $self->lagchecker->on_pong(@_) });
|
||||||
$self->conn->add_handler('whoisaccount' , sub { $self->antiflood->on_whoisaccount(@_) });
|
$self->conn->add_handler('whoisaccount' , sub { $self->antiflood->on_whoisaccount(@_) });
|
||||||
|
$self->conn->add_handler('banlist' , sub { $self->bantracker->on_banlistentry(@_) });
|
||||||
|
$self->conn->add_handler('endofnames' , sub { $self->bantracker->get_banlist(@_) });
|
||||||
}
|
}
|
||||||
|
|
||||||
#main loop
|
#main loop
|
||||||
@ -331,6 +337,12 @@ sub ignorelist {
|
|||||||
return $self->{ignorelist};
|
return $self->{ignorelist};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub bantracker {
|
||||||
|
my $self = shift;
|
||||||
|
if(@_) { $self->{bantracker} = shift; }
|
||||||
|
return $self->{bantracker};
|
||||||
|
}
|
||||||
|
|
||||||
sub lagchecker {
|
sub lagchecker {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if(@_) { $self->{lagchecker} = shift; }
|
if(@_) { $self->{lagchecker} = shift; }
|
||||||
|
@ -13,8 +13,8 @@ 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 => 310,
|
BUILD_REVISION => 311,
|
||||||
BUILD_DATE => "2011-02-11",
|
BUILD_DATE => "2011-02-12",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user