summaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-16 15:50:08 +0500
committerilotterytea <iltsu@alright.party>2025-04-16 15:50:08 +0500
commit52a6af6a2e5d64561a6a8a15c7e079fe46ffaa85 (patch)
treeb58b46608b14d7a7baf4623819cdb7d6944c0a7e /bot/src
parente410ed000d119d0d3e4d5707abad11512b9e4a34 (diff)
feat: !cmd in lua
Diffstat (limited to 'bot/src')
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/modules/custom_command.hpp96
2 files changed, 0 insertions, 98 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 92ae45b..fa266de 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -13,7 +13,6 @@
#include <string>
#include "../bundle.hpp"
-#include "../modules/custom_command.hpp"
#include "../modules/event.hpp"
#include "../modules/notify.hpp"
#include "../modules/timer.hpp"
@@ -28,7 +27,6 @@ namespace bot {
CommandLoader::CommandLoader() {
this->add_command(std::make_unique<mod::Event>());
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::LuaExecution>());
diff --git a/bot/src/modules/custom_command.hpp b/bot/src/modules/custom_command.hpp
deleted file mode 100644
index 9fd1429..0000000
--- a/bot/src/modules/custom_command.hpp
+++ /dev/null
@@ -1,96 +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 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<std::string> get_subcommand_ids() const override {
- return {"new", "remove"};
- }
-
- command::Response run(const InstanceBundle &bundle,
- const command::Request &request) const override {
- if (!request.subcommand_id.has_value()) {
- throw ResponseException<NOT_ENOUGH_ARGUMENTS>(
- request, bundle.localization, command::SUBCOMMAND);
- }
-
- const std::string &subcommand_id = request.subcommand_id.value();
-
- if (!request.message.has_value()) {
- throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
- request, bundle.localization, command::CommandArgument::NAME);
- }
-
- const std::string &message = request.message.value();
- std::vector<std::string> 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<ResponseError::NAMESAKE_CREATION>(
- request, bundle.localization, name);
- }
-
- if (s.empty()) {
- throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
- 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 command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::CustomcommandNew,
- {name})
- .value());
- } else if (subcommand_id == "remove") {
- if (cmds.empty()) {
- throw ResponseException<ResponseError::NOT_FOUND>(
- request, bundle.localization, name);
- }
-
- work.exec("DELETE FROM custom_commands WHERE id = " +
- std::to_string(cmds[0][0].as<int>()));
- work.commit();
-
- return command::Response(
- bundle.localization
- .get_formatted_line(
- request, loc::LineId::CustomcommandDelete, {name})
- .value());
- }
-
- throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(
- request, bundle.localization);
- }
- };
- }
-}