sparkle/libs/api/Bot.hpp

42 lines
1.0 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_BOT_HPP_
#define API_BOT_HPP_
2025-01-25 13:22:59 +05:00
#include <includes.hpp>
2025-01-25 15:46:27 +05:00
#include <variant>
2024-12-31 02:20:56 +05:00
template<typename...Args>
2025-01-19 04:35:20 +05:00
class Discord {
2024-12-31 02:20:56 +05:00
private:
2025-01-25 11:24:56 +05:00
std::tuple<std::unique_ptr<Args>...> net;
nlohmann::json data;
void initializeNets(const nlohmann::json& data) {
2024-12-31 02:20:56 +05:00
initializeNetsImpl(data, std::index_sequence_for<Args...>{});
}
template<unsigned long... Is>
2025-01-25 11:24:56 +05:00
void initializeNetsImpl(const nlohmann::json& data, std::index_sequence<Is...>) {
2024-12-31 02:20:56 +05:00
net = std::make_tuple(std::make_unique<Args>(data)...);
}
public:
2025-01-25 11:24:56 +05:00
Discord(const nlohmann::json& data) : data(data) {
2024-12-31 02:20:56 +05:00
initializeNets(data);
}
2025-01-25 15:46:27 +05:00
template<class T>
2025-01-25 11:24:56 +05:00
auto& get() const {
2025-01-25 15:46:27 +05:00
return *std::get<std::unique_ptr<T>>(net);
2025-01-25 11:24:56 +05:00
}
2025-01-06 22:18:30 +05:00
};
2025-01-19 04:35:20 +05:00
class Bot {
2025-01-06 22:18:30 +05:00
private:
2025-01-25 11:24:56 +05:00
nlohmann::json data;
2025-01-06 22:18:30 +05:00
public:
2025-01-25 11:24:56 +05:00
Bot(const nlohmann::json& data) : data(data) {};
std::string id() const {
2025-01-06 22:18:30 +05:00
return data["d"]["id"];
2024-12-31 02:20:56 +05:00
}
2025-01-25 11:24:56 +05:00
bool isBot() const {
2024-12-31 02:20:56 +05:00
try {
2025-01-06 22:18:30 +05:00
return data["d"]["bot"];
2025-01-25 13:22:59 +05:00
} catch (...) {
2024-12-31 02:20:56 +05:00
return false;
}
}
};
#endif