From c9391d7829e801dc25353829e02217d930178fb9 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 26 Dec 2019 19:24:35 -0800 Subject: [PATCH] Add wildcard support to `mode` command --- PBot/ChanOpCommands.pm | 65 ++++++++++++++++++++++++++++++++++++++++-- PBot/ChanOps.pm | 1 - 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index 49913853..93e92ae8 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -66,8 +66,69 @@ sub mode { } } - my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); - $self->{pbot}->{conn}->mode($channel, $args); + my ($channel, $modes, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); + my @targets = split /\s+/, $args; + my $modifier; + my $i = 0; + my $arg = 0; + + my ($new_modes, $new_targets) = ("", ""); + my $MAX_MODES = 4; + + while ($modes =~ m/(.)/g) { + my $mode = $1; + + if ($mode eq '-' or $mode eq '+') { + $modifier = $mode; + $new_modes .= $mode; + next; + } + + my $target = $targets[$arg++] // ""; + + if (($mode eq 'v' or $mode eq 'o') and $target =~ m/\*/) { + my $q_target = lc quotemeta $target; + $q_target =~ s/\\\*/.*/g; + $channel = lc $channel; + + if (not exists $self->{pbot}->{nicklist}->{nicklist}->{$channel}) { + return "I have no nick list for channel $channel; cannot use wildcard."; + } + + foreach my $n (keys %{$self->{pbot}->{nicklist}->{nicklist}->{$channel}}) { + if ($n =~ m/^$q_target$/) { + $new_modes = $modifier if not length $new_modes; + $new_modes .= $mode; + $new_targets .= "$self->{pbot}->{nicklist}->{nicklist}->{$channel}->{$n}->{nick} "; + $i++; + + if ($i == $MAX_MODES) { + $self->{pbot}->{chanops}->add_op_command($channel, "mode $channel $new_modes $new_targets"); + $new_modes = ""; + $new_targets = ""; + $i = 0; + } + } + } + } else { + $new_modes .= $mode; + $new_targets .= "$target " if length $target; + $i++; + + if ($i == $MAX_MODES) { + $self->{pbot}->{chanops}->add_op_command($channel, "mode $channel $new_modes $new_targets"); + $new_modes = ""; + $new_targets = ""; + $i = 0; + } + } + } + + if ($i) { + $self->{pbot}->{chanops}->add_op_command($channel, "mode $channel $new_modes $new_targets"); + } + + $self->{pbot}->{chanops}->gain_ops($channel); if ($from !~ m/^#/) { return "Done."; diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index e00d99a4..607df33d 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -477,7 +477,6 @@ sub check_opped_timeouts { and exists $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop} and $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop}) { $self->lose_ops($channel); - delete $self->{is_opped}->{$channel}; # assume op_nick is alive and deop will succeed } } else { # my $timediff = $self->{is_opped}->{$channel}{timeout} - $now;