sparkle/libs/api/Author.hpp
2025-01-25 13:22:59 +05:00

34 lines
1.2 KiB
C++

#ifndef API_AUTHOR_HPP_
#define API_AUTHOR_HPP_
#include <includes.hpp>
#include <net.hpp>
class Author {
private:
nlohmann::json data;
const nlohmann::json& d;
WebSocket& web;
NetworkManager& req;
public:
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"]),
avatar(d["author"]["avatar"]),
guild_id(d["guild_id"]),
discriminator(d["author"]["discriminator"]),
message_id(d["id"]),
isPinned(d["pinned"]),
isBot(d["author"].contains("bot") ? d["author"]["bot"].get<bool>() : false) {
};
std::string send(const nlohmann::json& msg) {
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + d["channel_id"].get<std::string>() + "/messages", msg.dump());
}
};
#endif