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