3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Modify the syntax of the kick command (#10)

* Modify the syntax of the kick command

* Modify the syntax of the kick command

* Beautify helpful comment
This commit is contained in:
Krokodile Glue 2017-11-09 19:26:05 -08:00 committed by Pragmatic Software
parent efe5d838f7
commit 250337927b

View File

@ -18,7 +18,7 @@ use Time::Duration;
use PBot::Utils::ParseDate; use PBot::Utils::ParseDate;
sub new { sub new {
if(ref($_[1]) eq 'HASH') { if (ref($_[1]) eq 'HASH') {
Carp::croak("Options to ChanOpCommands should be key/value pairs, not hash reference"); Carp::croak("Options to ChanOpCommands should be key/value pairs, not hash reference");
} }
@ -33,12 +33,12 @@ sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
my $pbot = delete $conf{pbot}; my $pbot = delete $conf{pbot};
if(not defined $pbot) { if (not defined $pbot) {
Carp::croak("Missing pbot reference to ChanOpCommands"); Carp::croak("Missing pbot reference to ChanOpCommands");
} }
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->{commands}->register(sub { return $self->ban_user(@_) }, "ban", 10); $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->unban_user(@_) }, "unban", 10);
$pbot->{commands}->register(sub { return $self->mute_user(@_) }, "mute", 10); $pbot->{commands}->register(sub { return $self->mute_user(@_) }, "mute", 10);
@ -54,7 +54,7 @@ sub ban_user {
$channel = '' if not defined $channel; $channel = '' if not defined $channel;
$length = '' if not defined $length; $length = '' if not defined $length;
if(not defined $from) { if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -67,11 +67,11 @@ sub ban_user {
$channel = $from if not defined $channel or not length $channel; $channel = $from if not defined $channel or not length $channel;
if(not defined $target) { if (not defined $target) {
return "/msg $nick Usage: ban <mask> [channel [timeout (default: 24 hours)]]"; return "/msg $nick Usage: ban <mask> [channel [timeout (default: 24 hours)]]";
} }
if(not defined $length) { if (not defined $length) {
$length = 60 * 60 * 24; # 24 hours $length = 60 * 60 * 24; # 24 hours
} else { } else {
my $error; my $error;
@ -101,7 +101,7 @@ sub unban_user {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -114,7 +114,7 @@ sub unban_user {
$channel = $from if not defined $channel; $channel = $from if not defined $channel;
$immediately = 1 if not defined $immediately; $immediately = 1 if not defined $immediately;
return "/msg $nick Usage for /msg: unban <nick/mask> <channel> [true value to use unban queue]" if $channel !~ /^#/; return "/msg $nick Usage for /msg: unban <nick/mask> <channel> [true value to use unban queue]" if $channel !~ /^#/;
if (not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host")) { if (not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host")) {
@ -136,7 +136,7 @@ sub mute_user {
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my ($target, $channel, $length) = split(/\s+/, $arguments, 3); my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
if(not defined $from) { if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -157,11 +157,11 @@ sub mute_user {
return "/msg $nick Please specify a channel."; return "/msg $nick Please specify a channel.";
} }
if(not defined $target) { if (not defined $target) {
return "/msg $nick Usage: mute <mask> [channel [timeout (default: 24 hours)]]"; return "/msg $nick Usage: mute <mask> [channel [timeout (default: 24 hours)]]";
} }
if(not defined $length) { if (not defined $length) {
$length = 60 * 60 * 24; # 24 hours $length = 60 * 60 * 24; # 24 hours
} else { } else {
my $error; my $error;
@ -191,14 +191,14 @@ sub unmute_user {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
my ($target, $channel) = split /\s+/, $arguments; my ($target, $channel) = split /\s+/, $arguments;
if(not defined $target) { if (not defined $target) {
return "/msg $nick Usage: unmute <mask> [channel]"; return "/msg $nick Usage: unmute <mask> [channel]";
} }
@ -218,30 +218,38 @@ sub kick_user {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
my ($channel, $victim, $reason); my ($channel, $victim, $reason);
if(not $from =~ /^#/) { if (not $from =~ /^#/) {
# used in private message # used in private message
if(not $arguments =~ s/^(^#\S+) (\S+)\s*//) { if (not $arguments =~ s/^(^#\S+) (\S+)\s*//) {
return "/msg $nick Usage from private message: kick <channel> <nick> [reason]"; return "/msg $nick Usage from private message: kick <channel> <nick> [reason]";
} }
($channel, $victim) = ($1, $2); ($channel, $victim) = ($1, $2);
} else { } else {
# used in channel # used in channel
if(not $arguments =~ s/^(\S+)\s*//) { if ($arguments =~ s/^(#\S+)\s+(\S+)\s*//) {
return "/msg $nick Usage: kick <nick> [reason]"; ($channel, $victim) = ($1, $2);
} elsif ($arguments =~ s/^(\S+)\s*//) {
($victim, $channel) = ($1, $from);
} else {
return "/msg $nick Usage: kick [channel] <nick> [reason]";
} }
$victim = $1;
$channel = $from;
} }
$reason = $arguments; $reason = $arguments;
# If the user is too stupid to remember the order of the arguments,
# we can help them out by seeing if they put the channel in the reason.
if ($reason =~ s/^(#\S+)\s*//) {
$channel = $1;
}
if (not length $reason) { if (not length $reason) {
if (open my $fh, '<', $self->{pbot}->{registry}->get_value('general', 'module_dir') . '/insults.txt') { if (open my $fh, '<', $self->{pbot}->{registry}->get_value('general', 'module_dir') . '/insults.txt') {
my @insults = <$fh>; my @insults = <$fh>;
@ -259,6 +267,7 @@ sub kick_user {
$self->{pbot}->{chanops}->add_op_command($channel, "kick $channel $victim $reason"); $self->{pbot}->{chanops}->add_op_command($channel, "kick $channel $victim $reason");
$self->{pbot}->{chanops}->gain_ops($channel); $self->{pbot}->{chanops}->gain_ops($channel);
return ""; return "";
} }