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
2025-01-15 13:34:41 +05:00

40 lines
1.0 KiB
C++

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