From 3355ee655fde11f3bb65037d4090a27e7acb37b1 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 17 Apr 2025 01:56:12 +0500 Subject: feat: !notify in lua --- bot/src/commands/command.cpp | 2 - bot/src/modules/notify.hpp | 131 ------------------------------------------- 2 files changed, 133 deletions(-) delete mode 100644 bot/src/modules/notify.hpp (limited to 'bot') diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp index 55fac64..410d5ba 100644 --- a/bot/src/commands/command.cpp +++ b/bot/src/commands/command.cpp @@ -13,7 +13,6 @@ #include #include "../bundle.hpp" -#include "../modules/notify.hpp" #include "../modules/timer.hpp" #include "../utils/chrono.hpp" #include "commands/lua.hpp" @@ -24,7 +23,6 @@ namespace bot { namespace command { CommandLoader::CommandLoader() { - this->add_command(std::make_unique()); this->add_command(std::make_unique()); this->add_command(std::make_unique()); diff --git a/bot/src/modules/notify.hpp b/bot/src/modules/notify.hpp deleted file mode 100644 index 7bea6a6..0000000 --- a/bot/src/modules/notify.hpp +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include -#include - -#include "../bundle.hpp" -#include "../commands/command.hpp" -#include "../commands/response_error.hpp" -#include "../schemas/stream.hpp" - -namespace bot { - namespace mod { - class Notify : public command::Command { - std::string get_name() const override { return "notify"; } - - std::vector get_subcommand_ids() const override { - return {"sub", "unsub"}; - } - - command::Response 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::TARGET); - } - - const std::string &message = request.message.value(); - std::vector s = utils::string::split_text(message, ' '); - - std::string target; - schemas::EventType type; - - std::vector target_and_type = - utils::string::split_text(s[0], ':'); - - if (target_and_type.size() != 2) { - throw ResponseException( - request, bundle.localization, s[0]); - } - - s.erase(s.begin()); - - target = target_and_type[0]; - type = schemas::string_to_event_type(target_and_type[1]); - - std::string t = target_and_type[0] + ":" + target_and_type[1]; - - auto channels = bundle.helix_client.get_users({target}); - api::twitch::schemas::User channel; - - if (channels.empty() && type < schemas::EventType::GITHUB) { - throw ResponseException( - request, bundle.localization, t); - } - - pqxx::work work(request.conn); - std::string query; - - if (type < schemas::GITHUB) { - channel = channels[0]; - - query = "SELECT id FROM events WHERE channel_id = " + - std::to_string(request.channel.get_id()) + - " AND target_alias_id = " + std::to_string(channel.id) + - " AND event_type = " + std::to_string(type); - } else { - query = "SELECT id FROM events WHERE channel_id = " + - std::to_string(request.channel.get_id()) + - " AND custom_alias_id = '" + target + - "' AND event_type = " + std::to_string(type); - } - - pqxx::result events = work.exec(query); - - if (events.empty()) { - throw ResponseException( - request, bundle.localization, t); - } - - pqxx::row event = events[0]; - - pqxx::result subs = - work.exec("SELECT id FROM event_subscriptions WHERE event_id = " + - std::to_string(event[0].as()) + " AND user_id = " + - std::to_string(request.user.get_id())); - - if (subcommand_id == "sub") { - if (!subs.empty()) { - throw ResponseException( - request, bundle.localization, t); - } - - work.exec( - "INSERT INTO event_subscriptions(event_id, user_id) VALUES (" + - std::to_string(event[0].as()) + ", " + - std::to_string(request.user.get_id()) + ")"); - work.commit(); - - return command::Response( - bundle.localization - .get_formatted_line(request, loc::LineId::NotifySub, {t}) - .value()); - } else if (subcommand_id == "unsub") { - if (subs.empty()) { - throw ResponseException( - request, bundle.localization, t); - } - - work.exec("DELETE FROM event_subscriptions WHERE id = " + - std::to_string(subs[0][0].as())); - work.commit(); - - return command::Response( - bundle.localization - .get_formatted_line(request, loc::LineId::NotifyUnsub, {t}) - .value()); - } - - throw ResponseException( - request, bundle.localization); - } - }; - } -} -- cgit v1.2.3