summaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-15 04:39:06 +0500
committerilotterytea <iltsu@alright.party>2025-04-15 04:39:06 +0500
commit25477e58bd54585066f518a0e87317a7cd9a6632 (patch)
treeddd9f1c36b6bf3629bdd0109fa9eb79e92ee864b /bot
parentc9d499a3bbd57df13c073798f4cae03272509625 (diff)
feat: !settings in lua
Diffstat (limited to 'bot')
-rw-r--r--bot/src/commands/command.cpp2
-rw-r--r--bot/src/modules/settings.hpp119
2 files changed, 0 insertions, 121 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index fe29b28..7364125 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -17,7 +17,6 @@
#include "../modules/event.hpp"
#include "../modules/help.hpp"
#include "../modules/notify.hpp"
-#include "../modules/settings.hpp"
#include "../modules/timer.hpp"
#include "../utils/chrono.hpp"
#include "commands/lua.hpp"
@@ -33,7 +32,6 @@ namespace bot {
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::Settings>());
this->add_command(std::make_unique<mod::LuaExecution>());
this->add_command(std::make_unique<mod::LuaRemoteExecution>());
diff --git a/bot/src/modules/settings.hpp b/bot/src/modules/settings.hpp
deleted file mode 100644
index 75060f3..0000000
--- a/bot/src/modules/settings.hpp
+++ /dev/null
@@ -1,119 +0,0 @@
-#pragma once
-
-#include <sys/resource.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <algorithm>
-#include <optional>
-#include <string>
-#include <vector>
-
-#include "../bundle.hpp"
-#include "../commands/command.hpp"
-#include "../commands/response_error.hpp"
-
-namespace bot {
- namespace mod {
- class Settings : public command::Command {
- std::string get_name() const override { return "set"; }
-
- schemas::PermissionLevel get_permission_level() const override {
- return schemas::PermissionLevel::MODERATOR;
- }
-
- std::vector<std::string> get_subcommand_ids() const override {
- return {"locale", "prefix", "feature"};
- }
-
- command::Response run(const InstanceBundle &bundle,
- const command::Request &request) const override {
- if (!request.message.has_value()) {
- throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
- request, bundle.localization, command::CommandArgument::VALUE);
- }
-
- pqxx::work work(request.conn);
-
- std::vector<std::string> parts =
- utils::string::split_text(request.message.value(), ' ');
-
- std::string &value = parts[0];
-
- if (request.subcommand_id == "locale") {
- auto locals = bundle.localization.get_loaded_localizations();
- if (!std::any_of(locals.begin(), locals.end(),
- [&value](const auto &x) { return x == value; })) {
- throw ResponseException<ResponseError::NOT_FOUND>(
- request, bundle.localization, value);
- }
-
- work.exec_params(
- "UPDATE channel_preferences SET locale = $1 WHERE channel_id = "
- "$2",
- value, request.channel.get_id());
-
- work.commit();
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::SetLocale,
- {value})
- .value());
- } else if (request.subcommand_id == "prefix") {
- work.exec_params(
- "UPDATE channel_preferences SET prefix = $1 WHERE channel_id = "
- "$2",
- value, request.channel.get_id());
-
- work.commit();
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::SetPrefix,
- {value})
- .value());
- } else if (request.subcommand_id == "feature") {
- std::optional<schemas::ChannelFeature> feature =
- schemas::string_to_channel_feature(value);
- if (!feature.has_value()) {
- throw ResponseException<ResponseError::NOT_FOUND>(
- request, bundle.localization, value);
- }
-
- loc::LineId line_id;
- std::string query;
-
- if (std::any_of(request.channel_preferences.get_features().begin(),
- request.channel_preferences.get_features().end(),
- [&feature](const auto &x) {
- return x == feature.value();
- })) {
- line_id = loc::LineId::SetFeatureDisabled;
- query =
- "UPDATE channel_preferences SET features = "
- "array_remove(features, $1) WHERE channel_id = $2";
- } else {
- line_id = loc::LineId::SetFeatureEnabled;
- query =
- "UPDATE channel_preferences SET features = "
- "array_append(features, $1) WHERE channel_id = $2";
- }
-
- work.exec_params(query, (int)feature.value(),
- request.channel.get_id());
- work.commit();
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, line_id, {value})
- .value());
- }
-
- work.commit();
- throw ResponseException<ResponseError::SOMETHING_WENT_WRONG>(
- request, bundle.localization);
- }
- };
- }
-}