45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#ifndef API_USER_HPP_
|
|
#define API_USER_HPP_
|
|
#include <utils/types.hpp>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <tls/Network.hpp>
|
|
#include <gateway/Websocket.hpp>
|
|
#include <vector>
|
|
using std::string;
|
|
using std::cout;
|
|
using std::endl;
|
|
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 |