2021-07-21 06:38:07 +02:00
|
|
|
# File: CommandMetadata.pm
|
|
|
|
#
|
|
|
|
# Purpose: Registers commands for manipulating command metadata.
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2021-07-21 08:06:03 +02:00
|
|
|
package PBot::Core::Commands::CommandMetadata;
|
2021-07-21 06:38:07 +02:00
|
|
|
|
|
|
|
use PBot::Imports;
|
2021-07-23 16:24:30 +02:00
|
|
|
use parent 'PBot::Core::Class';
|
2021-07-21 06:38:07 +02:00
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
|
|
|
# register commands to manipulate command metadata
|
|
|
|
$self->{pbot}->{commands}->register(sub { $self->cmd_set(@_) }, "cmdset", 1);
|
|
|
|
$self->{pbot}->{commands}->register(sub { $self->cmd_unset(@_) }, "cmdunset", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cmd_set {
|
|
|
|
my ($self, $context) = @_;
|
|
|
|
|
|
|
|
my ($command, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
|
|
|
|
|
|
|
|
if (not defined $command) {
|
|
|
|
return "Usage: cmdset <command> [key [value]]";
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:08:07 +02:00
|
|
|
return $self->{pbot}->{commands}->{metadata}->set($command, $key, $value);
|
2021-07-21 06:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub cmd_unset {
|
|
|
|
my ($self, $context) = @_;
|
|
|
|
|
|
|
|
my ($command, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
|
|
|
|
|
|
|
|
if (not defined $command or not defined $key) {
|
|
|
|
return "Usage: cmdunset <command> <key>";
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:08:07 +02:00
|
|
|
return $self->{pbot}->{commands}->{metadata}->unset($command, $key);
|
2021-07-21 06:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|