3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 19:52:34 +01:00

Capabilities: improve output of listings

This commit is contained in:
Pragmatic Software 2020-02-04 00:03:40 -08:00
parent e79d8bf710
commit bd252c5201

View File

@ -37,8 +37,8 @@ sub initialize {
# 'cap' command registered in PBot.pm because $self->{pbot}->{commands} is not yet loaded. # 'cap' command registered in PBot.pm because $self->{pbot}->{commands} is not yet loaded.
# add some basic capabilities # add some basic capabilities
$self->add('can-modify-capabilities', undef, 1); $self->add('can-modify-capabilities', undef, 1);
$self->add('can-group-capabilities', undef, 1); $self->add('can-group-capabilities', undef, 1);
$self->add('can-ungroup-capabilities', undef, 1); $self->add('can-ungroup-capabilities', undef, 1);
# add admin capabilities group # add admin capabilities group
@ -153,8 +153,8 @@ sub list {
return "No such capability $capability." if defined $capability and not exists $self->{caps}->{hash}->{$capability}; return "No such capability $capability." if defined $capability and not exists $self->{caps}->{hash}->{$capability};
my @caps; my @caps;
my @cap_group; my @groups;
my @cap_standalone; my @standalones;
my $result; my $result;
if (not defined $capability) { if (not defined $capability) {
@ -172,12 +172,12 @@ sub list {
next if $cap eq '_name'; next if $cap eq '_name';
my $count = keys(%{$self->{caps}->{hash}->{$cap}}) - 1; my $count = keys(%{$self->{caps}->{hash}->{$cap}}) - 1;
if ($count > 0) { if ($count > 0) {
push @cap_group, "$cap [$count]" if $count; push @groups, "$cap ($count cap" . ($count == 1 ? '' : 's') . ")" if $count;
} else { } else {
push @cap_standalone, $cap; push @standalones, $cap;
} }
} }
$result .= join ', ', @cap_group, @cap_standalone; $result .= join ', ', @groups, @standalones;
return $result; return $result;
} }
@ -216,7 +216,7 @@ sub capcmd {
next if not $self->exists($key); next if not $self->exists($key);
my $count = keys (%{$self->{caps}->{hash}->{$key}}) - 1; my $count = keys (%{$self->{caps}->{hash}->{$key}}) - 1;
if ($count > 0) { if ($count > 0) {
push @groups, "$key [$count]"; push @groups, "$key ($count cap" . ($count == 1 ? '' : 's') . ")";
} else { } else {
push @single, $key; push @single, $key;
} }