mirror of
https://github.com/pragma-/pbot.git
synced 2024-10-09 04:48:43 +02:00
d955bfa06c
Allows changing of bot configuration values without needing to restart bot instance or needing to edit pbot.pl script. Registry will initially be populated with default values from pbot.pl, but if a registry file exists then the registry values will take precedence over the pbot.pl values. For instance, if you regset the bot trigger to '%' then the trigger will be '%' even if pbot.pl has '!' or something else explicitly set. Some registry items can have trigger hooks associated with them. For instance, the irc->botnick registry entry has a change_botnick_trigger associated with it which changes the IRC nick on the server when a new value is set via regset/regadd. Tons of other fixes and improvements throughout.
102 lines
2.9 KiB
Perl
102 lines
2.9 KiB
Perl
# File: IgnoreListCommands.pm
|
|
# Author: pragma_
|
|
#
|
|
# Purpose: Bot commands for interfacing with ignore list.
|
|
|
|
package PBot::IgnoreListCommands;
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
use Carp ();
|
|
|
|
sub new {
|
|
if(ref($_[1]) eq 'HASH') {
|
|
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};
|
|
if(not defined $pbot) {
|
|
Carp::croak("Missing pbot reference to IgnoreListCommands");
|
|
}
|
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
$pbot->commands->register(sub { return $self->ignore_user(@_) }, "ignore", 10);
|
|
$pbot->commands->register(sub { return $self->unignore_user(@_) }, "unignore", 10);
|
|
}
|
|
|
|
sub ignore_user {
|
|
my $self = shift;
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
return "/msg $nick Usage: ignore nick!user\@host [channel] [timeout]" if not defined $arguments;
|
|
|
|
my ($target, $channel, $length) = split /\s+/, $arguments;
|
|
|
|
if(not defined $target) {
|
|
return "/msg $nick Usage: ignore host [channel] [timeout]";
|
|
}
|
|
|
|
if($target =~ /^list$/i) {
|
|
my $text = "Ignored: ";
|
|
my $sep = "";
|
|
|
|
foreach my $ignored (keys %{ $self->{pbot}->ignorelist->{ignore_list} }) {
|
|
foreach my $channel (keys %{ ${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored} }) {
|
|
$text .= $sep . "[$ignored]->[$channel]->[" . (${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored}{$channel} == -1 ? -1 : int(gettimeofday - ${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored}{$channel})) . "]";
|
|
$sep = ";\n";
|
|
}
|
|
}
|
|
return "/msg $nick $text";
|
|
}
|
|
|
|
if(not defined $channel) {
|
|
$channel = ".*"; # all channels
|
|
}
|
|
|
|
if(not defined $length) {
|
|
$length = -1; # permanently
|
|
}
|
|
|
|
$self->{pbot}->logger->log("$nick added [$target][$channel] to ignore list for $length seconds\n");
|
|
$self->{pbot}->ignorelist->add($target, $channel, $length);
|
|
return "/msg $nick [$target][$channel] added to ignore list for $length seconds";
|
|
}
|
|
|
|
sub unignore_user {
|
|
my $self = shift;
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
my ($target, $channel) = split /\s+/, $arguments if defined $arguments;
|
|
|
|
if(not defined $target) {
|
|
return "/msg $nick Usage: unignore host [channel]";
|
|
}
|
|
|
|
if(not defined $channel) {
|
|
$channel = ".*";
|
|
}
|
|
|
|
if(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";
|
|
}
|
|
|
|
1;
|