36 lines
858 B
C++
Raw Normal View History

2025-01-29 16:06:47 +05:00
#ifndef INTERFACE_BOT_HPP_
#define INTERFACE_BOT_HPP_
2025-02-02 00:11:39 +05:00
#include <pch.hpp>
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-27 17:24:33 +05:00
const nlohmann::json& data;
2025-01-25 11:24:56 +05:00
std::tuple<std::unique_ptr<Args>...> net;
2024-12-31 02:20:56 +05:00
public:
2025-01-27 17:24:33 +05:00
Discord(const nlohmann::json& data) : data(data), net(std::make_tuple(std::make_unique<Args>(data)...)) {}
2025-01-25 15:46:27 +05:00
template<class T>
2025-01-30 23:05:59 +05:00
_deprecated_t("Use ctx() instead")
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-25 17:21:44 +05:00
const auto& ctx() const {
return 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:
2025-01-27 17:24:33 +05:00
const 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