3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

irchandlers: now handles multiple modes; e.g. -bbb-o

chanops: moved flushqueues to inside loop
anti-flood/bantracker: now tracks quiets as well as bans
anti-flood: should now ban proxied hosts using a banned nickserv account -- untested
This commit is contained in:
Pragmatic Software 2011-02-13 09:05:48 +00:00
parent b16b5f6275
commit ea198bcab1
5 changed files with 109 additions and 51 deletions

View File

@ -392,16 +392,32 @@ sub address_to_mask {
sub check_nickserv_accounts {
my ($self, $nick, $account) = @_;
my $banned_channel = undef;
foreach my $mask (keys %{ $self->{message_history} }) {
if(exists $self->{message_history}->{$mask}->{nickserv_account}) {
if(lc $self->{message_history}->{$mask}->{nickserv_account} eq lc $account) {
$self->{pbot}->logger->log("anti-flood: [check-account] $nick [nickserv: $account] seen previously as $mask.\n");
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
if(defined $baninfo) {
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask is banned in $baninfo->{channel} by $baninfo->{owner}\n");
$banned_channel = $baninfo->{channel};
}
}
}
else {
if($mask =~ m/^\Q$nick\E!/i) {
$self->{pbot}->logger->log("anti-flood: $mask: setting nickserv account to [$account]\n");
$self->message_history->{$mask}->{nickserv_account} = $account;
if(defined $banned_channel) {
my $banmask;
$mask =~ m/[^@]+\@(.*)/;
$banmask = "*!*\@$1";
$self->{pbot}->logger->log("anti-flood: [$account] is banned in $banned_channel, banning $banmask.\n");
$self->{pbot}->chanops->ban_user_timed($banmask, $banned_channel, 60 * 60 * 5);
}
}
}
}

View File

@ -56,7 +56,31 @@ sub get_banlist {
delete $self->{banlist}->{$channel};
$self->{pbot}->logger->log("Retrieving banlist for $channel.\n");
$conn->sl("mode $channel +b");
$conn->sl("mode $channel +bq");
}
sub get_baninfo {
my ($self, $mask) = @_;
$mask = quotemeta $mask;
$mask =~ s/\\\*/.*?/g;
$mask =~ s/\\\?/./g;
$self->{pbot}->logger->log("get-baninfo: mask regex: $mask\n");
foreach my $channel (keys %{ $self->{banlist} }) {
foreach my $banmask (keys %{ $self->{banlist}{$channel} }) {
if($banmask =~ m/$mask/i) {
my $baninfo = {};
$baninfo->{channel} = $channel;
$baninfo->{owner} = $self->{banlist}{$channel}[0];
return $baninfo;
}
}
}
return undef;
}
sub on_banlistentry {
@ -76,11 +100,11 @@ sub track_mode {
my $self = shift;
my ($source, $mode, $target, $channel) = @_;
if($mode eq "+b") {
if($mode eq "+b" or $mode eq "+q") {
$self->{pbot}->logger->log("ban-tracker: $target banned by $source in $channel.\n");
$self->{banlist}->{$channel}->{$target} = [ $source, gettimeofday ];
}
elsif($mode eq "-b") {
elsif($mode eq "-b" or $mode eq "-q") {
$self->{pbot}->logger->log("ban-tracker: $target unbanned by $source in $channel.\n");
delete $self->{banlist}->{$channel}->{$target};
} else {

View File

@ -75,9 +75,9 @@ sub perform_op_commands {
$self->{pbot}->logger->log(" executing kick on $1 $2 $3\n");
}
shift(@{ $self->{op_commands} });
}
$self->{pbot}->{irc}->flush_output_queue();
$self->{pbot}->{irc}->do_one_loop();
}
$self->{pbot}->logger->log("Done.\n");
}

View File

@ -116,14 +116,31 @@ sub on_action {
sub on_mode {
my ($self, $conn, $event) = @_;
my ($nick, $user, $host) = ($event->nick, $event->user, $event->host);
my $mode = $event->{args}[0];
my $target = $event->{args}[1];
my $mode_string = $event->{args}[0];
my $channel = $event->{to}[0];
$channel = lc $channel;
my ($mode, $modifier);
my $i = 0;
my $target;
use Data::Dumper;
print Dumper($event), "\n";
while($mode_string =~ m/(.)/g) {
my $char = $1;
if($char eq '-' or $char eq '+') {
$modifier = $char;
next;
}
$mode = $modifier . $char;
$target = $event->{args}[++$i];
$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") {
if($mode eq "-b" or $mode eq "+b" or $mode eq "-q" or $mode eq "+q") {
$self->{pbot}->bantracker->track_mode("$nick!$user\@$host", $mode, $target, $channel);
}
@ -171,6 +188,7 @@ sub on_mode {
$self->{pbot}->{joined_channels} = 1;
}
}
}
}
sub on_join {

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 312,
BUILD_REVISION => 313,
BUILD_DATE => "2011-02-13",
};