diff --git a/include/net.hpp b/include/net.hpp index 127e0d0..ec6c3e2 100644 --- a/include/net.hpp +++ b/include/net.hpp @@ -1,5 +1,5 @@ #ifndef INCLUDE_NET_HPP_ #define INCLUDE_NET_HPP_ -#include <gateway/Websocket.hpp> -#include <network/Network.hpp> +#include <gateway/websocket.hpp> +#include <network/network.hpp> #endif \ No newline at end of file diff --git a/libs/gateway/Websocket.hpp b/libs/gateway/websocket.hpp similarity index 92% rename from libs/gateway/Websocket.hpp rename to libs/gateway/websocket.hpp index 74883c1..fbaa747 100644 --- a/libs/gateway/Websocket.hpp +++ b/libs/gateway/websocket.hpp @@ -6,7 +6,7 @@ class EventEmitter { private: using eventHandlers = std::function<void(const nlohmann::json&)>; - std::unordered_map<std::string, std::list<eventHandlers>> handlers; + std::unordered_map<std::string, std::vector<eventHandlers>> handlers; protected: void emit(const std::string& event, const nlohmann::json& data) { if (handlers.find(event) != handlers.end()) { @@ -80,8 +80,8 @@ private: case ix::WebSocketMessageType::Message: res = nlohmann::json::parse(msg->str); Log::create(INFO, WEBSOCKET, res["op"].dump() + " " + res["t"].dump()); - switch (res["op"].get<int>()) { - case 10: + switch (res["op"].get<GatewayOpcodes>()) { + case GatewayOpcodes::Hello: heartbeat_interval = res["d"]["heartbeat_interval"].get<int>(); !connected ? connected = true, webSocket.send(id.dump()) : 0; std::thread([this, &heartbeat_interval, &connected]() { @@ -92,7 +92,11 @@ private: } }).detach(); break; - case 0: emit(res["t"].get<std::string>(), res); break; + case GatewayOpcodes::Dispatch: + emit(res["t"].get<std::string>(), res); + break; + default: + break; } break; case ix::WebSocketMessageType::Error: diff --git a/libs/network/Network.hpp b/libs/network/network.hpp similarity index 98% rename from libs/network/Network.hpp rename to libs/network/network.hpp index a9bc59b..ce5945a 100644 --- a/libs/network/Network.hpp +++ b/libs/network/network.hpp @@ -1,7 +1,7 @@ #ifndef TLS_NETWORK_HPP_ #define TLS_NETWORK_HPP_ #include <includes.hpp> -#include <gateway/Websocket.hpp> +#include <gateway/websocket.hpp> #include <curl/curl.h> class NetworkManager { private: diff --git a/libs/utils/enums.hpp b/libs/utils/enums.hpp index 95e95d4..303b02e 100644 --- a/libs/utils/enums.hpp +++ b/libs/utils/enums.hpp @@ -140,4 +140,18 @@ enum UserStatus { enum DiscordTime { Epoch = 1420070400000, }; +enum GatewayOpcodes { + Dispatch, + Heartbeat, + Identify, + PresenceUpdate, + VoiceStateUpdate, + Resume = 6, + Reconnect, + RequestGuildMembers, + InvalidSession, + Hello, + HeartbeatACK, + RequestSoundboardSounds = 31, +}; #endif \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index cc39ae9..0b854d1 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -39,10 +39,7 @@ int main(int argc, char* argv[]) { message->send("939957962972229634", message->pack("content", author->channel_id)); } }); - bot->on(GatewayEvents::MESSAGE_REACTION_ADD, [](const Discord<Message>& msg) { - const auto& [message] = msg.ctx(); - message->send("939957962972229634", message->pack("content", "test")); - }); + bot->start(); return 0; } \ No newline at end of file