2010-03-23 19:24:02 +01:00
|
|
|
# File: ChanOpCommands.pm
|
2010-03-24 07:47:40 +01:00
|
|
|
# Author: pragma_
|
2010-03-23 19:24:02 +01:00
|
|
|
#
|
|
|
|
# Purpose: Channel operator command subroutines.
|
|
|
|
|
|
|
|
package PBot::ChanOpCommands;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Carp ();
|
2015-04-12 01:00:20 +02:00
|
|
|
use Time::Duration;
|
2015-04-14 00:43:19 +02:00
|
|
|
|
|
|
|
use PBot::Utils::ParseDate;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
|
|
|
sub new {
|
|
|
|
if(ref($_[1]) eq 'HASH') {
|
|
|
|
Carp::croak("Options to ChanOpCommands 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 ChanOpCommands");
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot} = $pbot;
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$pbot->{commands}->register(sub { return $self->ban_user(@_) }, "ban", 10);
|
|
|
|
$pbot->{commands}->register(sub { return $self->unban_user(@_) }, "unban", 10);
|
|
|
|
$pbot->{commands}->register(sub { return $self->kick_user(@_) }, "kick", 10);
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:03:16 +02:00
|
|
|
sub ban_user {
|
2010-03-23 19:24:02 +01:00
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
2015-04-12 01:00:20 +02:00
|
|
|
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
2010-03-23 19:24:02 +01:00
|
|
|
|
2015-04-12 01:00:20 +02:00
|
|
|
if(not defined $from) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
2010-03-23 19:24:02 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-04-12 01:00:20 +02:00
|
|
|
$channel = $from if not defined $channel;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
|
|
|
if(not defined $target) {
|
2015-04-12 01:00:20 +02:00
|
|
|
return "/msg $nick Usage: ban <mask> [channel [timeout (default: 24 hours)]]";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(not defined $length) {
|
2015-04-12 01:00:20 +02:00
|
|
|
$length = 60 * 60 * 24; # 24 hours
|
|
|
|
} else {
|
2015-04-14 00:43:19 +02:00
|
|
|
my $error;
|
|
|
|
($length, $error) = parsedate($length);
|
|
|
|
return $error if defined $error;
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
2014-05-17 22:08:19 +02:00
|
|
|
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
|
|
|
return "" if $target =~ /\Q$botnick\E/i;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
2015-04-12 01:00:20 +02:00
|
|
|
$self->{pbot}->{chanops}->ban_user_timed($target, $channel, $length);
|
|
|
|
$length = duration($length);
|
|
|
|
return "/msg $nick $target banned in $channel for $length";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:03:16 +02:00
|
|
|
sub unban_user {
|
2010-03-23 19:24:02 +01:00
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
if(not defined $from) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
2010-03-23 19:24:02 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-04-03 21:49:41 +02:00
|
|
|
my ($target, $channel) = split / /, $arguments;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
2010-04-03 21:49:41 +02:00
|
|
|
if(not defined $target) {
|
2010-06-18 09:03:16 +02:00
|
|
|
return "/msg $nick Usage: unban <mask> [channel]";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
2010-04-03 21:49:41 +02:00
|
|
|
$channel = $from if not defined $channel;
|
|
|
|
|
2015-04-12 01:00:20 +02:00
|
|
|
return "/msg $nick Usage for /msg: unban $target <channel>" if $channel !~ /^#/;
|
2010-03-23 19:24:02 +01:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{chanops}->unban_user($target, $channel);
|
2011-10-31 20:56:08 +01:00
|
|
|
return "/msg $nick $target has been unbanned from $channel.";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub kick_user {
|
|
|
|
my $self = shift;
|
|
|
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
|
|
|
|
|
|
if(not defined $from) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
2010-03-23 19:24:02 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-04-19 12:35:27 +02:00
|
|
|
# used in private message
|
2010-03-23 19:24:02 +01:00
|
|
|
if(not $from =~ /^#/) {
|
2014-04-19 12:35:27 +02:00
|
|
|
if(not $arguments =~ /(^#\S+) (\S+) (.*)/) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host: invalid arguments to kick\n");
|
2014-04-19 12:35:27 +02:00
|
|
|
return "/msg $nick Usage from private message: kick <channel> <nick> <reason>";
|
|
|
|
}
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{chanops}->add_op_command($1, "kick $1 $2 $3");
|
|
|
|
$self->{pbot}->{chanops}->gain_ops($1);
|
2014-04-19 12:35:27 +02:00
|
|
|
return "/msg $nick Kicking $2 from $1 with reason '$3'";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
2014-04-19 12:35:27 +02:00
|
|
|
|
|
|
|
# used in channel
|
2010-03-23 19:24:02 +01:00
|
|
|
if(not $arguments =~ /(.*?) (.*)/) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host: invalid arguments to kick\n");
|
2014-04-19 12:35:27 +02:00
|
|
|
return "/msg $nick Usage: kick <nick> <reason>";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
2014-04-19 12:35:27 +02:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{chanops}->add_op_command($from, "kick $from $1 $2");
|
|
|
|
$self->{pbot}->{chanops}->gain_ops($from);
|
2014-04-21 09:26:06 +02:00
|
|
|
return "/msg $nick Kicking $1 from $from with reason '$2'";
|
2010-03-23 19:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|