From 315a4a8df80b922bbb8132c625803443c031dfd3 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 15 Dec 2020 02:45:37 -0500 Subject: fix some reaction stuff --- discord/discord.cpp | 26 ++++++++++++++++++++------ discord/discord.hpp | 2 ++ discord/store.cpp | 16 +++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) (limited to 'discord') diff --git a/discord/discord.cpp b/discord/discord.cpp index 2151d86..9e6726c 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -121,9 +121,8 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::functionReactions.has_value()) to->Reactions.emplace(); // add if present @@ -1018,6 +1020,18 @@ bool DiscordClient::CheckCode(const cpr::Response &r) { return true; } +void DiscordClient::StoreMessageData(const Message &msg) { + m_store.SetMessage(msg.ID, msg); + m_store.SetUser(msg.Author.ID, msg.Author); + if (msg.Reactions.has_value()) + for (const auto &r : *msg.Reactions) { + if (!r.Emoji.ID.IsValid()) continue; + const auto cur = m_store.GetEmoji(r.Emoji.ID); + if (!cur.has_value()) + m_store.SetEmoji(r.Emoji.ID, r.Emoji); + } +} + void DiscordClient::LoadEventMap() { m_event_map["READY"] = GatewayEvent::READY; m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE; diff --git a/discord/discord.hpp b/discord/discord.hpp index 767cf7a..c43a764 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -154,6 +154,8 @@ private: bool CheckCode(const cpr::Response &r); + void StoreMessageData(const Message &msg); + std::string m_token; void AddMessageToChannel(Snowflake msg_id, Snowflake channel_id); diff --git a/discord/store.cpp b/discord/store.cpp index bf6318a..44933bb 100644 --- a/discord/store.cpp +++ b/discord/store.cpp @@ -328,11 +328,17 @@ std::optional Store::GetEmoji(Snowflake id) const { Emoji ret; ret.ID = id; Get(m_get_emote_stmt, 1, ret.Name); - std::string tmp; - Get(m_get_emote_stmt, 2, tmp); - ret.Roles = nlohmann::json::parse(tmp).get>(); - ret.Creator = std::optional(User()); - Get(m_get_emote_stmt, 3, ret.Creator->ID); + + if (!IsNull(m_get_emote_stmt, 2)) { + std::string tmp; + Get(m_get_emote_stmt, 2, tmp); + ret.Roles = nlohmann::json::parse(tmp).get>(); + } + + if (!IsNull(m_get_emote_stmt, 3)) { + ret.Creator = std::optional(User()); + Get(m_get_emote_stmt, 3, ret.Creator->ID); + } Get(m_get_emote_stmt, 3, ret.NeedsColons); Get(m_get_emote_stmt, 4, ret.IsManaged); Get(m_get_emote_stmt, 5, ret.IsAnimated); -- cgit v1.2.3