From 33ed25b2f66e727911182f1552aa8abfd558c69e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 14 Dec 2020 01:40:22 -0500 Subject: [PATCH] add guild role update, create, delete events --- discord/discord.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ discord/discord.hpp | 12 ++++++++++++ discord/objects.cpp | 15 +++++++++++++++ discord/objects.hpp | 24 ++++++++++++++++++++++++ 4 files changed, 93 insertions(+) diff --git a/discord/discord.cpp b/discord/discord.cpp index ec58293..0c34944 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -542,6 +542,15 @@ void DiscordClient::HandleGatewayMessage(std::string str) { case GatewayEvent::GUILD_UPDATE: { HandleGatewayGuildUpdate(m); } break; + case GatewayEvent::GUILD_ROLE_UPDATE: { + HandleGatewayGuildRoleUpdate(m); + } break; + case GatewayEvent::GUILD_ROLE_CREATE: { + HandleGatewayGuildRoleCreate(m); + } break; + case GatewayEvent::GUILD_ROLE_DELETE: { + HandleGatewayGuildRoleDelete(m); + } break; } } break; default: @@ -703,6 +712,24 @@ void DiscordClient::HandleGatewayGuildUpdate(const GatewayMessage &msg) { m_signal_guild_update.emit(id); } +void DiscordClient::HandleGatewayGuildRoleUpdate(const GatewayMessage &msg) { + GuildRoleUpdateObject data = msg.Data; + m_store.SetRole(data.Role.ID, data.Role); + m_signal_role_update.emit(data.Role.ID); +} + +void DiscordClient::HandleGatewayGuildRoleCreate(const GatewayMessage &msg) { + GuildRoleCreateObject data = msg.Data; + m_store.SetRole(data.Role.ID, data.Role); + m_signal_role_create.emit(data.Role.ID); +} + +void DiscordClient::HandleGatewayGuildRoleDelete(const GatewayMessage &msg) { + GuildRoleDeleteObject data = msg.Data; + // todo: actually delete it + m_signal_role_delete.emit(data.RoleID); +} + void DiscordClient::HandleGatewayReconnect(const GatewayMessage &msg) { m_signal_disconnected.emit(true); inflateEnd(&m_zstream); @@ -875,6 +902,9 @@ void DiscordClient::LoadEventMap() { m_event_map["CHANNEL_UPDATE"] = GatewayEvent::CHANNEL_UPDATE; m_event_map["CHANNEL_CREATE"] = GatewayEvent::CHANNEL_CREATE; m_event_map["GUILD_UPDATE"] = GatewayEvent::GUILD_UPDATE; + m_event_map["GUILD_ROLE_UPDATE"] = GatewayEvent::GUILD_ROLE_UPDATE; + m_event_map["GUILD_ROLE_CREATE"] = GatewayEvent::GUILD_ROLE_CREATE; + m_event_map["GUILD_ROLE_DELETE"] = GatewayEvent::GUILD_ROLE_DELETE; } DiscordClient::type_signal_gateway_ready DiscordClient::signal_gateway_ready() { @@ -928,3 +958,15 @@ DiscordClient::type_signal_disconnected DiscordClient::signal_disconnected() { DiscordClient::type_signal_connected DiscordClient::signal_connected() { return m_signal_connected; } + +DiscordClient::type_signal_role_update DiscordClient::signal_role_update() { + return m_signal_role_update; +} + +DiscordClient::type_signal_role_create DiscordClient::signal_role_create() { + return m_signal_role_create; +} + +DiscordClient::type_signal_role_delete DiscordClient::signal_role_delete() { + return m_signal_role_delete; +} diff --git a/discord/discord.hpp b/discord/discord.hpp index 17187d5..b9829dc 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -138,6 +138,9 @@ private: void HandleGatewayChannelUpdate(const GatewayMessage &msg); void HandleGatewayChannelCreate(const GatewayMessage &msg); void HandleGatewayGuildUpdate(const GatewayMessage &msg); + void HandleGatewayGuildRoleUpdate(const GatewayMessage &msg); + void HandleGatewayGuildRoleCreate(const GatewayMessage &msg); + void HandleGatewayGuildRoleDelete(const GatewayMessage &msg); void HandleGatewayReconnect(const GatewayMessage &msg); void HeartbeatThread(); void SendIdentify(); @@ -197,6 +200,9 @@ public: typedef sigc::signal type_signal_channel_update; typedef sigc::signal type_signal_channel_create; typedef sigc::signal type_signal_guild_update; + typedef sigc::signal type_signal_role_update; + typedef sigc::signal type_signal_role_create; + typedef sigc::signal type_signal_role_delete; typedef sigc::signal type_signal_disconnected; // bool true if reconnecting typedef sigc::signal type_signal_connected; @@ -211,6 +217,9 @@ public: type_signal_channel_update signal_channel_update(); type_signal_channel_create signal_channel_create(); type_signal_guild_update signal_guild_update(); + type_signal_role_update signal_role_update(); + type_signal_role_create signal_role_create(); + type_signal_role_delete signal_role_delete(); type_signal_disconnected signal_disconnected(); type_signal_connected signal_connected(); @@ -226,6 +235,9 @@ protected: type_signal_channel_update m_signal_channel_update; type_signal_channel_create m_signal_channel_create; type_signal_guild_update m_signal_guild_update; + type_signal_role_update m_signal_role_update; + type_signal_role_create m_signal_role_create; + type_signal_role_delete m_signal_role_delete; type_signal_disconnected m_signal_disconnected; type_signal_connected m_signal_connected; }; diff --git a/discord/objects.cpp b/discord/objects.cpp index 5936785..ac1dc02 100644 --- a/discord/objects.cpp +++ b/discord/objects.cpp @@ -179,3 +179,18 @@ void to_json(nlohmann::json &j, const ResumeMessage &m) { j["d"]["session_id"] = m.SessionID; j["d"]["seq"] = m.Sequence; } + +void from_json(const nlohmann::json &j, GuildRoleUpdateObject &m) { + JS_D("guild_id", m.GuildID); + JS_D("role", m.Role); +} + +void from_json(const nlohmann::json &j, GuildRoleCreateObject &m) { + JS_D("guild_id", m.GuildID); + JS_D("role", m.Role); +} + +void from_json(const nlohmann::json &j, GuildRoleDeleteObject &m) { + JS_D("guild_id", m.GuildID); + JS_D("role_id", m.RoleID); +} diff --git a/discord/objects.hpp b/discord/objects.hpp index 7e325e4..8651068 100644 --- a/discord/objects.hpp +++ b/discord/objects.hpp @@ -46,6 +46,9 @@ enum class GatewayEvent : int { CHANNEL_UPDATE, CHANNEL_CREATE, GUILD_UPDATE, + GUILD_ROLE_UPDATE, + GUILD_ROLE_CREATE, + GUILD_ROLE_DELETE, }; struct GatewayMessage { @@ -251,3 +254,24 @@ struct ResumeMessage : GatewayMessage { friend void to_json(nlohmann::json &j, const ResumeMessage &m); }; + +struct GuildRoleUpdateObject { + Snowflake GuildID; + Role Role; + + friend void from_json(const nlohmann::json &j, GuildRoleUpdateObject &m); +}; + +struct GuildRoleCreateObject { + Snowflake GuildID; + Role Role; + + friend void from_json(const nlohmann::json &j, GuildRoleCreateObject &m); +}; + +struct GuildRoleDeleteObject { + Snowflake GuildID; + Snowflake RoleID; + + friend void from_json(const nlohmann::json &j, GuildRoleDeleteObject &m); +};