3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 15:29:32 +01:00

RegistryCommands: regset value argument now optional; shows value if omitted

This commit is contained in:
Pragmatic Software 2020-02-04 21:51:27 -08:00
parent 735cae5c54
commit 52509f1786

View File

@ -39,7 +39,7 @@ sub initialize {
sub regset {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my $usage = "Usage: regset <section>.<item> <value>";
my $usage = "Usage: regset <section>.<item> [value]";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
@ -51,11 +51,15 @@ sub regset {
($item, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
}
if (not defined $section or not defined $item or not defined $value) {
if (not defined $section or not defined $item) {
return $usage;
}
$self->{pbot}->{registry}->add('text', $section, $item, $value);
if (defined $value) {
$self->{pbot}->{registry}->add('text', $section, $item, $value);
} else {
return $self->{pbot}->{registry}->set($section, $item, 'value');
}
$self->{pbot}->{logger}->log("$nick!$user\@$host set registry entry [$section] $item => $value\n");
return "$section.$item set to $value";