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.

37 lines
1.1 KiB
C++
Raw Normal View History

2025-01-29 16:06:47 +05:00
#ifndef INTERFACE_USER_HPP_
#define INTERFACE_USER_HPP_
2025-01-25 13:22:59 +05:00
#include <includes.hpp>
2025-01-29 16:06:47 +05:00
#include <network.hpp>
2025-01-13 14:40:21 +05:00
#include <vector>
2024-12-31 02:20:56 +05:00
class User {
private:
2025-01-27 17:24:33 +05:00
const nlohmann::json& data;
2024-12-31 02:20:56 +05:00
WebSocket& web;
NetworkManager& req;
public:
2025-01-27 22:02:21 +05:00
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();
}
}
2025-01-26 23:33:52 +05:00
bool isBot;
2025-01-30 23:05:59 +05:00
auto extract(const std::vector<std::string>& keys) -> nlohmann::json {
2025-01-25 11:24:56 +05:00
std::vector<std::string> d = { "d" };
2025-01-13 14:40:21 +05:00
d.insert(d.end(), keys.begin(), keys.end());
2025-01-25 11:24:56 +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];
2025-01-25 13:22:59 +05:00
} else {
2025-01-13 14:40:21 +05:00
return "Key not found.";
}
}
return current;
2025-01-26 23:33:52 +05:00
};
2025-01-30 23:05:59 +05:00
auto me() -> std::string {
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
}
};
#endif