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

39 lines
1.0 KiB
C++

#ifndef API_USER_HPP_
#define API_USER_HPP_
#include <includes.hpp>
#include <net.hpp>
#include <vector>
class User {
private:
nlohmann::json data;
WebSocket& web;
NetworkManager& req;
public:
User(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {}
#ifdef DEBUG
nlohmann::json extract(const std::vector<std::string>& keys) {
std::vector<std::string> d = { "d" };
d.insert(d.end(), keys.begin(), keys.end());
nlohmann::json current = data;
for (const auto& key : d) {
if (current.contains(key)) {
current = current[key];
} else {
return "Key not found.";
}
}
return current;
}
#endif
std::string me() {
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/users/@me");
}
bool isBot() const {
try {
return data["d"]["author"]["bot"];
} catch (...) {
return false;
}
}
};
#endif