2014-12-27 05:53:42 +01:00
|
|
|
# File: AntiAway.pm
|
|
|
|
#
|
|
|
|
# Purpose: Kicks people that visibly auto-away with ACTIONs or nick-changes
|
|
|
|
|
2021-07-11 00:00:22 +02:00
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
2017-03-05 22:33:31 +01:00
|
|
|
|
2021-07-14 04:45:56 +02:00
|
|
|
package PBot::Plugin::AntiAway;
|
|
|
|
use parent 'PBot::Plugin::Base';
|
2014-12-27 05:53:42 +01:00
|
|
|
|
2021-06-19 06:23:34 +02:00
|
|
|
use PBot::Imports;
|
2019-07-11 03:40:53 +02:00
|
|
|
|
2014-12-27 05:53:42 +01:00
|
|
|
sub initialize {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, %conf) = @_;
|
2023-01-31 14:44:34 +01:00
|
|
|
|
2020-04-29 06:33:49 +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:]]*$|.+\[.*\]$)'
|
|
|
|
);
|
2023-01-31 14:44:34 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'bad_actions', $conf{bad_actions} // '^/me (is (away|gone)|.*auto.?away)');
|
|
|
|
$self->{pbot}->{registry}->add_default('text', 'antiaway', 'kick_msg', 'http://sackheads.org/~bnaylor/spew/away_msgs.html');
|
2014-12-27 05:53:42 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.nick', sub { $self->on_nickchange(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) });
|
2014-12-27 05:53:42 +01:00
|
|
|
}
|
|
|
|
|
2020-02-07 21:24:21 +01:00
|
|
|
sub unload {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self) = @_;
|
|
|
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.nick');
|
|
|
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.caction');
|
2020-02-07 21:24:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 05:53:42 +01:00
|
|
|
sub on_nickchange {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2023-01-31 14:44:34 +01:00
|
|
|
|
|
|
|
my ($nick, $user, $host, $newnick) = (
|
|
|
|
$event->nick,
|
|
|
|
$event->user,
|
|
|
|
$event->host,
|
|
|
|
$event->args
|
|
|
|
);
|
2014-12-27 05:53:42 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my $bad_nicks = $self->{pbot}->{registry}->get_value('antiaway', 'bad_nicks');
|
2023-01-31 14:44:34 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($newnick =~ m/$bad_nicks/i) {
|
|
|
|
my $kick_msg = $self->{pbot}->{registry}->get_value('antiaway', 'kick_msg');
|
|
|
|
my $channels = $self->{pbot}->{nicklist}->get_channels($newnick);
|
2023-01-31 14:44:34 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
foreach my $chan (@$channels) {
|
|
|
|
next if not $self->{pbot}->{chanops}->can_gain_ops($chan);
|
2020-02-10 01:20:58 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my $u = $self->{pbot}->{users}->loggedin($chan, "$nick!$user\@$host");
|
|
|
|
next if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted');
|
2020-02-10 01:20:58 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{logger}->log("$newnick matches bad away nick regex, kicking from $chan\n");
|
|
|
|
$self->{pbot}->{chanops}->add_op_command($chan, "kick $chan $newnick $kick_msg");
|
|
|
|
$self->{pbot}->{chanops}->gain_ops($chan);
|
|
|
|
}
|
2014-12-27 05:53:42 +01:00
|
|
|
}
|
2020-02-15 23:38:32 +01:00
|
|
|
return 0;
|
2014-12-27 05:53:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_action {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2023-01-31 14:44:34 +01:00
|
|
|
|
|
|
|
my ($nick, $user, $host, $msg, $channel) = (
|
|
|
|
$event->nick,
|
|
|
|
$event->user,
|
|
|
|
$event->host,
|
|
|
|
$event->{args}[0],
|
|
|
|
$event->{to}[0],
|
|
|
|
);
|
2014-12-27 06:08:42 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
return 0 if $channel !~ /^#/;
|
|
|
|
return 0 if not $self->{pbot}->{chanops}->can_gain_ops($channel);
|
2014-12-27 05:53:42 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my $u = $self->{pbot}->{users}->loggedin($channel, "$nick!$user\@$host");
|
|
|
|
return 0 if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted');
|
2020-02-10 01:20:58 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my $bad_actions = $self->{pbot}->{registry}->get_value('antiaway', 'bad_actions');
|
2023-01-31 14:44:34 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
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');
|
|
|
|
$self->{pbot}->{chanops}->add_op_command($channel, "kick $channel $nick $kick_msg");
|
|
|
|
$self->{pbot}->{chanops}->gain_ops($channel);
|
|
|
|
}
|
|
|
|
return 0;
|
2014-12-27 05:53:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|