diff options
| -rw-r--r-- | localization/english.json | 4 | ||||
| -rw-r--r-- | localization/russian.json | 4 | ||||
| -rw-r--r-- | src/commands/command.cpp | 2 | ||||
| -rw-r--r-- | src/config.cpp | 6 | ||||
| -rw-r--r-- | src/config.hpp | 5 | ||||
| -rw-r--r-- | src/localization/line_id.cpp | 4 | ||||
| -rw-r--r-- | src/localization/line_id.hpp | 4 | ||||
| -rw-r--r-- | src/modules/help.hpp | 31 |
8 files changed, 57 insertions, 3 deletions
diff --git a/localization/english.json b/localization/english.json index e48ac2e..f6679ef 100644 --- a/localization/english.json +++ b/localization/english.json @@ -39,5 +39,7 @@ "custom_command.delete": "{sender.alias_name}: The command \"%s\" has been deleted!", "timer.new": "{sender.alias_name}: New timer \"%s\" has been successfully created!", - "timer.delete": "{sender.alias_name}: The timer \"%s\" has been deleted!" + "timer.delete": "{sender.alias_name}: The timer \"%s\" has been deleted!", + + "help.response": "{sender.alias_name}: Bot command reference: %s" } diff --git a/localization/russian.json b/localization/russian.json index 0e803fe..e68d770 100644 --- a/localization/russian.json +++ b/localization/russian.json @@ -39,5 +39,7 @@ "custom_command.delete": "{sender.alias_name}: Команда \"%s\" была удалена!", "timer.new": "{sender.alias_name}: Новый таймер \"%s\" был успешно создан!", - "timer.delete": "{sender.alias_name}: Таймер \"%s\" был удален!" + "timer.delete": "{sender.alias_name}: Таймер \"%s\" был удален!", + + "help.response": "{sender.alias_name}: Справочник по командам бота: %s" } diff --git a/src/commands/command.cpp b/src/commands/command.cpp index 0bc0f15..e3b45b1 100644 --- a/src/commands/command.cpp +++ b/src/commands/command.cpp @@ -11,6 +11,7 @@ #include "../bundle.hpp" #include "../modules/custom_command.hpp" #include "../modules/event.hpp" +#include "../modules/help.hpp" #include "../modules/join.hpp" #include "../modules/massping.hpp" #include "../modules/notify.hpp" @@ -29,6 +30,7 @@ namespace bot { this->add_command(std::make_unique<mod::Join>()); this->add_command(std::make_unique<mod::CustomCommand>()); this->add_command(std::make_unique<mod::Timer>()); + this->add_command(std::make_unique<mod::Help>()); } void CommandLoader::add_command(std::unique_ptr<Command> command) { diff --git a/src/config.cpp b/src/config.cpp index 977b92c..a8bf3fb 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -23,6 +23,7 @@ namespace bot { DatabaseConfiguration db_cfg; CommandConfiguration cmd_cfg; OwnerConfiguration owner_cfg; + UrlConfiguration url_cfg; std::string line; while (std::getline(ifs, line, '\n')) { @@ -64,8 +65,13 @@ namespace bot { } else if (key == "owner.id") { owner_cfg.id = std::stoi(value); } + + else if (key == "url.help") { + url_cfg.help = value; + } } + cfg.url = url_cfg; cfg.owner = owner_cfg; cfg.commands = cmd_cfg; cfg.twitch_credentials = ttv_crd_cfg; diff --git a/src/config.hpp b/src/config.hpp index 323e18f..5c437d6 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -37,11 +37,16 @@ namespace bot { std::optional<int> id = std::nullopt; }; + struct UrlConfiguration { + std::optional<std::string> help = std::nullopt; + }; + struct Configuration { TwitchCredentialsConfiguration twitch_credentials; DatabaseConfiguration database; CommandConfiguration commands; OwnerConfiguration owner; + UrlConfiguration url; }; std::optional<Configuration> parse_configuration_from_file( diff --git a/src/localization/line_id.cpp b/src/localization/line_id.cpp index 4e84b16..567a3ba 100644 --- a/src/localization/line_id.cpp +++ b/src/localization/line_id.cpp @@ -88,6 +88,10 @@ namespace bot { return LineId::TimerDelete; } + else if (str == "help.response") { + return LineId::HelpResponse; + } + else { return std::nullopt; } diff --git a/src/localization/line_id.hpp b/src/localization/line_id.hpp index 25ab255..41ceec6 100644 --- a/src/localization/line_id.hpp +++ b/src/localization/line_id.hpp @@ -46,7 +46,9 @@ namespace bot { CustomcommandDelete, TimerNew, - TimerDelete + TimerDelete, + + HelpResponse }; std::optional<LineId> string_to_line_id(const std::string &str); diff --git a/src/modules/help.hpp b/src/modules/help.hpp new file mode 100644 index 0000000..13af228 --- /dev/null +++ b/src/modules/help.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <string> +#include <variant> +#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"; } + + std::variant<std::vector<std::string>, std::string> 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 bundle.localization + .get_formatted_line(request, loc::LineId::HelpResponse, + {*bundle.configuration.url.help}) + .value(); + } + }; + } +} |
