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>
|
|
|
|
using std::string, std::cout, std::endl, nlohmann::json;
|
2024-12-31 02:20:56 +05:00
|
|
|
class Author {
|
|
|
|
private:
|
|
|
|
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-20 04:03:27 +05:00
|
|
|
Author(const json& data) :
|
|
|
|
data(data),
|
|
|
|
web(WebSocket::getInstance()),
|
|
|
|
req(NetworkManager::getInstance()),
|
|
|
|
channel_id(functions::isNull(data["d"]["channel_id"])),
|
|
|
|
global_name(functions::isNull(data["d"]["author"]["global_name"])),
|
|
|
|
id(data["d"]["author"]["id"])
|
|
|
|
{
|
|
|
|
};
|
|
|
|
string content() const {
|
2024-12-31 02:20:56 +05:00
|
|
|
try {
|
|
|
|
return data["d"]["content"];
|
|
|
|
}
|
2025-01-14 16:14:01 +05:00
|
|
|
catch (...) {
|
|
|
|
return "";
|
2024-12-31 02:20:56 +05:00
|
|
|
}
|
|
|
|
}
|
2025-01-20 04:03:27 +05:00
|
|
|
const string channel_id, global_name, id;
|
|
|
|
string discriminator() const {
|
2024-12-31 02:20:56 +05:00
|
|
|
return data["d"]["author"]["discriminator"];
|
|
|
|
}
|
2025-01-20 04:03:27 +05:00
|
|
|
bool isBot() const {
|
2024-12-31 02:20:56 +05:00
|
|
|
try {
|
|
|
|
return data["d"]["author"]["bot"];
|
|
|
|
}
|
2025-01-13 22:30:24 +05:00
|
|
|
catch (...) {
|
|
|
|
return 0;
|
2024-12-31 02:20:56 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
string guild_id() {
|
|
|
|
return data["d"]["guild_id"];
|
|
|
|
}
|
|
|
|
string msg_id() {
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
string avatar() {
|
|
|
|
return data["d"]["author"]["avatar"];
|
|
|
|
}
|
2025-01-13 22:30:24 +05:00
|
|
|
string send(const json& msg) {
|
2025-01-19 04:35:20 +05:00
|
|
|
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + data["d"]["channel_id"].get<string>() + "/messages", msg.dump());
|
2025-01-13 22:30:24 +05:00
|
|
|
}
|
2024-12-31 02:20:56 +05:00
|
|
|
};
|
|
|
|
#endif
|