diff options
| -rw-r--r-- | bot/src/commands/command.cpp | 2 | ||||
| -rw-r--r-- | bot/src/modules/help.hpp | 30 | ||||
| -rw-r--r-- | luamods/help.lua | 50 |
3 files changed, 50 insertions, 32 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp index 7364125..92ae45b 100644 --- a/bot/src/commands/command.cpp +++ b/bot/src/commands/command.cpp @@ -15,7 +15,6 @@ #include "../bundle.hpp" #include "../modules/custom_command.hpp" #include "../modules/event.hpp" -#include "../modules/help.hpp" #include "../modules/notify.hpp" #include "../modules/timer.hpp" #include "../utils/chrono.hpp" @@ -31,7 +30,6 @@ namespace bot { this->add_command(std::make_unique<mod::Notify>()); this->add_command(std::make_unique<mod::CustomCommand>()); this->add_command(std::make_unique<mod::Timer>()); - this->add_command(std::make_unique<mod::Help>()); this->add_command(std::make_unique<mod::LuaExecution>()); this->add_command(std::make_unique<mod::LuaRemoteExecution>()); diff --git a/bot/src/modules/help.hpp b/bot/src/modules/help.hpp deleted file mode 100644 index 1341b86..0000000 --- a/bot/src/modules/help.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include <string> -#include <vector> - -#include "../bundle.hpp" -#include "../commands/command.hpp" -#include "../commands/response_error.hpp" - -namespace bot { - namespace mod { - class Help : public command::Command { - std::string get_name() const override { return "help"; } - - command::Response run(const InstanceBundle &bundle, - const command::Request &request) const override { - if (!bundle.configuration.url.help.has_value()) { - throw ResponseException<ResponseError::ILLEGAL_COMMAND>( - request, bundle.localization); - } - - return command::Response( - bundle.localization - .get_formatted_line(request, loc::LineId::HelpResponse, - {*bundle.configuration.url.help}) - .value()); - } - }; - } -} diff --git a/luamods/help.lua b/luamods/help.lua new file mode 100644 index 0000000..6fd8968 --- /dev/null +++ b/luamods/help.lua @@ -0,0 +1,50 @@ +local lines = { + english = { + ["command_unavailable"] = "{sender.alias_name}: This command is not available.", + ["help_default"] = "{sender.alias_name}: More info can be found here: %s", + ["help_command"] = "{sender.alias_name}: More info about {channel.prefix}%s: %s", + }, + russian = { + ["command_unavailable"] = "{sender.alias_name}: Эта команда недоступна.", + ["help_default"] = "{sender.alias_name}: Больше информации можно найти здесь: %s", + ["help_command"] = "{sender.alias_name}: Больше информации о {channel.prefix}%s: %s", + }, +} + +return { + name = "help", + description = [[ +Get an information about commands. +]], + delay_sec = 1, + options = {}, + subcommands = {}, + aliases = {}, + minimal_rights = "user", + handle = function(request) + local cfg = bot_config() + if cfg == nil then + return l10n_custom_formatted_line_request(request, lines, "command_unavailable", {}) + end + + if cfg.url.help == nil then + return l10n_custom_formatted_line_request(request, lines, "command_unavailable", {}) + end + + local line_id = "help_default" + local args = { cfg.url.help } + if request.message ~= nil then + local parts = str_split(request.message, ' ') + local command = parts[1] + + if array_contains(bot_get_loaded_command_names(), command) then + line_id = "help_command" + args = {} + table.insert(args, command) + table.insert(args, cfg.url.help .. '/!' .. command) + end + end + + return l10n_custom_formatted_line_request(request, lines, line_id, args) + end, +} |
