2014-12-27 05:53:42 +01:00
|
|
|
# File: AntiAway.pm
|
|
|
|
# Author: pragma_
|
|
|
|
#
|
|
|
|
# Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes
|
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-09-01 20:01:18 +02:00
|
|
|
package Plugins::AntiAway;
|
2014-12-27 05:53:42 +01:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2019-07-11 03:40:53 +02:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2014-12-27 05:53:42 +01:00
|
|
|
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__);
|
|
|
|
|
2015-07-02 00:18:55 +02:00
|
|
|
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_nicks', $conf{bad_nicks} // '([[:punct:]](afk|brb|bbl|away|sleep|z+|work|gone|study|out|home|busy|off)[[:punct:]]*$|.+\[.*\]$)');
|
2015-02-14 13:02:13 +01:00
|
|
|
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me (is (away|gone)|.*auto.?away)');
|
2014-12-27 05:53:42 +01:00
|
|
|
$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');
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($newnick =~ m/$bad_nicks/i) {
|
2014-12-27 05:53:42 +01:00
|
|
|
my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg');
|
|
|
|
my $channels = $self->{pbot}->{nicklist}->get_channels($newnick);
|
|
|
|
foreach my $chan (@$channels) {
|
2020-01-15 03:10:53 +01:00
|
|
|
next if not exists $self->{pbot}->{channels}->{channels}->{hash}->{$chan} or not $self->{pbot}->{channels}->{channels}->{hash}->{$chan}->{chanop};
|
2015-06-20 16:24:13 +02:00
|
|
|
$self->{pbot}->{logger}->log("$newnick matches bad away nick regex, kicking from $chan\n");
|
2014-12-27 05:53:42 +01:00
|
|
|
$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) = @_;
|
2014-12-27 06:08:42 +01:00
|
|
|
my ($nick, $user, $host, $msg, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{args}[0], $event->{event}->{to}[0]);
|
|
|
|
|
|
|
|
return 0 if $channel !~ /^#/;
|
2015-06-26 05:55:42 +02:00
|
|
|
return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel);
|
2014-12-27 05:53:42 +01:00
|
|
|
|
|
|
|
my $bad_actions = $self->{pbot}->{registry}->get_value('antiaway', 'bad_actions');
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($msg =~ m/$bad_actions/i) {
|
2014-12-27 05:53:42 +01:00
|
|
|
$self->{pbot}->{logger}->log("$nick $msg matches bad away actions regex, kicking...\n");
|
|
|
|
my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg');
|
2014-12-27 06:08:42 +01:00
|
|
|
$self->{pbot}->{chanops}->add_op_command($channel, "kick $channel $nick $kick_msg");
|
|
|
|
$self->{pbot}->{chanops}->gain_ops($channel);
|
2014-12-27 05:53:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|