diff --git a/libs/api/Bot.hpp b/libs/api/Bot.hpp index 7a95b43..f558026 100644 --- a/libs/api/Bot.hpp +++ b/libs/api/Bot.hpp @@ -1,27 +1,26 @@ #ifndef API_BOT_HPP_ #define API_BOT_HPP_ #include <includes.hpp> -#include <variant> 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...>) { + 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) { - initializeNets(data); + initializeCtx(data, std::index_sequence_for<Args...>{}); } template<class T> - auto& get() const { + [[deprecated("Use ctx() instead")]] auto& get() const { return *std::get<std::unique_ptr<T>>(net); } + const auto& ctx() const { + return net; + } }; class Bot { private: diff --git a/sources/main.cpp b/sources/main.cpp index d8b1567..9449ffb 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -3,12 +3,14 @@ int main(int argc, char* argv[]) { if (argc != 3) return -1; WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents); - bot->on(GatewayEvents::READY, [](const nlohmann::json&) { - std::cout << DiscordEndpoints::details::latest << std::endl; + bot->on(GatewayEvents::READY, [](const Discord<User>& b) { + auto& [user] = b.ctx(); + std::cout << nlohmann::json::parse(user->me())["username"].get<std::string>() << std::endl; }); - bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author, Message::Api>& ctx) { - if (!ctx.get<Author>().isBot) { - ctx.get<Message>().send("939957962972229634", ctx.get<Message>().pack("content", ctx.get<Author>().avatar)); + bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author, Message::Api>& msg) { + const auto& [message, user, author, _] = msg.ctx(); + if (!author->isBot) { + message->send("939957962972229634", message->pack("content", author->avatar)); } }); bot->start();