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

45 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-06 21:57:27 +05:00
#include <utils/types.hpp>
2024-12-31 02:20:56 +05:00
#include <string>
#include <iostream>
2025-01-13 14:40:21 +05:00
#include <tls/Network.hpp>
#include <gateway/Websocket.hpp>
#include <vector>
2024-12-31 02:20:56 +05:00
using std::string;
using std::cout;
using std::endl;
class User {
private:
json data;
WebSocket& web;
NetworkManager& req;
public:
2025-01-13 14:40:21 +05:00
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;
2024-12-31 02:20:56 +05:00
}
2025-01-13 14:40:21 +05:00
virtual string me() {
return req.request("GET", dapi + "/users/@me");
2024-12-31 02:20:56 +05:00
}
bool isBot() {
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