From e5909965f70bcc5ae46da472c9fe399bf598aa36 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 27 Dec 2014 04:53:42 +0000 Subject: [PATCH] Move anti-away stuff to its own AntiAway.pm module; add /me actions to anti-away detection --- PBot/AntiAway.pm | 73 +++++++++++++++++++++++++++++++++++++++++++++++ PBot/AntiFlood.pm | 14 --------- PBot/PBot.pm | 2 ++ PBot/VERSION.pm | 4 +-- 4 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 PBot/AntiAway.pm diff --git a/PBot/AntiAway.pm b/PBot/AntiAway.pm new file mode 100644 index 00000000..d5b83933 --- /dev/null +++ b/PBot/AntiAway.pm @@ -0,0 +1,73 @@ +# File: AntiAway.pm +# Author: pragma_ +# +# Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes + +package PBot::AntiAway; + +use warnings; +use strict; + +use Data::Dumper; +use Carp (); + +sub new { + Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH'; + my ($class, %conf) = @_; + my $self = bless {}, $class; + $self->initialize(%conf); + return $self; +} + +sub initialize { + my ($self, %conf) = @_; + + $self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__); + + $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_nicks', $conf{bad_nicks} // '[[:punct:]](afk|away|sleep|z+|work|gone)[[:punct:]]*$'); + $self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me is away'); + $self->{pbot}->{registry}->add_default('text', 'antiaway', 'kick_msg', 'http://sackheads.org/~bnaylor/spew/away_msgs.html'); + + $self->{pbot}->{event_dispatcher}->register_handler('irc.nick', sub { $self->on_nickchange(@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) }); +} + +sub on_nickchange { + my ($self, $event_type, $event) = @_; + my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); + + my $bad_nicks = $self->{pbot}->{registry}->get_value('antiaway', 'bad_nicks'); + if($newnick =~ m/$bad_nicks/i) { + $self->{pbot}->{logger}->log("$newnick matches bad away nick regex, kicking...\n"); + my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg'); + my $channels = $self->{pbot}->{nicklist}->get_channels($newnick); + foreach my $chan (@$channels) { + $self->{pbot}->{chanops}->add_op_command($chan, "kick $chan $newnick $kick_msg"); + $self->{pbot}->{chanops}->gain_ops($chan); + } + } + + return 0; +} + +sub on_action { + my ($self, $event_type, $event) = @_; + my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{args}[0]); + + print "antiaway got action [$msg]\n"; + my $bad_actions = $self->{pbot}->{registry}->get_value('antiaway', 'bad_actions'); + print "antiaway got action [$msg]\nbad_actions: [$bad_actions]\n"; + if($msg =~ m/$bad_actions/i) { + $self->{pbot}->{logger}->log("$nick $msg matches bad away actions regex, kicking...\n"); + my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg'); + my $channels = $self->{pbot}->{nicklist}->get_channels($nick); + foreach my $chan (@$channels) { + $self->{pbot}->{chanops}->add_op_command($chan, "kick $chan $nick $kick_msg"); + $self->{pbot}->{chanops}->gain_ops($chan); + } + } + + return 0; +} + +1; diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index 30954347..7eb5290a 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -73,8 +73,6 @@ sub initialize { $self->{pbot}->{registry}->add_default('text', 'antiflood', 'debug_checkban', $conf{debug_checkban} // 0); - $self->{pbot}->{registry}->add_default('text', 'antiflood', 'bad_away_nicks', $conf{bad_away_nicks} // '[[:punct:]](afk|away|sleep|z+|work|gone)[[:punct:]]*$'); - $self->{pbot}->{commands}->register(sub { return $self->unbanme(@_) }, "unbanme", 0); $self->{pbot}->{commands}->register(sub { return $self->whitelist(@_) }, "whitelist", 10); @@ -200,18 +198,6 @@ sub check_flood { $self->{nickflood}->{$account}->{changes}++; } - - my $bad_away_nicks = $self->{pbot}->{registry}->get_value('antiflood', 'bad_away_nicks'); - if($newnick =~ m/$bad_away_nicks/i) { - $self->{pbot}->{logger}->log("$newnick matches bad away nick regex, kicking...\n"); - my @channels = $self->{pbot}->{messagehistory}->{database}->get_channels($account); - foreach my $chan (@channels) { - if($chan =~ m/^#/) { - $self->{pbot}->{chanops}->add_op_command($chan, "kick $chan $newnick No away nicks: http://sackheads.org/~bnaylor/spew/away_msgs.html"); - $self->{pbot}->{chanops}->gain_ops($chan); - } - } - } } else { $self->{pbot}->{logger}->log(sprintf("%-18s | %-65s | %s\n", lc $channel eq lc $mask ? "QUIT" : $channel, $mask, $text)); } diff --git a/PBot/PBot.pm b/PBot/PBot.pm index b82adb4c..cb247b61 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -46,6 +46,7 @@ use PBot::BotAdmins; use PBot::IgnoreList; use PBot::Quotegrabs; use PBot::Timer; +use PBot::AntiAway; sub new { if(ref($_[1]) eq 'HASH') { @@ -114,6 +115,7 @@ sub initialize { $self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self, %conf); $self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file}, %conf); $self->{chanops} = PBot::ChanOps->new(pbot => $self, %conf); + $self->{antiaway} = PBot::AntiAway->new(pbot => $self, %conf); $self->{interpreter} = PBot::Interpreter->new(pbot => $self, %conf); $self->{interpreter}->register(sub { return $self->{commands}->interpreter(@_); }); diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 35802937..36c19489 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 802, - BUILD_DATE => "2014-12-20", + BUILD_REVISION => 803, + BUILD_DATE => "2014-12-26", }; 1;