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;
|
|
|
|
|
|
|
|
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
|
|
|
use Carp ();
|
|
|
|
|
|
|
|
sub new {
|
2019-05-28 18:19:42 +02:00
|
|
|
if (ref($_[1]) eq 'HASH') {
|
2010-03-22 08:33:44 +01:00
|
|
|
Carp::croak("Options to IgnoreListCommands should be key/value pairs, not hash reference");
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
|
|
|
my $pbot = delete $conf{pbot};
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $pbot) {
|
2010-03-22 08:33:44 +01:00
|
|
|
Carp::croak("Missing pbot reference to IgnoreListCommands");
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$pbot->{commands}->register(sub { return $self->ignore_user(@_) }, "ignore", 10);
|
|
|
|
$pbot->{commands}->register(sub { return $self->unignore_user(@_) }, "unignore", 10);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ignore_user {
|
|
|
|
my $self = shift;
|
2018-08-09 02:38:57 +02:00
|
|
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-01-29 22:35:56 +01:00
|
|
|
return "Usage: ignore <hostmask> [channel [timeout]]" if not defined $arguments;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2018-08-09 02:38:57 +02:00
|
|
|
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $target) {
|
2020-01-29 22:35:56 +01:00
|
|
|
return "Usage: ignore <hostmask> [channel [timeout]]";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($target =~ /^list$/i) {
|
2010-03-22 08:33:44 +01:00
|
|
|
my $text = "Ignored: ";
|
|
|
|
my $sep = "";
|
|
|
|
|
2015-03-21 05:14:07 +01:00
|
|
|
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));
|
2012-09-06 12:09:44 +02:00
|
|
|
$sep = ";\n";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "/msg $nick $text";
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $channel) {
|
2010-03-22 08:33:44 +01:00
|
|
|
$channel = ".*"; # all channels
|
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $length) {
|
2012-09-06 12:09:44 +02:00
|
|
|
$length = -1; # permanently
|
2015-04-14 00:43:19 +02:00
|
|
|
} else {
|
|
|
|
my $error;
|
2019-06-07 06:46:00 +02:00
|
|
|
($length, $error) = $self->{pbot}->{parsedate}->parsedate($length);
|
2015-04-14 00:43:19 +02:00
|
|
|
return $error if defined $error;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{ignorelist}->add($target, $channel, $length);
|
2015-03-21 05:14:07 +01:00
|
|
|
|
|
|
|
if ($length >= 0) {
|
|
|
|
$length = "for " . duration($length);
|
|
|
|
} else {
|
|
|
|
$length = "permanently";
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 {
|
|
|
|
my $self = shift;
|
2018-08-09 02:38:57 +02:00
|
|
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
|
|
|
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $target) {
|
2020-01-29 22:35:56 +01:00
|
|
|
return "Usage: unignore <hostmask> [channel]";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not defined $channel) {
|
2010-03-22 08:33:44 +01:00
|
|
|
$channel = ".*";
|
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (exists $self->{pbot}->{ignorelist}->{ignore_list}->{$target} and not exists $self->{pbot}->{ignorelist}->{ignore_list}->{$target}->{$channel}) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick attempt to remove nonexistent [$target][$channel] from ignore list\n");
|
2015-03-17 05:08:25 +01:00
|
|
|
return "/msg $nick [$target][$channel] not found in ignore list (use `ignore list` to list ignores)";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{ignorelist}->remove($target, $channel);
|
|
|
|
$self->{pbot}->{logger}->log("$nick removed [$target][$channel] from ignore list\n");
|
2010-03-22 08:33:44 +01:00
|
|
|
return "/msg $nick [$target][$channel] unignored";
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|