2010-03-22 08:33:44 +01:00
|
|
|
# File: IgnoreListCommands.pm
|
2010-03-24 07:47:40 +01:00
|
|
|
# Author: pragma_
|
2010-03-22 08:33:44 +01:00
|
|
|
#
|
|
|
|
# Purpose: Bot commands for interfacing with ignore list.
|
|
|
|
|
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::IgnoreListCommands;
|
2020-02-15 23:38:32 +01:00
|
|
|
|
2020-02-08 20:04:13 +01:00
|
|
|
use parent 'PBot::Class';
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-08 20:04:13 +01:00
|
|
|
use warnings; use strict;
|
2019-07-11 03:40:53 +02:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
use Time::HiRes qw(gettimeofday);
|
2015-03-21 05:14:07 +01:00
|
|
|
use Time::Duration;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
|
|
|
sub initialize {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, %conf) = @_;
|
|
|
|
$self->{pbot}->{commands}->register(sub { $self->ignore_user(@_) }, "ignore", 1);
|
|
|
|
$self->{pbot}->{commands}->register(sub { $self->unignore_user(@_) }, "unignore", 1);
|
|
|
|
$self->{pbot}->{capabilities}->add('admin', 'can-ignore', 1);
|
|
|
|
$self->{pbot}->{capabilities}->add('admin', 'can-unignore', 1);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ignore_user {
|
2020-02-15 23:38:32 +01:00
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
|
|
|
|
|
|
|
return "Usage: ignore <hostmask> [channel [timeout]]" if not defined $arguments;
|
|
|
|
|
|
|
|
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
|
|
|
|
|
|
|
if (not defined $target) { return "Usage: ignore <hostmask> [channel [timeout]]"; }
|
|
|
|
|
|
|
|
if ($target =~ /^list$/i) {
|
|
|
|
my $text = "Ignored: ";
|
|
|
|
my $sep = "";
|
|
|
|
|
|
|
|
foreach my $ignored (sort keys %{$self->{pbot}->{ignorelist}->{ignore_list}}) {
|
|
|
|
foreach my $channel (sort keys %{${$self->{pbot}->{ignorelist}->{ignore_list}}{$ignored}}) {
|
|
|
|
$text .=
|
|
|
|
$sep
|
|
|
|
. "$ignored [$channel] "
|
|
|
|
. (
|
|
|
|
$self->{pbot}->{ignorelist}->{ignore_list}->{$ignored}->{$channel} < 0
|
|
|
|
? "perm"
|
|
|
|
: duration($self->{pbot}->{ignorelist}->{ignore_list}->{$ignored}->{$channel} - gettimeofday)
|
|
|
|
);
|
|
|
|
$sep = ";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "/msg $nick $text";
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if (not defined $channel) {
|
|
|
|
$channel = ".*"; # all channels
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if (not defined $length) {
|
|
|
|
$length = -1; # permanently
|
|
|
|
} else {
|
|
|
|
my $error;
|
|
|
|
($length, $error) = $self->{pbot}->{parsedate}->parsedate($length);
|
|
|
|
return $error if defined $error;
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{ignorelist}->add($target, $channel, $length);
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($length >= 0) { $length = "for " . duration($length); }
|
|
|
|
else { $length = "permanently"; }
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{logger}->log("$nick added [$target][$channel] to ignore list $length\n");
|
|
|
|
return "/msg $nick [$target][$channel] added to ignore list $length";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub unignore_user {
|
2020-02-15 23:38:32 +01:00
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
|
|
|
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
|
|
|
|
|
|
|
if (not defined $target) { return "Usage: unignore <hostmask> [channel]"; }
|
|
|
|
|
|
|
|
if (not defined $channel) { $channel = ".*"; }
|
|
|
|
|
|
|
|
if (exists $self->{pbot}->{ignorelist}->{ignore_list}->{$target} and not exists $self->{pbot}->{ignorelist}->{ignore_list}->{$target}->{$channel}) {
|
|
|
|
$self->{pbot}->{logger}->log("$nick attempt to remove nonexistent [$target][$channel] from ignore list\n");
|
|
|
|
return "/msg $nick [$target][$channel] not found in ignore list (use `ignore list` to list ignores)";
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot}->{ignorelist}->remove($target, $channel);
|
|
|
|
$self->{pbot}->{logger}->log("$nick removed [$target][$channel] from ignore list\n");
|
|
|
|
return "/msg $nick [$target][$channel] unignored";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|