3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-25 04:02:37 +01:00

Add "forever" as valid parsedate option

`ban` command will not save ban to unban-timeouts if "forever" is used.
This commit is contained in:
Pragmatic Software 2015-05-06 21:13:39 -07:00
parent 3be6755a61
commit b5c10b73d9
3 changed files with 16 additions and 6 deletions

View File

@ -65,10 +65,16 @@ sub ban_user {
} }
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
return "" if $target =~ /\Q$botnick\E/i; return "I don't think so." if $target =~ /^\Q$botnick\E!/i;
$self->{pbot}->{chanops}->ban_user_timed($target, $channel, $length); $self->{pbot}->{chanops}->ban_user_timed($target, $channel, $length);
$length = duration($length);
if ($length > 0) {
$length = duration($length);
} else {
$length = 'all eternity';
}
return "/msg $nick $target banned in $channel for $length"; return "/msg $nick $target banned in $channel for $length";
} }

View File

@ -116,10 +116,12 @@ sub ban_user_timed {
my $self = shift; my $self = shift;
my ($mask, $channel, $length) = @_; my ($mask, $channel, $length) = @_;
$mask .= '!*@*' if $mask !~ m/[!@]/; $mask .= '!*@*' if $mask !~ m/[\$!@]/;
$self->ban_user($mask, $channel); $self->ban_user($mask, $channel);
$self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + $length; if ($length > 0) {
$self->{unban_timeout}->save; $self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + $length;
$self->{unban_timeout}->save;
}
} }
sub join_channel { sub join_channel {

View File

@ -20,7 +20,9 @@ sub parsedate {
my $seconds = 0; my $seconds = 0;
foreach my $input (@inputs) { foreach my $input (@inputs) {
return -1 if $input =~ m/forever/i;
$input .= ' seconds' if $input =~ m/^\d+$/; $input .= ' seconds' if $input =~ m/^\d+$/;
my $parse = Time::ParseDate::parsedate($input, NOW => $now); my $parse = Time::ParseDate::parsedate($input, NOW => $now);
if (not defined $parse) { if (not defined $parse) {
@ -30,7 +32,7 @@ sub parsedate {
} }
} }
return ($seconds, undef); return $seconds;
} }
1; 1;