add guild role update, create, delete events

This commit is contained in:
ouwou 2020-12-14 01:40:22 -05:00
parent 1f19efc90e
commit 33ed25b2f6
4 changed files with 93 additions and 0 deletions

View File

@ -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;
}

View File

@ -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<void, Snowflake> type_signal_channel_update;
typedef sigc::signal<void, Snowflake> type_signal_channel_create;
typedef sigc::signal<void, Snowflake> type_signal_guild_update;
typedef sigc::signal<void, Snowflake> type_signal_role_update;
typedef sigc::signal<void, Snowflake> type_signal_role_create;
typedef sigc::signal<void, Snowflake> type_signal_role_delete;
typedef sigc::signal<void, bool> type_signal_disconnected; // bool true if reconnecting
typedef sigc::signal<void> 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;
};

View File

@ -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);
}

View File

@ -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);
};