3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-27 06:19:25 +01:00

Make unmute and unban more smarter about argument order (#40)

* clean up unban and unmute

* unmute and unban are now smart about argument order
This commit is contained in:
k 2018-06-05 17:55:59 -07:00 committed by Pragmatic Software
parent 430017abf9
commit 9d8940fee2
2 changed files with 32 additions and 32 deletions

View File

@ -108,6 +108,12 @@ sub unban_user {
my ($target, $channel, $immediately) = split /\s+/, $arguments; my ($target, $channel, $immediately) = split /\s+/, $arguments;
if (defined $target and defined $channel and $channel !~ /^#/) {
my $temp = $target;
$target = $channel;
$channel = $temp;
}
if(not defined $target) { if(not defined $target) {
return "/msg $nick Usage: unban <mask> [[channel] [false value to use unban queue]]"; return "/msg $nick Usage: unban <mask> [[channel] [false value to use unban queue]]";
} }
@ -198,6 +204,12 @@ sub unmute_user {
my ($target, $channel) = split /\s+/, $arguments; my ($target, $channel) = split /\s+/, $arguments;
if (defined $target and defined $channel and $channel !~ /^#/) {
my $temp = $target;
$target = $channel;
$channel = $temp;
}
if (not defined $target) { if (not defined $target) {
return "/msg $nick Usage: unmute <mask> [channel]"; return "/msg $nick Usage: unmute <mask> [channel]";
} }

View File

@ -126,7 +126,7 @@ sub ban_user {
$self->gain_ops($channel); $self->gain_ops($channel);
} }
sub get_akas { sub get_bans {
my ($self, $mask, $channel) = @_; my ($self, $mask, $channel) = @_;
my $masks; my $masks;
@ -155,33 +155,41 @@ sub get_akas {
return $masks return $masks
} }
sub unban_user { sub unmode_user {
my $self = shift; my ($self, $mask, $channel, $immediately, $mode) = @_;
my ($mask, $channel, $immediately) = @_;
$mask = lc $mask; $mask = lc $mask;
$channel = lc $channel; $channel = lc $channel;
$self->{pbot}->{logger}->log("Unbanning $channel $mask\n"); $self->{pbot}->{logger}->log("Removing mode $mode from $mask in $channel\n");
my $bans = $self->get_akas($mask, $channel); my $bans = $self->get_bans($mask, $channel);
my %unbanned;
if (not defined $bans) { if (not defined $bans) {
my $baninfo = {}; my $baninfo = {};
$baninfo->{banmask} = $mask; $baninfo->{banmask} = $mask;
$baninfo->{type} = '+b'; $baninfo->{type} = '+' . $mode;
push @$bans, $baninfo; push @$bans, $baninfo;
} }
my %unbanned;
foreach my $baninfo (@$bans) { foreach my $baninfo (@$bans) {
next if $baninfo->{type} ne '+b'; next if $baninfo->{type} ne '+' . $mode;
next if exists $unbanned{$baninfo->{banmask}}; next if exists $unbanned{$baninfo->{banmask}};
$unbanned{$baninfo->{banmask}} = 1; $unbanned{$baninfo->{banmask}} = 1;
$self->add_to_unban_queue($channel, 'b', $baninfo->{banmask}); $self->add_to_unban_queue($channel, $mode, $baninfo->{banmask});
} }
$self->check_unban_queue if $immediately; $self->check_unban_queue if $immediately;
} }
sub unban_user {
my ($self, $mask, $channel, $immediately) = @_;
$mask = lc $mask;
$channel = lc $channel;
$self->{pbot}->{logger}->log("Unbanning $channel $mask\n");
$self->unmode_user($mask, $channel, $immediately, 'b');
}
sub ban_user_timed { sub ban_user_timed {
my $self = shift; my $self = shift;
my ($mask, $channel, $length) = @_; my ($mask, $channel, $length) = @_;
@ -224,31 +232,11 @@ sub mute_user {
} }
sub unmute_user { sub unmute_user {
my $self = shift; my ($self, $mask, $channel, $immediately) = @_;
my ($mask, $channel, $immediately) = @_;
$mask = lc $mask; $mask = lc $mask;
$channel = lc $channel; $channel = lc $channel;
$self->{pbot}->{logger}->log("Unmuting $channel $mask\n"); $self->{pbot}->{logger}->log("Unmuting $channel $mask\n");
$self->unmode_user($mask, $channel, $immediately, 'q');
my $mutes = $self->get_akas($mask, $channel);
if (not defined $mutes) {
my $muteinfo = {};
$muteinfo->{banmask} = $mask;
$muteinfo->{type} = '+q';
push @$mutes, $muteinfo;
}
my %unmutes;
foreach my $muteinfo (@$mutes) {
next if $muteinfo->{type} ne '+q';
next if exists $unmutes{$muteinfo->{banmask}};
$unmutes{$muteinfo->{banmask}} = 1;
$self->add_to_unban_queue($channel, 'q', $muteinfo->{banmask});
}
$self->check_unban_queue if $immediately;
} }
sub mute_user_timed { sub mute_user_timed {