This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
sparkle/libs/api/Author.hpp

45 lines
1.3 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-20 16:07:42 +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-20 16:07:42 +05:00
Author(const nlohmann::json& data) :
2025-01-20 04:03:27 +05:00
data(data),
2025-01-20 16:07:42 +05:00
d(data["d"]),
2025-01-20 04:03:27 +05:00
web(WebSocket::getInstance()),
req(NetworkManager::getInstance()),
2025-01-20 16:07:42 +05:00
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)
2025-01-20 04:03:27 +05:00
{
};
2025-01-20 16:07:42 +05:00
const std::string channel_id, global_name, id, content;
bool isBot;
std::string discriminator() const {
2024-12-31 02:20:56 +05:00
return data["d"]["author"]["discriminator"];
}
2025-01-20 16:07:42 +05:00
std::string guild_id() {
2024-12-31 02:20:56 +05:00
return data["d"]["guild_id"];
}
2025-01-20 16:07:42 +05:00
std::string msg_id() {
2024-12-31 02:20:56 +05:00
return data["d"]["id"];
}
2025-01-13 22:34:42 +05:00
bool isPinned() {
2024-12-31 02:20:56 +05:00
return data["d"]["pinned"];
}
2025-01-20 16:07:42 +05:00
std::string avatar() {
2024-12-31 02:20:56 +05:00
return data["d"]["author"]["avatar"];
}
2025-01-20 16:07:42 +05:00
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());
2025-01-13 22:30:24 +05:00
}
2024-12-31 02:20:56 +05:00
};
#endif