sparkle/libs/api/Bot.hpp
2025-01-20 16:07:42 +05:00

42 lines
1.0 KiB
C++

#ifndef API_BOT_HPP_
#define API_BOT_HPP_
#include <includes.h>
template<typename...Args>
class Discord {
private:
std::tuple<std::unique_ptr<Args>...> net;
nlohmann::json data;
void initializeNets(const nlohmann::json& data) {
initializeNetsImpl(data, std::index_sequence_for<Args...>{});
}
template<unsigned long... Is>
void initializeNetsImpl(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) {
initializeNets(data);
}
template<unsigned long Index>
auto& get() const {
return *std::get<Index>(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