summaryrefslogtreecommitdiff
path: root/bot/src/modules/chatters.hpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-10 23:37:38 +0500
committerilotterytea <iltsu@alright.party>2025-04-10 23:37:38 +0500
commitead8d4e14f939eca0be580199de56a3d6039e446 (patch)
treebaaf4c549213bf07d62d3761073d6cb51e397a60 /bot/src/modules/chatters.hpp
parent97189d3f0947294fe3e8f20b559a3634c5ae0ccd (diff)
feat: !chatters in lua
Diffstat (limited to 'bot/src/modules/chatters.hpp')
-rw-r--r--bot/src/modules/chatters.hpp78
1 files changed, 0 insertions, 78 deletions
diff --git a/bot/src/modules/chatters.hpp b/bot/src/modules/chatters.hpp
deleted file mode 100644
index 6e4c61c..0000000
--- a/bot/src/modules/chatters.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#pragma once
-
-#include <ctime>
-#include <iomanip>
-#include <sstream>
-#include <string>
-#include <vector>
-
-#include "../bundle.hpp"
-#include "../commands/command.hpp"
-#include "../commands/response_error.hpp"
-#include "cpr/api.h"
-#include "cpr/multipart.h"
-#include "cpr/response.h"
-#include "nlohmann/json.hpp"
-
-namespace bot::mod {
- class Chatters : public command::Command {
- std::string get_name() const override { return "chatters"; }
-
- schemas::PermissionLevel get_permission_level() const override {
- return schemas::PermissionLevel::USER;
- }
-
- int get_delay_seconds() const override { return 10; }
-
- command::Response run(const InstanceBundle &bundle,
- const command::Request &request) const override {
- if (!bundle.configuration.url.paste_service.has_value()) {
- throw ResponseException<ResponseError::ILLEGAL_COMMAND>(
- request, bundle.localization);
- }
-
- auto chatters = bundle.helix_client.get_chatters(
- request.channel.get_alias_id(), bundle.irc_client.get_bot_id());
-
- std::string body;
-
- for (const auto &chatter : chatters) {
- body += chatter.login + '\n';
- }
-
- std::time_t t = std::time(nullptr);
- std::tm *now = std::localtime(&t);
-
- std::ostringstream oss;
-
- oss << std::put_time(now, "%d.%m.%Y %H:%M:%S");
-
- cpr::Multipart multipart = {
- {"paste", body},
- {"title", request.channel.get_alias_name() + "'s chatter list on " +
- oss.str()}};
-
- cpr::Response response = cpr::Post(
- cpr::Url{*bundle.configuration.url.paste_service + "/paste"},
- multipart);
-
- if (response.status_code == 201) {
- nlohmann::json j = nlohmann::json::parse(response.text);
-
- std::string id = j["data"]["id"];
-
- std::string url = *bundle.configuration.url.paste_service + "/" + id;
-
- return command::Response(
- bundle.localization
- .get_formatted_line(request, loc::LineId::ChattersResponse,
- {url})
- .value());
- } else {
- throw ResponseException<ResponseError::EXTERNAL_API_ERROR>(
- request, bundle.localization, response.status_code,
- response.status_line);
- }
- }
- };
-}