sparkle/libs/api/Bot.hpp
2025-01-25 17:21:44 +05:00

41 lines
1.0 KiB
C++

#ifndef API_BOT_HPP_
#define API_BOT_HPP_
#include <includes.hpp>
template<typename...Args>
class Discord {
private:
std::tuple<std::unique_ptr<Args>...> net;
nlohmann::json data;
template<unsigned long... Is>
void initializeCtx(const nlohmann::json& data, std::index_sequence<Is...>) {
net = std::make_tuple(std::make_unique<Args>(data)...);
}
public:
Discord(const nlohmann::json& data) : data(data) {
initializeCtx(data, std::index_sequence_for<Args...>{});
}
template<class T>
[[deprecated("Use ctx() instead")]] auto& get() const {
return *std::get<std::unique_ptr<T>>(net);
}
const auto& ctx() const {
return net;
}
};
class Bot {
private:
nlohmann::json data;
public:
Bot(const nlohmann::json& data) : data(data) {};
std::string id() const {
return data["d"]["id"];
}
bool isBot() const {
try {
return data["d"]["bot"];
} catch (...) {
return false;
}
}
};
#endif