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.

42 lines
1018 B
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_BOT_HPP_
#define API_BOT_HPP_
2025-01-15 13:34:41 +05:00
#include <includes.h>
using std::string, std::cout, std::endl, nlohmann::json;
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:
void initializeNets(const json& data) {
initializeNetsImpl(data, std::index_sequence_for<Args...>{});
}
2025-01-20 03:09:27 +05:00
template<unsigned long... Is>void initializeNetsImpl(const json& data, std::index_sequence<Is...>) {
2024-12-31 02:20:56 +05:00
net = std::make_tuple(std::make_unique<Args>(data)...);
}
json data;
public:
std::tuple<std::unique_ptr<Args>...> net;
2025-01-19 04:35:20 +05:00
Discord(const json& data) : data(data) {
2024-12-31 02:20:56 +05:00
initializeNets(data);
}
2025-01-20 03:09:27 +05:00
template<unsigned long Index>
auto& get() const {
return *std::get<Index>(net);
}
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:
json data;
public:
2025-01-19 04:35:20 +05:00
Bot(const json& data) : data(data) {};
2024-12-31 02:20:56 +05:00
string id() {
2025-01-06 22:18:30 +05:00
return data["d"]["id"];
2024-12-31 02:20:56 +05:00
}
bool isBot() {
try {
2025-01-06 22:18:30 +05:00
return data["d"]["bot"];
2024-12-31 02:20:56 +05:00
}
2025-01-13 22:30:24 +05:00
catch (...) {
2024-12-31 02:20:56 +05:00
return false;
}
}
};
#endif