From 2a6f98c02d87ba91b44bc3e0e8458873cf75de5a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 30 Dec 2019 15:59:56 -0800 Subject: [PATCH] ChanOpCommands: `mode` now skips existing modes when used with wildcard; unsetting modes via wildcard now skips admins/whitelisted users --- PBot/ChanOpCommands.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index 1239694c..1df571b6 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -110,16 +110,33 @@ sub mode { my $target = $targets[$arg++] // ""; if (($mode eq 'v' or $mode eq 'o') and $target =~ m/\*/) { + # wildcard used; find all matching nicks; test against whitelist, etc 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."; + return "I have no nicklist for channel $channel; cannot use wildcard."; } foreach my $n (keys %{$self->{pbot}->{nicklist}->{nicklist}->{$channel}}) { if ($n =~ m/^$q_target$/) { + my $nick_data = $self->{pbot}->{nicklist}->{nicklist}->{$channel}->{$n}; + + if ($modifier eq '-') { + # removing mode -- check against whitelist, etc + next if $n eq $self->{pbot}->{registry}->get_value('irc', 'botnick'); + next if $self->{pbot}->{antiflood}->whitelisted($channel, $nick_data->{hostmask}); + next if $self->{pbot}->{admins}->loggedin($channel, $nick_data->{hostmask}); + } + + # skip nick if already has mode set/unset + if ($modifier eq '+') { + next if exists $nick_data->{"+$mode"}; + } else { + next unless exists $nick_data->{"+$mode"}; + } + $new_modes = $modifier if not length $new_modes; $new_modes .= $mode; $new_targets .= "$self->{pbot}->{nicklist}->{nicklist}->{$channel}->{$n}->{nick} "; @@ -134,6 +151,7 @@ sub mode { } } } else { + # no wildcard used; explicit mode requested - no whitelist checking $new_modes .= $mode; $new_targets .= "$target " if length $target; $i++;