diff --git a/libs/api/Bot.hpp b/libs/api/Bot.hpp index 0ea776c..41c1c65 100644 --- a/libs/api/Bot.hpp +++ b/libs/api/Bot.hpp @@ -24,15 +24,18 @@ public: Bot(const json& data) : data(data) { initializeNets(data); } - auto& use(const int number) { - return *std::get(net); - } +}; +class BotHandler : Bot<> { +private: + json data; +public: + BotHandler(const json& data) : data(data), Bot(data) {}; string id() { - return data["d"]["user"]["id"]; + return data["d"]["id"]; } bool isBot() { try { - return data["d"]["user"]["bot"]; + return data["d"]["bot"]; } catch (std::exception& e) { return false; diff --git a/libs/gateway/websocket.hpp b/libs/gateway/websocket.hpp index cb21b54..b3e8776 100644 --- a/libs/gateway/websocket.hpp +++ b/libs/gateway/websocket.hpp @@ -128,11 +128,10 @@ private: }} }} }; - using namespace ix; - initNetSystem(); + ix::initNetSystem(); webSocket.setUrl("wss://gateway.discord.gg/?v=10&encoding=json"); - webSocket.setOnMessageCallback([this](const WebSocketMessagePtr& msg) { - if (msg->type == WebSocketMessageType::Message) { + webSocket.setOnMessageCallback([this](const ix::WebSocketMessagePtr& msg) { + if (msg->type == ix::WebSocketMessageType::Message) { res = json::parse(msg->str); res["s"].is_number() ? lastS = res["s"] : false; chngcol(std::string("WEBSOCKET: " + std::to_string(lastS) + " " + res["op"].dump() + " " + res["t"].dump()), 0, 0, 120); diff --git a/sources/main.cpp b/sources/main.cpp index b6a944a..a05ef23 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,12 +17,12 @@ int main(int argc, char* argv[]) { bot->on(GatewayEvents::READY, [](const Bot& b) { cout << "started" << endl; }); - bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Bot& msg) { - if (g(2, msg.net)->isBot() == false) { - g(1, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); + bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot& msg) { + if (g(1, msg.net)->isBot() == false) { + g(0, msg.net)->send("939957962972229634", j("content", g(1, msg.net)->content())); } }); - bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [bot](const Bot& msg) { + bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [](const Bot& msg) { g(0, msg.net)->send("939957962972229634", j("content", "bye")); });