From 569e42cac0d6fa52f69c425fc13c4eae6aeef25a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 6 Feb 2020 02:20:47 -0800 Subject: [PATCH] Capabilities: add `cap whohas` --- PBot/Capabilities.pm | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/PBot/Capabilities.pm b/PBot/Capabilities.pm index 74667514..701d9a53 100644 --- a/PBot/Capabilities.pm +++ b/PBot/Capabilities.pm @@ -183,9 +183,35 @@ sub capcmd { return $self->list($cap); } + when ('whohas') { + my $cap = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}); + return "Usage: cap whohas ; Lists all users who have " if not defined $cap; + return "No such capability $cap." if not $self->exists($cap); + my $result = "Users with capability $cap: "; + my $matched = 0; + my $users = $self->{pbot}->{users}->{users}->{hash}; + foreach my $channel (sort keys %$users) { + my @matches; + next if $channel eq '_name'; + foreach my $hostmask (sort keys %{$users->{$channel}}) { + next if $hostmask eq '_name'; + my $u = $users->{$channel}->{$hostmask}; + push @matches, $u->{name} if $self->userhas($u, $cap); + } + if (@matches) { + $result .= '; ' if $matched; + $result .= $users->{$channel}->{_name} eq '.*' ? '' : "$channel: "; + $result .= join ', ', @matches; + $matched = 1; + } + } + $result .= 'nobody' if not $matched; + return $result; + } + when ('userhas') { my ($hostmask, $cap) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); - return "Usage: cap userhas [capability]" if not defined $hostmask; + return "Usage: cap userhas [capability]; Lists capabilities belonging to " if not defined $hostmask; $cap = lc $cap if defined $cap; my $u = $self->{pbot}->{users}->find_user('.*', $hostmask); @@ -253,7 +279,7 @@ sub capcmd { } default { - $result = "Usage: cap list [capability] | cap group | cap ungroup | cap userhas [capability]"; + $result = "Usage: cap list [capability] | cap group | cap ungroup | cap userhas [capability] | cap whohas "; } } return $result;