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
|
|
|
|
2023-04-14 06:04:12 +02:00
|
|
|
sub initialize($self, %conf) {
|
2021-07-21 06:38:07 +02:00
|
|
|
# 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);
|
|
|
|
}
|
|
|
|
|
2023-04-14 06:04:12 +02:00
|
|
|
sub cmd_set($self, $context) {
|
2021-07-21 06:38:07 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-04-14 06:04:12 +02:00
|
|
|
sub cmd_unset($self, $context) {
|
2021-07-21 06:38:07 +02:00
|
|
|
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;
|