sparkle/libs/interface/Author.hpp

45 lines
2.0 KiB
C++
Raw Normal View History

2025-01-29 16:06:47 +05:00
#ifndef INTERFACE_AUTHOR_HPP_
#define INTERFACE_AUTHOR_HPP_
2025-02-02 00:11:39 +05:00
#include <pch.hpp>
2025-01-29 16:06:47 +05:00
#include <network.hpp>
2024-12-31 02:20:56 +05:00
class Author {
private:
2025-01-27 22:02:21 +05:00
const nlohmann::json& data;
2025-01-13 22:30:24 +05:00
WebSocket& web;
NetworkManager& req;
2024-12-31 02:20:56 +05:00
public:
2025-01-30 23:05:59 +05:00
_deprecated_t("requires update")
struct Channel {
2025-01-27 22:02:21 +05:00
std::string channel_id;
std::string global_name;
std::string id;
std::string content;
std::string avatar;
std::string guild_id;
std::string discriminator;
std::string message_id;
bool isPinned;
bool isBot;
} authorData;
2025-01-25 11:24:56 +05:00
const std::string channel_id, global_name, id, content, avatar, guild_id, discriminator, message_id;
bool isPinned, isBot;
2025-01-27 22:02:21 +05:00
Author(const nlohmann::json& data)
: data(data),
2025-01-25 11:24:56 +05:00
web(WebSocket::getInstance()),
req(NetworkManager::getInstance()),
2025-01-27 22:02:21 +05:00
channel_id(functions::testValue<std::string>(data, { "d", "channel_id" }).value_or("")),
global_name(functions::testValue<std::string>(data, { "d", "author", "global_name" }).value_or("")),
id(functions::testValue<std::string>(data, { "d", "author", "id" }).value_or("")),
content(functions::testValue<std::string>(data, { "d", "content" }).value_or("")),
avatar(functions::testValue<std::string>(data, { "d", "author", "avatar" }).value_or("")),
guild_id(functions::testValue<std::string>(data, { "d", "guild_id" }).value_or("")),
discriminator(functions::testValue<std::string>(data, { "d", "author", "discriminator" }).value_or("")),
message_id(functions::testValue<std::string>(data, { "d", "id" }).value_or("")),
isPinned(functions::testValue<bool>(data, { "d", "pinned" }).value_or(false)),
2025-01-29 16:06:47 +05:00
isBot(functions::testValue<bool>(data, { "d", "author", "bot" }).value_or(false)) {
}
2025-01-30 23:05:59 +05:00
auto send(const nlohmann::json& msg) -> std::string {
2025-01-27 22:02:21 +05:00
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + data["d"]["channel_id"].get<std::string>() + "/messages", msg.dump());
2025-01-13 22:30:24 +05:00
}
2024-12-31 02:20:56 +05:00
};
#endif