From d1793df1eda463b10107d41785ad1d7f055ed476 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 18 May 2024 14:48:12 +0500 Subject: upd: moved the bot part to a relative subfolder --- src/modules/custom_command.hpp | 96 ------------------------------------------ 1 file changed, 96 deletions(-) delete mode 100644 src/modules/custom_command.hpp (limited to 'src/modules/custom_command.hpp') diff --git a/src/modules/custom_command.hpp b/src/modules/custom_command.hpp deleted file mode 100644 index 50b3692..0000000 --- a/src/modules/custom_command.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "../bundle.hpp" -#include "../commands/command.hpp" -#include "../commands/response_error.hpp" - -namespace bot { - namespace mod { - class CustomCommand : public command::Command { - std::string get_name() const override { return "scmd"; } - - schemas::PermissionLevel get_permission_level() const override { - return schemas::PermissionLevel::MODERATOR; - } - - std::vector get_subcommand_ids() const override { - return {"new", "remove"}; - } - - std::variant, std::string> run( - const InstanceBundle &bundle, - const command::Request &request) const override { - if (!request.subcommand_id.has_value()) { - throw ResponseException( - request, bundle.localization, command::SUBCOMMAND); - } - - const std::string &subcommand_id = request.subcommand_id.value(); - - if (!request.message.has_value()) { - throw ResponseException( - request, bundle.localization, command::CommandArgument::NAME); - } - - const std::string &message = request.message.value(); - std::vector s = utils::string::split_text(message, ' '); - - std::string name = s[0]; - s.erase(s.begin()); - - pqxx::work work(request.conn); - pqxx::result cmds = work.exec( - "SELECT id FROM custom_commands WHERE name = '" + name + - "' AND channel_id = " + std::to_string(request.channel.get_id())); - - if (subcommand_id == "new") { - if (!cmds.empty()) { - throw ResponseException( - request, bundle.localization, name); - } - - if (s.empty()) { - throw ResponseException( - request, bundle.localization, - command::CommandArgument::MESSAGE); - } - - std::string m = utils::string::str(s.begin(), s.end(), ' '); - - work.exec( - "INSERT INTO custom_commands(channel_id, name, message) VALUES " - "(" + - std::to_string(request.channel.get_id()) + ", '" + name + - "', '" + m + "')"); - work.commit(); - - return bundle.localization - .get_formatted_line(request, loc::LineId::CustomcommandNew, - {name}) - .value(); - } else if (subcommand_id == "remove") { - if (cmds.empty()) { - throw ResponseException( - request, bundle.localization, name); - } - - work.exec("DELETE FROM custom_commands WHERE id = " + - std::to_string(cmds[0][0].as())); - work.commit(); - - return bundle.localization - .get_formatted_line(request, loc::LineId::CustomcommandDelete, - {name}) - .value(); - } - - throw ResponseException( - request, bundle.localization); - } - }; - } -} -- cgit v1.2.3