fluttershy 61e59be26e fixes
2025-02-02 00:11:39 +05:00

37 lines
1.1 KiB
C++

#ifndef INTERFACE_USER_HPP_
#define INTERFACE_USER_HPP_
#include <pch.hpp>
#include <network.hpp>
#include <vector>
class User {
private:
const nlohmann::json& data;
WebSocket& web;
NetworkManager& req;
public:
User(const nlohmann::json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()),
isBot(false) {
auto botValue = functions::testValue<bool>(data, { "d", "user", "bot" });
if (botValue.has_value()) {
isBot = botValue.value();
}
}
bool isBot;
auto extract(const std::vector<std::string>& keys) -> nlohmann::json {
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;
};
auto me() -> std::string {
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/users/@me");
}
};
#endif