sparkle/libs/api/Author.hpp

33 lines
1.2 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_AUTHOR_HPP_
#define API_AUTHOR_HPP_
2025-01-15 13:34:41 +05:00
#include <includes.h>
#include <net.h>
2024-12-31 02:20:56 +05:00
class Author {
private:
2025-01-25 11:24:56 +05:00
nlohmann::json data;
const nlohmann::json &d;
2025-01-13 22:30:24 +05:00
WebSocket& web;
NetworkManager& req;
2024-12-31 02:20:56 +05:00
public:
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;
Author(const nlohmann::json& data) :
data(data),
d(data["d"]),
web(WebSocket::getInstance()),
req(NetworkManager::getInstance()),
channel_id(functions::isNull(d["channel_id"])),
global_name(functions::isNull(d["author"]["global_name"])),
id(d["author"]["id"]),
content(d["content"]),
2025-01-25 12:23:31 +05:00
avatar(d["author"]["avatar"]),
guild_id(d["guild_id"]),
discriminator(d["author"]["discriminator"]),
message_id(d["id"]),
isPinned(d["pinned"]),
2025-01-25 11:24:56 +05:00
isBot(d["author"].contains("bot") ? d["author"]["bot"].get<bool>() : false) {};
std::string send(const nlohmann::json& msg) {
2025-01-25 12:23:31 +05:00
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + 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