2010-03-22 08:33:44 +01:00
|
|
|
# File: ChanOps.pm
|
2010-03-24 07:47:40 +01:00
|
|
|
# Author: pragma_
|
2010-03-22 08:33:44 +01:00
|
|
|
#
|
|
|
|
# Purpose: Provides channel operator status tracking and commands.
|
|
|
|
|
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/.
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
package PBot::ChanOps;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2019-07-11 03:40:53 +02:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2014-05-18 02:27:57 +02:00
|
|
|
use PBot::ChanOpCommands;
|
2010-03-22 08:33:44 +01:00
|
|
|
use Time::HiRes qw(gettimeofday);
|
2020-02-01 07:46:19 +01:00
|
|
|
use Time::Duration qw(concise duration);
|
2010-03-22 08:33:44 +01:00
|
|
|
|
|
|
|
sub new {
|
2020-02-04 02:19:04 +01:00
|
|
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref($_[1]) eq 'HASH';
|
2010-03-22 08:33:44 +01:00
|
|
|
my ($class, %conf) = @_;
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
2020-02-06 10:14:08 +01:00
|
|
|
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to ChanOps");
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2014-05-20 00:59:51 +02:00
|
|
|
$self->{unban_timeout} = PBot::DualIndexHashObject->new(
|
|
|
|
pbot => $self->{pbot},
|
|
|
|
name => 'Unban Timeouts',
|
|
|
|
filename => $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/unban_timeouts'
|
|
|
|
);
|
2014-05-17 22:08:19 +02:00
|
|
|
|
|
|
|
$self->{unban_timeout}->load;
|
|
|
|
|
2015-05-27 19:45:43 +02:00
|
|
|
$self->{unmute_timeout} = PBot::DualIndexHashObject->new(
|
|
|
|
pbot => $self->{pbot},
|
|
|
|
name => 'Unmute Timeouts',
|
|
|
|
filename => $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/unmute_timeouts'
|
|
|
|
);
|
|
|
|
|
|
|
|
$self->{unmute_timeout}->load;
|
|
|
|
|
2018-06-06 07:59:33 +02:00
|
|
|
$self->{ban_queue} = {};
|
2017-05-21 08:48:03 +02:00
|
|
|
$self->{unban_queue} = {};
|
|
|
|
|
2012-10-27 23:03:10 +02:00
|
|
|
$self->{op_commands} = {};
|
2010-03-22 08:33:44 +01:00
|
|
|
$self->{is_opped} = {};
|
2014-08-11 09:34:30 +02:00
|
|
|
$self->{op_requested} = {};
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2014-05-20 00:59:51 +02:00
|
|
|
$self->{commands} = PBot::ChanOpCommands->new(pbot => $self->{pbot});
|
|
|
|
|
2019-12-26 14:47:18 +01:00
|
|
|
$self->{pbot}->{registry}->add_default('text', 'general', 'deop_timeout', 300);
|
2014-05-18 02:27:57 +02:00
|
|
|
|
2015-05-27 19:45:43 +02:00
|
|
|
$self->{pbot}->{timer}->register(sub { $self->check_opped_timeouts }, 10);
|
|
|
|
$self->{pbot}->{timer}->register(sub { $self->check_unban_timeouts }, 10);
|
|
|
|
$self->{pbot}->{timer}->register(sub { $self->check_unmute_timeouts }, 10);
|
2017-05-21 11:18:00 +02:00
|
|
|
$self->{pbot}->{timer}->register(sub { $self->check_unban_queue }, 30);
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2015-06-26 05:54:38 +02:00
|
|
|
sub can_gain_ops {
|
|
|
|
my ($self, $channel) = @_;
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2020-01-15 03:10:53 +01:00
|
|
|
return exists $self->{pbot}->{channels}->{channels}->{hash}->{$channel}
|
|
|
|
&& $self->{pbot}->{channels}->{channels}->{hash}->{$channel}->{chanop}
|
|
|
|
&& $self->{pbot}->{channels}->{channels}->{hash}->{$channel}->{enabled};
|
2015-06-26 05:54:38 +02:00
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub gain_ops {
|
|
|
|
my $self = shift;
|
|
|
|
my $channel = shift;
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2018-06-06 00:02:02 +02:00
|
|
|
|
2014-08-11 09:34:30 +02:00
|
|
|
return if exists $self->{op_requested}->{$channel};
|
2015-06-26 05:54:38 +02:00
|
|
|
return if not $self->can_gain_ops($channel);
|
2014-08-11 09:34:30 +02:00
|
|
|
|
2019-12-26 14:47:18 +01:00
|
|
|
my $op_nick = $self->{pbot}->{registry}->get_value($channel, 'op_nick') //
|
|
|
|
$self->{pbot}->{registry}->get_value('general', 'op_nick') // 'chanserv';
|
|
|
|
|
|
|
|
my $op_command = $self->{pbot}->{registry}->get_value($channel, 'op_command') //
|
|
|
|
$self->{pbot}->{registry}->get_value('general', 'op_command') // "op $channel";
|
|
|
|
|
|
|
|
$op_command =~ s/\$channel\b/$channel/g;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not exists $self->{is_opped}->{$channel}) {
|
2019-12-26 14:47:18 +01:00
|
|
|
$self->{pbot}->{conn}->privmsg($op_nick, $op_command);
|
2014-08-11 09:34:30 +02:00
|
|
|
$self->{op_requested}->{$channel} = scalar gettimeofday;
|
2010-03-22 08:33:44 +01:00
|
|
|
} else {
|
2012-10-27 23:03:10 +02:00
|
|
|
$self->perform_op_commands($channel);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub lose_ops {
|
|
|
|
my $self = shift;
|
|
|
|
my $channel = shift;
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2019-12-26 14:47:18 +01:00
|
|
|
$self->{pbot}->{conn}->mode($channel, '-o ' . $self->{pbot}->{registry}->get_value('irc', 'botnick'));
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2014-04-19 12:38:16 +02:00
|
|
|
sub add_op_command {
|
|
|
|
my ($self, $channel, $command) = @_;
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2015-06-26 05:54:38 +02:00
|
|
|
return if not $self->can_gain_ops($channel);
|
2014-04-19 12:38:16 +02:00
|
|
|
push @{ $self->{op_commands}->{$channel} }, $command;
|
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub perform_op_commands {
|
|
|
|
my $self = shift;
|
2012-10-27 23:03:10 +02:00
|
|
|
my $channel = shift;
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2014-05-17 22:08:19 +02:00
|
|
|
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
2012-10-27 23:03:10 +02:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Performing op commands...\n");
|
2019-05-28 18:19:42 +02:00
|
|
|
while (my $command = shift @{ $self->{op_commands}->{$channel} }) {
|
|
|
|
if ($command =~ /^mode (.*?) (.*)/i) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{conn}->mode($1, $2);
|
2020-01-29 22:35:56 +01:00
|
|
|
$self->{pbot}->{logger}->log(" executing mode $1 $2\n");
|
2019-05-28 18:19:42 +02:00
|
|
|
} elsif ($command =~ /^kick (.*?) (.*?) (.*)/i) {
|
2019-12-29 08:20:55 +01:00
|
|
|
$self->{pbot}->{conn}->kick($1, $2, $3) unless $1 =~ /^\Q$botnick\E$/i;
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log(" executing kick on $1 $2 $3\n");
|
2019-12-29 08:17:15 +01:00
|
|
|
} elsif ($command =~ /^sl (.*)/i) {
|
|
|
|
$self->{pbot}->{conn}->sl($1);
|
|
|
|
$self->{pbot}->{logger}->log(" executing sl $1\n");
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Done.\n");
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:03:16 +02:00
|
|
|
sub ban_user {
|
2010-03-22 08:33:44 +01:00
|
|
|
my $self = shift;
|
2018-06-06 07:59:33 +02:00
|
|
|
my ($mask, $channel, $immediately) = @_;
|
2012-10-27 23:03:10 +02:00
|
|
|
|
2018-06-06 07:59:33 +02:00
|
|
|
$self->add_to_ban_queue($channel, 'b', $mask);
|
|
|
|
|
|
|
|
if (not defined $immediately or $immediately != 0) {
|
|
|
|
$self->check_ban_queue;
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 02:55:59 +02:00
|
|
|
sub get_bans {
|
2018-06-06 00:02:02 +02:00
|
|
|
my ($self, $mask, $channel) = @_;
|
|
|
|
my $masks;
|
2015-08-20 07:26:28 +02:00
|
|
|
|
2015-09-04 05:44:33 +02:00
|
|
|
if ($mask !~ m/[!@\$]/) {
|
2015-08-20 07:26:28 +02:00
|
|
|
my ($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($mask);
|
|
|
|
|
|
|
|
if (defined $hostmask) {
|
2015-08-22 20:05:53 +02:00
|
|
|
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account);
|
2018-06-06 00:02:02 +02:00
|
|
|
$masks = $self->{pbot}->{bantracker}->get_baninfo($hostmask, $channel, $nickserv);
|
2015-08-20 07:26:28 +02:00
|
|
|
}
|
2017-03-03 20:42:39 +01:00
|
|
|
|
|
|
|
my %akas = $self->{pbot}->{messagehistory}->{database}->get_also_known_as($mask);
|
|
|
|
|
|
|
|
foreach my $aka (keys %akas) {
|
|
|
|
next if $akas{$aka}->{type} == $self->{pbot}->{messagehistory}->{database}->{alias_type}->{WEAK};
|
|
|
|
next if $akas{$aka}->{nickchange} == 1;
|
|
|
|
|
|
|
|
my $b = $self->{pbot}->{bantracker}->get_baninfo($aka, $channel);
|
|
|
|
if (defined $b) {
|
2018-06-06 00:02:02 +02:00
|
|
|
$masks = {} if not defined $masks;
|
|
|
|
push @$masks, @$b;
|
2017-03-03 20:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-20 07:26:28 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 00:02:02 +02:00
|
|
|
return $masks
|
|
|
|
}
|
|
|
|
|
2018-06-06 02:55:59 +02:00
|
|
|
sub unmode_user {
|
|
|
|
my ($self, $mask, $channel, $immediately, $mode) = @_;
|
2018-06-06 00:02:02 +02:00
|
|
|
|
|
|
|
$mask = lc $mask;
|
|
|
|
$channel = lc $channel;
|
2018-06-06 02:55:59 +02:00
|
|
|
$self->{pbot}->{logger}->log("Removing mode $mode from $mask in $channel\n");
|
2018-06-06 00:02:02 +02:00
|
|
|
|
2018-06-06 02:55:59 +02:00
|
|
|
my $bans = $self->get_bans($mask, $channel);
|
|
|
|
my %unbanned;
|
2018-06-06 00:02:02 +02:00
|
|
|
|
2015-08-20 07:26:28 +02:00
|
|
|
if (not defined $bans) {
|
|
|
|
my $baninfo = {};
|
|
|
|
$baninfo->{banmask} = $mask;
|
2018-06-06 02:55:59 +02:00
|
|
|
$baninfo->{type} = '+' . $mode;
|
2015-08-20 07:26:28 +02:00
|
|
|
push @$bans, $baninfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $baninfo (@$bans) {
|
2018-06-06 02:55:59 +02:00
|
|
|
next if $baninfo->{type} ne '+' . $mode;
|
2017-03-03 20:42:39 +01:00
|
|
|
next if exists $unbanned{$baninfo->{banmask}};
|
|
|
|
$unbanned{$baninfo->{banmask}} = 1;
|
2018-06-06 02:55:59 +02:00
|
|
|
$self->add_to_unban_queue($channel, $mode, $baninfo->{banmask});
|
2013-07-24 14:35:40 +02:00
|
|
|
}
|
2018-06-06 02:55:59 +02:00
|
|
|
|
2017-08-04 08:19:02 +02:00
|
|
|
$self->check_unban_queue if $immediately;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 17:55:24 +02:00
|
|
|
sub nick_to_banmask {
|
|
|
|
my ($self, $mask) = @_;
|
2016-10-29 19:47:08 +02:00
|
|
|
|
2015-09-04 05:44:33 +02:00
|
|
|
if ($mask !~ m/[!@\$]/) {
|
2015-08-22 20:05:53 +02:00
|
|
|
my ($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($mask);
|
|
|
|
if (defined $hostmask) {
|
|
|
|
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account);
|
|
|
|
if (defined $nickserv && length $nickserv) {
|
|
|
|
$mask = '$a:' . $nickserv;
|
|
|
|
} else {
|
|
|
|
my ($nick, $user, $host) = $hostmask =~ m/([^!]+)!([^@]+)@(.*)/;
|
2020-01-26 06:09:17 +01:00
|
|
|
$mask = "*!$user\@" .$self->{pbot}->{antiflood}->address_to_mask($host);
|
2015-08-22 20:05:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$mask .= '!*@*';
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 17:55:24 +02:00
|
|
|
return $mask;
|
|
|
|
}
|
2015-08-22 20:05:53 +02:00
|
|
|
|
2019-07-23 17:55:24 +02:00
|
|
|
sub unban_user {
|
|
|
|
my ($self, $mask, $channel, $immediately) = @_;
|
|
|
|
$mask = lc $mask;
|
|
|
|
$channel = lc $channel;
|
|
|
|
$self->{pbot}->{logger}->log("Unbanning $channel $mask\n");
|
|
|
|
$self->unmode_user($mask, $channel, $immediately, 'b');
|
|
|
|
}
|
|
|
|
|
|
|
|
sub ban_user_timed {
|
|
|
|
my $self = shift;
|
2019-07-26 23:17:06 +02:00
|
|
|
my ($owner, $reason, $mask, $channel, $length, $immediately) = @_;
|
2019-07-23 17:55:24 +02:00
|
|
|
|
|
|
|
$channel = lc $channel;
|
|
|
|
$mask = lc $mask;
|
|
|
|
|
|
|
|
$mask = $self->nick_to_banmask($mask);
|
2018-06-06 07:59:33 +02:00
|
|
|
$self->ban_user($mask, $channel, $immediately);
|
|
|
|
|
2015-05-07 06:13:39 +02:00
|
|
|
if ($length > 0) {
|
2020-01-15 03:10:53 +01:00
|
|
|
my $data = {
|
|
|
|
timeout => gettimeofday + $length
|
|
|
|
};
|
|
|
|
$data->{owner} = $owner if defined $owner;
|
|
|
|
$data->{reason} = $reason if defined $reason;
|
|
|
|
$self->{unban_timeout}->add($channel, $mask, $data);
|
2015-06-08 03:02:35 +02:00
|
|
|
} else {
|
2020-01-15 03:10:53 +01:00
|
|
|
$self->{unban_timeout}->remove($channel, $mask);
|
2015-05-07 06:13:39 +02:00
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 07:46:19 +01:00
|
|
|
sub checkban {
|
|
|
|
my ($self, $channel, $target) = @_;
|
|
|
|
$channel = lc $channel;
|
|
|
|
$target = lc $target;
|
|
|
|
|
|
|
|
my $mask = lc $self->nick_to_banmask($target);
|
|
|
|
|
|
|
|
if (exists $self->{unban_timeout}->{hash}->{$channel}
|
|
|
|
&& exists $self->{unban_timeout}->{hash}->{$channel}->{$mask}) {
|
|
|
|
my $timeout = $self->{unban_timeout}->{hash}->{$channel}->{$mask}->{timeout};
|
|
|
|
my $owner = $self->{unban_timeout}->{hash}->{$channel}->{$mask}->{owner};
|
|
|
|
my $reason = $self->{unban_timeout}->{hash}->{$channel}->{$mask}->{reason};
|
|
|
|
my $duration = concise duration($timeout - gettimeofday);
|
|
|
|
|
|
|
|
my $result = "$mask banned in $channel ";
|
|
|
|
$result .= "by $owner " if defined $owner;
|
|
|
|
$result .= "for $reason " if defined $reason;
|
|
|
|
$result .= "($duration remaining)";
|
|
|
|
return $result;
|
|
|
|
} else {
|
|
|
|
return "$mask has no ban timeout.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:45:43 +02:00
|
|
|
sub mute_user {
|
|
|
|
my $self = shift;
|
2018-06-06 07:59:33 +02:00
|
|
|
my ($mask, $channel, $immediately) = @_;
|
2015-05-27 19:45:43 +02:00
|
|
|
|
2018-06-06 07:59:33 +02:00
|
|
|
$self->add_to_ban_queue($channel, 'q', $mask);
|
|
|
|
|
|
|
|
if (not defined $immediately or $immediately != 0) {
|
|
|
|
$self->check_ban_queue;
|
|
|
|
}
|
2015-05-27 19:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub unmute_user {
|
2018-06-06 02:55:59 +02:00
|
|
|
my ($self, $mask, $channel, $immediately) = @_;
|
2016-10-29 19:47:08 +02:00
|
|
|
$mask = lc $mask;
|
|
|
|
$channel = lc $channel;
|
2015-05-27 19:45:43 +02:00
|
|
|
$self->{pbot}->{logger}->log("Unmuting $channel $mask\n");
|
2018-06-06 02:55:59 +02:00
|
|
|
$self->unmode_user($mask, $channel, $immediately, 'q');
|
2015-05-27 19:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub mute_user_timed {
|
|
|
|
my $self = shift;
|
2019-07-26 23:17:06 +02:00
|
|
|
my ($owner, $reason, $mask, $channel, $length, $immediately) = @_;
|
2015-05-27 19:45:43 +02:00
|
|
|
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
|
|
|
$mask = lc $mask;
|
|
|
|
|
2019-07-23 17:55:24 +02:00
|
|
|
$mask = $self->nick_to_banmask($mask);
|
2018-06-06 07:59:33 +02:00
|
|
|
$self->mute_user($mask, $channel, $immediately);
|
2019-07-23 17:55:24 +02:00
|
|
|
|
2015-05-27 19:45:43 +02:00
|
|
|
if ($length > 0) {
|
2020-01-15 03:10:53 +01:00
|
|
|
my $data = {
|
|
|
|
timeout => gettimeofday + $length
|
|
|
|
};
|
|
|
|
$data->{owner} = $owner if defined $owner;
|
|
|
|
$data->{reason} = $reason if defined $reason;
|
|
|
|
$self->{unmute_timeout}->add($channel, $mask, $data);
|
2015-06-08 03:02:35 +02:00
|
|
|
} else {
|
2020-01-15 03:10:53 +01:00
|
|
|
$self->{unmute_timeout}->remove($channel, $mask);
|
2015-05-27 19:45:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 07:46:19 +01:00
|
|
|
sub checkmute {
|
|
|
|
my ($self, $channel, $target) = @_;
|
|
|
|
|
|
|
|
$channel = lc $channel;
|
|
|
|
$target = lc $target;
|
|
|
|
|
|
|
|
my $mask = lc $self->nick_to_banmask($target);
|
|
|
|
|
|
|
|
if (exists $self->{unmute_timeout}->{hash}->{$channel}
|
|
|
|
&& exists $self->{unmute_timeout}->{hash}->{$channel}->{$mask}) {
|
|
|
|
my $timeout = $self->{unmute_timeout}->{hash}->{$channel}->{$mask}->{timeout};
|
|
|
|
my $owner = $self->{unmute_timeout}->{hash}->{$channel}->{$mask}->{owner};
|
|
|
|
my $reason = $self->{unmute_timeout}->{hash}->{$channel}->{$mask}->{reason};
|
|
|
|
my $duration = concise duration($timeout - gettimeofday);
|
|
|
|
|
|
|
|
my $result = "$mask muted in $channel ";
|
|
|
|
$result .= "by $owner " if defined $owner;
|
|
|
|
$result .= "for $reason " if defined $reason;
|
|
|
|
$result .= "($duration remaining)";
|
|
|
|
|
2020-02-01 10:03:16 +01:00
|
|
|
return $result;
|
2020-02-01 07:46:19 +01:00
|
|
|
} else {
|
|
|
|
return "$mask has no mute timeout.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 09:46:13 +01:00
|
|
|
sub join_channel {
|
2015-07-29 02:47:22 +02:00
|
|
|
my ($self, $channels) = @_;
|
2014-12-18 09:46:13 +01:00
|
|
|
|
2015-07-29 02:47:22 +02:00
|
|
|
$self->{pbot}->{conn}->join($channels);
|
2014-12-18 09:46:13 +01:00
|
|
|
|
2015-07-29 02:47:22 +02:00
|
|
|
foreach my $channel (split /,/, $channels) {
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
2015-07-29 02:47:22 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $channel });
|
2014-12-18 09:46:13 +01:00
|
|
|
|
2015-07-29 02:47:22 +02:00
|
|
|
delete $self->{is_opped}->{$channel};
|
|
|
|
delete $self->{op_requested}->{$channel};
|
|
|
|
|
2020-01-15 03:10:53 +01:00
|
|
|
if (exists $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}
|
|
|
|
and $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}->{permop}) {
|
2015-07-29 02:47:22 +02:00
|
|
|
$self->gain_ops($channel);
|
|
|
|
}
|
2018-08-06 07:47:38 +02:00
|
|
|
|
|
|
|
$self->{pbot}->{conn}->mode($channel);
|
2014-12-18 09:46:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub part_channel {
|
|
|
|
my ($self, $channel) = @_;
|
|
|
|
|
2016-10-29 19:47:08 +02:00
|
|
|
$channel = lc $channel;
|
|
|
|
|
2014-12-18 09:46:13 +01:00
|
|
|
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.part', { channel => $channel });
|
|
|
|
$self->{pbot}->{conn}->part($channel);
|
|
|
|
|
|
|
|
delete $self->{is_opped}->{$channel};
|
|
|
|
delete $self->{op_requested}->{$channel};
|
|
|
|
}
|
|
|
|
|
2015-06-26 05:54:38 +02:00
|
|
|
sub has_ban_timeout {
|
|
|
|
my ($self, $channel, $mask) = @_;
|
2020-01-15 03:10:53 +01:00
|
|
|
return exists $self->{unban_timeout}->{hash}->{lc $channel}->{lc $mask};
|
2015-06-26 05:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub has_mute_timeout {
|
|
|
|
my ($self, $channel, $mask) = @_;
|
2020-01-15 03:10:53 +01:00
|
|
|
return exists $self->{unmute_timeout}->{hash}->{lc $channel}->{lc $mask};
|
2015-06-26 05:54:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 07:59:33 +02:00
|
|
|
sub add_to_ban_queue {
|
|
|
|
my ($self, $channel, $mode, $target) = @_;
|
|
|
|
push @{$self->{ban_queue}->{$channel}->{$mode}}, $target;
|
|
|
|
$self->{pbot}->{logger}->log("Added +$mode $target for $channel to ban queue.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_ban_queue {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $MAX_COMMANDS = 4;
|
|
|
|
my $commands = 0;
|
|
|
|
|
|
|
|
foreach my $channel (keys %{$self->{ban_queue}}) {
|
|
|
|
my $done = 0;
|
|
|
|
while (not $done) {
|
|
|
|
my ($list, $count, $modes);
|
|
|
|
$list = '';
|
|
|
|
$modes = '+';
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach my $mode (keys %{$self->{ban_queue}->{$channel}}) {
|
|
|
|
while (@{$self->{ban_queue}->{$channel}->{$mode}}) {
|
|
|
|
my $target = pop @{$self->{ban_queue}->{$channel}->{$mode}};
|
|
|
|
$list .= " $target";
|
|
|
|
$modes .= $mode;
|
|
|
|
last if ++$count >= $self->{pbot}->{ircd}->{MODES};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not @{$self->{ban_queue}->{$channel}->{$mode}}) {
|
|
|
|
delete $self->{ban_queue}->{$channel}->{$mode};
|
|
|
|
}
|
|
|
|
|
|
|
|
last if $count >= $self->{pbot}->{ircd}->{MODES};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not keys %{ $self->{ban_queue}->{$channel} }) {
|
|
|
|
delete $self->{ban_queue}->{$channel};
|
|
|
|
$done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($count) {
|
|
|
|
$self->add_op_command($channel, "mode $channel $modes $list");
|
|
|
|
$self->gain_ops($channel);
|
|
|
|
|
|
|
|
return if ++$commands >= $MAX_COMMANDS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-21 08:48:03 +02:00
|
|
|
sub add_to_unban_queue {
|
|
|
|
my ($self, $channel, $mode, $target) = @_;
|
|
|
|
push @{$self->{unban_queue}->{$channel}->{$mode}}, $target;
|
|
|
|
$self->{pbot}->{logger}->log("Added -$mode $target for $channel to unban queue.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_unban_queue {
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-08-03 22:30:42 +02:00
|
|
|
my $MAX_COMMANDS = 4;
|
|
|
|
my $commands = 0;
|
|
|
|
|
2017-05-21 08:48:03 +02:00
|
|
|
foreach my $channel (keys %{$self->{unban_queue}}) {
|
2017-08-03 22:30:42 +02:00
|
|
|
my $done = 0;
|
|
|
|
while (not $done) {
|
|
|
|
my ($list, $count, $modes);
|
|
|
|
$list = '';
|
|
|
|
$modes = '-';
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach my $mode (keys %{$self->{unban_queue}->{$channel}}) {
|
|
|
|
while (@{$self->{unban_queue}->{$channel}->{$mode}}) {
|
|
|
|
my $target = pop @{$self->{unban_queue}->{$channel}->{$mode}};
|
|
|
|
$list .= " $target";
|
|
|
|
$modes .= $mode;
|
|
|
|
last if ++$count >= $self->{pbot}->{ircd}->{MODES};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not @{$self->{unban_queue}->{$channel}->{$mode}}) {
|
|
|
|
delete $self->{unban_queue}->{$channel}->{$mode};
|
|
|
|
}
|
|
|
|
|
|
|
|
last if $count >= $self->{pbot}->{ircd}->{MODES};
|
2017-05-21 08:48:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-09 10:22:13 +02:00
|
|
|
if (not keys %{ $self->{unban_queue}->{$channel} }) {
|
2017-08-03 22:30:42 +02:00
|
|
|
delete $self->{unban_queue}->{$channel};
|
|
|
|
$done = 1;
|
2017-05-21 08:48:03 +02:00
|
|
|
}
|
2017-05-21 11:18:00 +02:00
|
|
|
|
2017-08-03 22:30:42 +02:00
|
|
|
if ($count) {
|
|
|
|
$self->add_op_command($channel, "mode $channel $modes $list");
|
|
|
|
$self->gain_ops($channel);
|
2017-05-21 08:48:03 +02:00
|
|
|
|
2017-08-03 22:30:42 +02:00
|
|
|
return if ++$commands >= $MAX_COMMANDS;
|
|
|
|
}
|
2017-05-21 11:18:00 +02:00
|
|
|
}
|
2017-05-21 08:48:03 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-26 05:54:38 +02:00
|
|
|
|
2010-06-18 09:03:16 +02:00
|
|
|
sub check_unban_timeouts {
|
2010-03-22 08:33:44 +01:00
|
|
|
my $self = shift;
|
2010-06-18 12:46:23 +02:00
|
|
|
|
|
|
|
return if not $self->{pbot}->{joined_channels};
|
|
|
|
|
2010-03-23 19:24:02 +01:00
|
|
|
my $now = gettimeofday();
|
|
|
|
|
2020-01-15 03:10:53 +01:00
|
|
|
foreach my $channel (keys %{ $self->{unban_timeout}->{hash} }) {
|
|
|
|
foreach my $mask (keys %{ $self->{unban_timeout}->{hash}->{$channel} }) {
|
|
|
|
next if $mask eq '_name';
|
|
|
|
if ($self->{unban_timeout}->{hash}->{$channel}->{$mask}->{timeout} < $now) {
|
|
|
|
$self->{unban_timeout}->{hash}->{$channel}->{$mask}->{timeout} = $now + 7200;
|
2013-07-24 14:35:40 +02:00
|
|
|
$self->unban_user($mask, $channel);
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:45:43 +02:00
|
|
|
sub check_unmute_timeouts {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return if not $self->{pbot}->{joined_channels};
|
|
|
|
|
|
|
|
my $now = gettimeofday();
|
|
|
|
|
2020-01-15 03:10:53 +01:00
|
|
|
foreach my $channel (keys %{ $self->{unmute_timeout}->{hash} }) {
|
|
|
|
foreach my $mask (keys %{ $self->{unmute_timeout}->{hash}->{$channel} }) {
|
|
|
|
next if $mask eq '_name';
|
|
|
|
if ($self->{unmute_timeout}->{hash}->{$channel}->{$mask}->{timeout} < $now) {
|
|
|
|
$self->{unmute_timeout}->{hash}->{$channel}->{$mask}->{timeout} = $now + 7200;
|
2015-05-27 19:45:43 +02:00
|
|
|
$self->unmute_user($mask, $channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 19:24:02 +01:00
|
|
|
sub check_opped_timeouts {
|
2010-03-22 08:33:44 +01:00
|
|
|
my $self = shift;
|
2010-03-23 19:24:02 +01:00
|
|
|
my $now = gettimeofday();
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2010-03-23 19:24:02 +01:00
|
|
|
foreach my $channel (keys %{ $self->{is_opped} }) {
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($self->{is_opped}->{$channel}{timeout} < $now) {
|
2020-01-15 03:10:53 +01:00
|
|
|
unless (exists $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}
|
|
|
|
and $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}->{permop}) {
|
2014-12-18 09:46:13 +01:00
|
|
|
$self->lose_ops($channel);
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:34:30 +02:00
|
|
|
|
|
|
|
foreach my $channel (keys %{ $self->{op_requested} }) {
|
|
|
|
if ($now - $self->{op_requested}->{$channel} > 60 * 5) {
|
2020-01-15 03:10:53 +01:00
|
|
|
if (exists $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}
|
|
|
|
and $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}->{enabled}) {
|
2019-04-25 23:11:54 +02:00
|
|
|
$self->{pbot}->{logger}->log("5 minutes since OP request for $channel and no OP yet; trying again ...\n");
|
|
|
|
delete $self->{op_requested}->{$channel};
|
|
|
|
$self->gain_ops($channel);
|
|
|
|
} else {
|
|
|
|
$self->{pbot}->{logger}->log("Disregarding OP request for $channel (channel is disabled)\n");
|
|
|
|
delete $self->{op_requested}->{$channel};
|
|
|
|
}
|
2014-08-11 09:34:30 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|