From 2746c14f7cf0c686abf9515c875e7ad02f53a820 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 3 Aug 2017 13:30:42 -0700 Subject: [PATCH] Improved unban queue handling --- PBot/ChanOpCommands.pm | 4 +-- PBot/ChanOps.pm | 72 +++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index b8c67141..24d82eba 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -112,7 +112,7 @@ sub unban_user { return "/msg $nick Usage for /msg: unban " if $channel !~ /^#/; - $self->{pbot}->{chanops}->unban_user($target, $channel, 1); + $self->{pbot}->{chanops}->unban_user($target, $channel); return "/msg $nick $target has been unbanned from $channel."; } @@ -187,7 +187,7 @@ sub unmute_user { return "/msg $nick Usage for /msg: unmute " if $channel !~ /^#/; - $self->{pbot}->{chanops}->unmute_user($target, $channel, 1); + $self->{pbot}->{chanops}->unmute_user($target, $channel); return "/msg $nick $target has been unmuted in $channel."; } diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index 363570e9..6a2de9f3 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -128,7 +128,7 @@ sub ban_user { sub unban_user { my $self = shift; - my ($mask, $channel, $immediately) = @_; + my ($mask, $channel) = @_; my $bans; @@ -166,14 +166,9 @@ sub unban_user { next if $baninfo->{type} ne '+b'; next if exists $unbanned{$baninfo->{banmask}}; $unbanned{$baninfo->{banmask}} = 1; - - if ($immediately) { - $self->add_op_command($channel, "mode $channel -b $baninfo->{banmask}"); - $self->gain_ops($channel); - } else { - $self->add_to_unban_queue($channel, 'b', $baninfo->{banmask}); - } + $self->add_to_unban_queue($channel, 'b', $baninfo->{banmask}); } + $self->check_unban_queue; } sub ban_user_timed { @@ -219,7 +214,7 @@ sub mute_user { sub unmute_user { my $self = shift; - my ($mask, $channel, $immediately) = @_; + my ($mask, $channel) = @_; $mask = lc $mask; $channel = lc $channel; $self->{pbot}->{logger}->log("Unmuting $channel $mask\n"); @@ -229,12 +224,8 @@ sub unmute_user { $self->{unmute_timeout}->save; } - if ($immediately) { - $self->add_op_command($channel, "mode $channel -q $mask"); - $self->gain_ops($channel); - } else { - $self->add_to_unban_queue($channel, 'q', $mask); - } + $self->add_to_unban_queue($channel, 'q', $mask); + $self->check_unban_queue; } sub mute_user_timed { @@ -307,34 +298,43 @@ sub add_to_unban_queue { sub check_unban_queue { my $self = shift; + my $MAX_COMMANDS = 4; + my $commands = 0; + foreach my $channel (keys %{$self->{unban_queue}}) { - my ($list, $count, $modes); - $list = ''; - $modes = '-'; - $count = 0; + my $done = 0; + while (not $done) { + my ($list, $count, $modes); + $list = ''; + $modes = '-'; + $count = 0; - foreach my $mode (keys %{$self->{unban_queue}->{$channel}}) { - while (@{$self->{unban_queue}->{$channel}->{$mode}}) { - my $target = pop @{$self->{unban_queue}->{$channel}->{$mode}}; - $list .= " $target"; - $modes .= $mode; - last if ++$count >= $self->{pbot}->{ircd}->{MODES}; + foreach my $mode (keys %{$self->{unban_queue}->{$channel}}) { + while (@{$self->{unban_queue}->{$channel}->{$mode}}) { + my $target = pop @{$self->{unban_queue}->{$channel}->{$mode}}; + $list .= " $target"; + $modes .= $mode; + last if ++$count >= $self->{pbot}->{ircd}->{MODES}; + } + + if (not @{$self->{unban_queue}->{$channel}->{$mode}}) { + delete $self->{unban_queue}->{$channel}->{$mode}; + } + + last if $count >= $self->{pbot}->{ircd}->{MODES}; } - if (not @{$self->{unban_queue}->{$channel}->{$mode}}) { - delete $self->{unban_queue}->{$channel}->{$mode}; + if (not keys $self->{unban_queue}->{$channel}) { + delete $self->{unban_queue}->{$channel}; + $done = 1; } - last if $count == $self->{pbot}->{ircd}->{MODES}; - } + if ($count) { + $self->add_op_command($channel, "mode $channel $modes $list"); + $self->gain_ops($channel); - if (not keys $self->{unban_queue}->{$channel}) { - delete $self->{unban_queue}->{$channel}; - } - - if ($count) { - $self->add_op_command($channel, "mode $channel $modes $list"); - $self->gain_ops($channel); + return if ++$commands >= $MAX_COMMANDS; + } } } }