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/User.hpp

41 lines
1.1 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_USER_HPP_
#define API_USER_HPP_
2025-01-15 13:34:41 +05:00
#include <includes.h>
#include <net.h>
2025-01-13 14:40:21 +05:00
#include <vector>
2024-12-31 02:20:56 +05:00
class User {
private:
2025-01-20 16:07:42 +05:00
nlohmann::json data;
2024-12-31 02:20:56 +05:00
WebSocket& web;
NetworkManager& req;
public:
2025-01-20 16:07:42 +05:00
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" };
2025-01-13 14:40:21 +05:00
d.insert(d.end(), keys.begin(), keys.end());
2025-01-20 16:07:42 +05:00
nlohmann::json current = data;
2025-01-13 14:40:21 +05:00
for (const auto& key : d) {
if (current.contains(key)) {
current = current[key];
}
else {
return "Key not found.";
}
}
return current;
2024-12-31 02:20:56 +05:00
}
2025-01-20 16:07:42 +05:00
#endif
std::string me() {
2025-01-19 04:35:20 +05:00
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/users/@me");
2024-12-31 02:20:56 +05:00
}
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-06 21:57:27 +05:00
catch (...) {
2024-12-31 02:20:56 +05:00
return false;
}
}
};
#endif