From dfd642bb82d2998cc563f0f401f2d522632692c1 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 20 Jan 2022 01:34:36 -0500 Subject: show unread indicators for threads --- src/discord/discord.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 5b3cdb5..ff269df 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -2343,10 +2343,14 @@ void DiscordClient::StoreMessageData(Message &msg) { // here the absence of an entry in m_unread indicates a read channel and the value is only the mention count since the message doesnt matter // no entry.id cannot be a guild even though sometimes it looks like it void DiscordClient::HandleReadyReadState(const ReadyEventData &data) { - for (const auto &guild : data.Guilds) + for (const auto &guild : data.Guilds) { for (const auto &channel : *guild.Channels) if (channel.LastMessageID.has_value()) m_last_message_id[channel.ID] = *channel.LastMessageID; + for (const auto &thread : *guild.Threads) + if (thread.LastMessageID.has_value()) + m_last_message_id[thread.ID] = *thread.LastMessageID; + } for (const auto &channel : data.PrivateChannels) if (channel.LastMessageID.has_value()) m_last_message_id[channel.ID] = *channel.LastMessageID; -- cgit v1.2.3 From 2328c8bafee708fc33dcd004562a270183ebcf30 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 20 Jan 2022 01:40:27 -0500 Subject: handle initial muted state for threads --- src/discord/channel.cpp | 2 ++ src/discord/channel.hpp | 10 ++++++++++ src/discord/discord.cpp | 6 +++++- src/discord/objects.hpp | 8 -------- 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src/discord') diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index 2f5c3c1..dcd3b8f 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -13,6 +13,8 @@ void from_json(const nlohmann::json &j, ThreadMemberObject &m) { JS_O("user_id", m.UserID); JS_D("join_timestamp", m.JoinTimestamp); JS_D("flags", m.Flags); + JS_O("muted", m.IsMuted); + JS_ON("mute_config", m.MuteConfig); } void from_json(const nlohmann::json &j, ChannelData &m) { diff --git a/src/discord/channel.hpp b/src/discord/channel.hpp index 195a09a..4485b0b 100644 --- a/src/discord/channel.hpp +++ b/src/discord/channel.hpp @@ -49,9 +49,19 @@ struct ThreadMetadataData { friend void from_json(const nlohmann::json &j, ThreadMetadataData &m); }; +struct MuteConfigData { + std::optional EndTime; // nullopt is encoded as null + int SelectedTimeWindow; + + friend void from_json(const nlohmann::json &j, MuteConfigData &m); + friend void to_json(nlohmann::json &j, const MuteConfigData &m); +}; + struct ThreadMemberObject { std::optional ThreadID; std::optional UserID; + std::optional IsMuted; + std::optional MuteConfig; std::string JoinTimestamp; int Flags; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index ff269df..e123818 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -2389,10 +2389,14 @@ void DiscordClient::HandleReadyGuildSettings(const ReadyEventData &data) { // i dont like this implementation for muted categories but its rather simple and doesnt use a horriiible amount of ram std::unordered_map> category_children; - for (const auto &guild : data.Guilds) + for (const auto &guild : data.Guilds) { for (const auto &channel : *guild.Channels) if (channel.ParentID.has_value() && !channel.IsThread()) category_children[*channel.ParentID].push_back(channel.ID); + for (const auto &thread : *guild.Threads) + if (thread.ThreadMember.has_value() && thread.ThreadMember->IsMuted.has_value() && *thread.ThreadMember->IsMuted) + m_muted_channels.insert(thread.ID); + } const auto now = Snowflake::FromNow(); for (const auto &entry : data.GuildSettings.Entries) { diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index c72361b..8568222 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -244,14 +244,6 @@ struct ReadStateData { friend void from_json(const nlohmann::json &j, ReadStateData &m); }; -struct MuteConfigData { - std::optional EndTime; // nullopt is encoded as null - int SelectedTimeWindow; - - friend void from_json(const nlohmann::json &j, MuteConfigData &m); - friend void to_json(nlohmann::json &j, const MuteConfigData &m); -}; - struct UserGuildSettingsChannelOverride { bool Muted; MuteConfigData MuteConfig; -- cgit v1.2.3 From d7f3ee9f983458bdaf504c5813adc93bed1404e4 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 20 Jan 2022 01:52:48 -0500 Subject: handle mute/unmute updates for threads --- src/discord/discord.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/discord') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index e123818..ab821a8 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1921,9 +1921,24 @@ void DiscordClient::HandleGatewayThreadMembersUpdate(const GatewayMessage &msg) void DiscordClient::HandleGatewayThreadMemberUpdate(const GatewayMessage &msg) { ThreadMemberUpdateData data = msg.Data; + if (!data.Member.ThreadID.has_value()) return; + m_joined_threads.insert(*data.Member.ThreadID); if (*data.Member.UserID == GetUserData().ID) m_signal_added_to_thread.emit(*data.Member.ThreadID); + + if (data.Member.IsMuted.has_value()) { + const bool was_muted = IsChannelMuted(*data.Member.ThreadID); + const bool now_muted = *data.Member.IsMuted; + + if (was_muted && !now_muted) { + m_muted_channels.erase(*data.Member.ThreadID); + m_signal_channel_unmuted.emit(*data.Member.ThreadID); + } else if (!was_muted && now_muted) { + m_muted_channels.insert(*data.Member.ThreadID); + m_signal_channel_muted.emit(*data.Member.ThreadID); + } + } } void DiscordClient::HandleGatewayThreadUpdate(const GatewayMessage &msg) { -- cgit v1.2.3 From b6b215ee6f08e4e7d6d987ffd676cebeb8638a62 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 20 Jan 2022 02:45:28 -0500 Subject: add mark as unread/toggle mute for threads --- src/components/channels.cpp | 27 ++++++++++++++++++++++++--- src/components/channels.hpp | 2 ++ src/discord/discord.cpp | 18 ++++++++++++++++++ src/discord/discord.hpp | 2 ++ 4 files changed, 46 insertions(+), 3 deletions(-) (limited to 'src/discord') diff --git a/src/components/channels.cpp b/src/components/channels.cpp index 5385b23..c0d1a8b 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -22,7 +22,8 @@ ChannelList::ChannelList() , m_menu_thread_copy_id("_Copy ID", true) , m_menu_thread_leave("_Leave", true) , m_menu_thread_archive("_Archive", true) - , m_menu_thread_unarchive("_Unarchive", true) { + , m_menu_thread_unarchive("_Unarchive", true) + , m_menu_thread_mark_as_read("Mark as _Read", true) { get_style_context()->add_class("channel-list"); // todo: move to method @@ -187,10 +188,23 @@ ChannelList::ChannelList() m_menu_thread_unarchive.signal_activate().connect([this] { Abaddon::Get().GetDiscordClient().UnArchiveThread(static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {}); }); - m_menu_thread.append(m_menu_thread_copy_id); + m_menu_thread_mark_as_read.signal_activate().connect([this] { + Abaddon::Get().GetDiscordClient().MarkChannelAsRead(static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), NOOP_CALLBACK); + }); + m_menu_thread_toggle_mute.signal_activate().connect([this] { + const auto id = static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); + auto &discord = Abaddon::Get().GetDiscordClient(); + if (discord.IsChannelMuted(id)) + discord.UnmuteThread(id, NOOP_CALLBACK); + else + discord.MuteThread(id, NOOP_CALLBACK); + }); + m_menu_thread.append(m_menu_thread_mark_as_read); + m_menu_thread.append(m_menu_thread_toggle_mute); m_menu_thread.append(m_menu_thread_leave); m_menu_thread.append(m_menu_thread_archive); m_menu_thread.append(m_menu_thread_unarchive); + m_menu_thread.append(m_menu_thread_copy_id); m_menu_thread.show_all(); m_menu_guild.signal_popped_up().connect(sigc::mem_fun(*this, &ChannelList::OnGuildSubmenuPopup)); @@ -914,7 +928,14 @@ void ChannelList::OnThreadSubmenuPopup(const Gdk::Rectangle *flipped_rect, const auto &discord = Abaddon::Get().GetDiscordClient(); auto iter = m_model->get_iter(m_path_for_menu); if (!iter) return; - auto channel = discord.GetChannel(static_cast((*iter)[m_columns.m_id])); + const auto id = static_cast((*iter)[m_columns.m_id]); + + if (discord.IsChannelMuted(id)) + m_menu_thread_toggle_mute.set_label("Unmute"); + else + m_menu_thread_toggle_mute.set_label("Mute"); + + auto channel = discord.GetChannel(id); if (!channel.has_value() || !channel->ThreadMetadata.has_value()) return; if (!discord.HasGuildPermission(discord.GetUserData().ID, *channel->GuildID, Permission::MANAGE_THREADS)) return; diff --git a/src/components/channels.hpp b/src/components/channels.hpp index 4ec0587..a2553fd 100644 --- a/src/components/channels.hpp +++ b/src/components/channels.hpp @@ -131,6 +131,8 @@ protected: Gtk::MenuItem m_menu_thread_leave; Gtk::MenuItem m_menu_thread_archive; Gtk::MenuItem m_menu_thread_unarchive; + Gtk::MenuItem m_menu_thread_mark_as_read; + Gtk::MenuItem m_menu_thread_toggle_mute; void OnGuildSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); void OnCategorySubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index ab821a8..8d1cf12 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -983,6 +983,24 @@ void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":true})", [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + +void DiscordClient::UnmuteThread(Snowflake id, sigc::slot callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":false})", [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + void DiscordClient::FetchPinned(Snowflake id, sigc::slot, DiscordError code)> callback) { // return from db if we know the pins have already been requested if (m_channels_pinned_requested.find(id) != m_channels_pinned_requested.end()) { diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 1a6aa14..4a7593d 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -146,6 +146,8 @@ public: void MarkAllAsRead(sigc::slot callback); void MuteGuild(Snowflake id, sigc::slot callback); void UnmuteGuild(Snowflake id, sigc::slot callback); + void MuteThread(Snowflake id, sigc::slot callback); + void UnmuteThread(Snowflake id, sigc::slot callback); bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const; -- cgit v1.2.3 From 7d49f934bc1bb87a5b811374433f574733963188 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 26 Jan 2022 18:43:47 -0500 Subject: muted dms dont contribute to unread count --- src/discord/discord.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 8d1cf12..78f2c35 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1224,7 +1224,7 @@ int DiscordClient::GetUnreadDMsCount() const { const auto channels = GetPrivateChannels(); int count = 0; for (const auto channel_id : channels) - if (GetUnreadStateForChannel(channel_id) > -1) count++; + if (!IsChannelMuted(channel_id) && GetUnreadStateForChannel(channel_id) > -1) count++; return count; } -- cgit v1.2.3 From f7845509646b6ddaab7209fac0d8caac77e9aa2c Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 2 Feb 2022 22:27:19 -0500 Subject: support channel icons for dms --- src/components/channels.cpp | 8 +++++++- src/discord/channel.cpp | 8 ++++++++ src/discord/channel.hpp | 2 ++ src/discord/store.cpp | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/components/channels.cpp b/src/components/channels.cpp index c0d1a8b..99bd07b 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -752,7 +752,13 @@ void ChannelList::AddPrivateChannels() { else if (dm->Type == ChannelType::GROUP_DM) row[m_columns.m_name] = std::to_string(recipients.size()) + " members"; - if (top_recipient.has_value()) { + if (dm->HasIcon()) { + const auto cb = [this, iter](const Glib::RefPtr &pb) { + if (iter) + (*iter)[m_columns.m_icon] = pb->scale_simple(DMIconSize, DMIconSize, Gdk::INTERP_BILINEAR); + }; + img.LoadFromURL(dm->GetIconURL(), sigc::track_obj(cb, *this)); + } else if (top_recipient.has_value()) { const auto cb = [this, iter](const Glib::RefPtr &pb) { if (iter) (*iter)[m_columns.m_icon] = pb->scale_simple(DMIconSize, DMIconSize, Gdk::INTERP_BILINEAR); diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index dcd3b8f..9d47076 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -84,6 +84,14 @@ bool ChannelData::IsCategory() const noexcept { return Type == ChannelType::GUILD_CATEGORY; } +bool ChannelData::HasIcon() const noexcept { + return Icon.has_value(); +} + +std::string ChannelData::GetIconURL() const { + return "https://cdn.discordapp.com/channel-icons/" + std::to_string(ID) + "/" + *Icon + ".png"; +} + std::vector ChannelData::GetChildIDs() const { return Abaddon::Get().GetDiscordClient().GetChildChannelIDs(ID); } diff --git a/src/discord/channel.hpp b/src/discord/channel.hpp index 4485b0b..89e43a0 100644 --- a/src/discord/channel.hpp +++ b/src/discord/channel.hpp @@ -99,6 +99,8 @@ struct ChannelData { bool IsThread() const noexcept; bool IsJoinedThread() const; bool IsCategory() const noexcept; + bool HasIcon() const noexcept; + std::string GetIconURL() const; std::vector GetChildIDs() const; std::optional GetOverwrite(Snowflake id) const; std::vector GetDMRecipients() const; diff --git a/src/discord/store.cpp b/src/discord/store.cpp index e182c70..a5b0c13 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -646,6 +646,7 @@ std::optional Store::GetChannel(Snowflake id) const { s->Get(6, r.IsNSFW); s->Get(7, r.LastMessageID); s->Get(10, r.RateLimitPerUser); + s->Get(11, r.Icon); s->Get(12, r.OwnerID); s->Get(14, r.ParentID); if (!s->IsNull(16)) { -- cgit v1.2.3 From 179ff980e93b1e4f54127b474785b5f0dde3cdc1 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 2 Feb 2022 22:34:54 -0500 Subject: fix ready parsing (#54) --- src/discord/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 8ca8c0f..8d85f9a 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -154,7 +154,7 @@ void to_json(nlohmann::json &j, const UserGuildSettingsChannelOverride &m) { void from_json(const nlohmann::json &j, MuteConfigData &m) { JS_ON("end_time", m.EndTime); - JS_D("selected_time_window", m.SelectedTimeWindow); + JS_ON("selected_time_window", m.SelectedTimeWindow); } void to_json(nlohmann::json &j, const MuteConfigData &m) { -- cgit v1.2.3 From 25fd2c38400d3cafa63343721899d59b42e639a5 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 14 Feb 2022 02:53:21 -0500 Subject: fix per-guild avatars --- src/components/chatmessage.cpp | 8 ++++---- src/discord/user.cpp | 29 ++++++++++++++++++++++++----- src/discord/user.hpp | 4 +++- 3 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src/discord') diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp index e5a65cd..d34730b 100644 --- a/src/components/chatmessage.cpp +++ b/src/components/chatmessage.cpp @@ -1,7 +1,7 @@ -#include "chatmessage.hpp" #include "abaddon.hpp" -#include "util.hpp" +#include "chatmessage.hpp" #include "lazyimage.hpp" +#include "util.hpp" #include constexpr static int EmojiSize = 24; // settings eventually @@ -1068,11 +1068,11 @@ ChatMessageHeader::ChatMessageHeader(const Message &data) }; img.LoadFromURL(author->GetAvatarURL(data.GuildID), sigc::track_obj(cb, *this)); - if (author->HasAnimatedAvatar()) { + if (author->HasAnimatedAvatar(data.GuildID)) { auto cb = [this](const Glib::RefPtr &pb) { m_anim_avatar = pb; }; - img.LoadAnimationFromURL(author->GetAvatarURL("gif"), AvatarSize, AvatarSize, sigc::track_obj(cb, *this)); + img.LoadAnimationFromURL(author->GetAvatarURL(data.GuildID, "gif"), AvatarSize, AvatarSize, sigc::track_obj(cb, *this)); } get_style_context()->add_class("message-container"); diff --git a/src/discord/user.cpp b/src/discord/user.cpp index fae212d..6df53aa 100644 --- a/src/discord/user.cpp +++ b/src/discord/user.cpp @@ -6,22 +6,41 @@ bool UserData::IsDeleted() const { } bool UserData::HasAvatar() const { - return Avatar.size() > 0; + return !Avatar.empty(); } -bool UserData::HasAnimatedAvatar() const { - return Avatar.size() > 0 && Avatar[0] == 'a' && Avatar[1] == '_'; +bool UserData::HasAnimatedAvatar() const noexcept { + return !Avatar.empty() && Avatar[0] == 'a' && Avatar[1] == '_'; +} + +bool UserData::HasAnimatedAvatar(Snowflake guild_id) const { + const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id); + if (member.has_value() && member->Avatar.has_value() && member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_') + return true; + else if (!member->Avatar.has_value()) + return HasAnimatedAvatar(); + return false; +} + +bool UserData::HasAnimatedAvatar(const std::optional &guild_id) const { + if (guild_id.has_value()) + return HasAnimatedAvatar(*guild_id); + else + return HasAnimatedAvatar(); } std::string UserData::GetAvatarURL(Snowflake guild_id, std::string ext, std::string size) const { const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id); - if (member.has_value() && member->Avatar.has_value()) + if (member.has_value() && member->Avatar.has_value()) { + if (ext == "gif" && !(member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_')) + return GetAvatarURL(ext, size); return "https://cdn.discordapp.com/guilds/" + std::to_string(guild_id) + "/users/" + std::to_string(ID) + "/avatars/" + *member->Avatar + "." + ext + "?" + "size=" + size; - else + } else { return GetAvatarURL(ext, size); + } } std::string UserData::GetAvatarURL(const std::optional &guild_id, std::string ext, std::string size) const { diff --git a/src/discord/user.hpp b/src/discord/user.hpp index d4711fa..c058ea1 100644 --- a/src/discord/user.hpp +++ b/src/discord/user.hpp @@ -62,7 +62,9 @@ struct UserData { bool IsDeleted() const; bool HasAvatar() const; - bool HasAnimatedAvatar() const; + bool HasAnimatedAvatar() const noexcept; + bool HasAnimatedAvatar(Snowflake guild_id) const; + bool HasAnimatedAvatar(const std::optional &guild_id) const; std::string GetAvatarURL(Snowflake guild_id, std::string ext = "png", std::string size = "32") const; std::string GetAvatarURL(const std::optional &guild_id, std::string ext = "png", std::string size = "32") const; std::string GetAvatarURL(std::string ext = "png", std::string size = "32") const; -- cgit v1.2.3 From 7ed415040a982fc0c2f95ce3c7a0f31d78655df0 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 17 Feb 2022 02:14:19 -0500 Subject: delete database instead of trying to clear it --- src/discord/store.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/discord') diff --git a/src/discord/store.cpp b/src/discord/store.cpp index a5b0c13..d96bb1f 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -13,18 +13,6 @@ Store::Store(bool mem_store) return; } - m_db.Execute(R"( - PRAGMA writable_schema = 1; - DELETE FROM sqlite_master WHERE TYPE IN ("view", "table", "index", "trigger"); - PRAGMA writable_schema = 0; - VACUUM; - PRAGMA integrity_check; - )"); - if (!m_db.OK()) { - fprintf(stderr, "failed to clear database: %s\n", m_db.ErrStr()); - return; - } - if (m_db.Execute("PRAGMA journal_mode = WAL") != SQLITE_OK) { fprintf(stderr, "enabling write-ahead-log failed: %s\n", m_db.ErrStr()); return; @@ -2150,6 +2138,13 @@ bool Store::CreateStatements() { } Store::Database::Database(const char *path) { + if (path != ":memory:"s) { + std::error_code ec; + if (std::filesystem::exists(path, ec) && !std::filesystem::remove(path, ec)) { + fprintf(stderr, "the database could not be removed. the database may be corrupted as a result\n"); + } + } + m_err = sqlite3_open(path, &m_db); } -- cgit v1.2.3 From a0599ab812280c74fdeb6b622bf9701f10d659ea Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 20 Feb 2022 01:19:18 -0500 Subject: parse role mentions --- src/components/chatmessage.cpp | 43 +++++++++++++++++++++++++++++++++++++++++- src/components/chatmessage.hpp | 3 ++- src/discord/role.cpp | 8 ++++++++ src/discord/role.hpp | 3 +++ 4 files changed, 55 insertions(+), 2 deletions(-) (limited to 'src/discord') diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp index d34730b..69e46a6 100644 --- a/src/components/chatmessage.cpp +++ b/src/components/chatmessage.cpp @@ -203,6 +203,7 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { case MessageType::DEFAULT: case MessageType::INLINE_REPLY: b->insert(s, data->Content); + HandleRoleMentions(b); HandleUserMentions(b); HandleLinks(*tv); HandleChannelMentions(tv); @@ -736,7 +737,47 @@ bool ChatMessageItemContainer::IsEmbedImageOnly(const EmbedData &data) { return data.Thumbnail->ProxyURL.has_value() && data.Thumbnail->URL.has_value() && data.Thumbnail->Width.has_value() && data.Thumbnail->Height.has_value(); } -void ChatMessageItemContainer::HandleUserMentions(Glib::RefPtr buf) { +void ChatMessageItemContainer::HandleRoleMentions(const Glib::RefPtr &buf) { + constexpr static const auto mentions_regex = R"(<@&(\d+)>)"; + + static auto rgx = Glib::Regex::create(mentions_regex); + + Glib::ustring text = GetText(buf); + const auto &discord = Abaddon::Get().GetDiscordClient(); + + int startpos = 0; + Glib::MatchInfo match; + while (rgx->match(text, startpos, match)) { + int mstart, mend; + if (!match.fetch_pos(0, mstart, mend)) break; + const Glib::ustring role_id = match.fetch(1); + const auto role = discord.GetRole(role_id); + if (!role.has_value()) { + startpos = mend; + continue; + } + + Glib::ustring replacement; + if (role->HasColor()) { + replacement = "Color) + "\">@" + role->GetEscapedName() + ""; + } else { + replacement = "@" + role->GetEscapedName() + ""; + } + + const auto chars_start = g_utf8_pointer_to_offset(text.c_str(), text.c_str() + mstart); + const auto chars_end = g_utf8_pointer_to_offset(text.c_str(), text.c_str() + mend); + const auto start_it = buf->get_iter_at_offset(chars_start); + const auto end_it = buf->get_iter_at_offset(chars_end); + + auto it = buf->erase(start_it, end_it); + buf->insert_markup(it, replacement); + + text = GetText(buf); + startpos = 0; + } +} + +void ChatMessageItemContainer::HandleUserMentions(const Glib::RefPtr &buf) { constexpr static const auto mentions_regex = R"(<@!?(\d+)>)"; static auto rgx = Glib::Regex::create(mentions_regex); diff --git a/src/components/chatmessage.hpp b/src/components/chatmessage.hpp index 8b69117..bd99275 100644 --- a/src/components/chatmessage.hpp +++ b/src/components/chatmessage.hpp @@ -34,7 +34,8 @@ protected: static bool IsEmbedImageOnly(const EmbedData &data); - void HandleUserMentions(Glib::RefPtr buf); + void HandleRoleMentions(const Glib::RefPtr &buf); + void HandleUserMentions(const Glib::RefPtr &buf); void HandleStockEmojis(Gtk::TextView &tv); void HandleCustomEmojis(Gtk::TextView &tv); void HandleEmojis(Gtk::TextView &tv); diff --git a/src/discord/role.cpp b/src/discord/role.cpp index 07a912e..8a9ed50 100644 --- a/src/discord/role.cpp +++ b/src/discord/role.cpp @@ -12,3 +12,11 @@ void from_json(const nlohmann::json &j, RoleData &m) { JS_D("managed", m.IsManaged); JS_D("mentionable", m.IsMentionable); } + +bool RoleData::HasColor() const noexcept { + return Color != 0; +} + +Glib::ustring RoleData::GetEscapedName() const { + return Glib::Markup::escape_text(Name); +} diff --git a/src/discord/role.hpp b/src/discord/role.hpp index f638b65..a526f4e 100644 --- a/src/discord/role.hpp +++ b/src/discord/role.hpp @@ -16,5 +16,8 @@ struct RoleData { bool IsManaged; bool IsMentionable; + bool HasColor() const noexcept; + Glib::ustring GetEscapedName() const; + friend void from_json(const nlohmann::json &j, RoleData &m); }; -- cgit v1.2.3 From 17f1289c84af11b6e02f5f5de4714c8aad18e47e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 3 Mar 2022 03:01:09 -0500 Subject: fill out gateway op enum using internal names --- src/discord/discord.cpp | 2 +- src/discord/objects.cpp | 4 ++-- src/discord/objects.hpp | 25 ++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/discord') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 78f2c35..6ea0ea6 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1328,7 +1328,7 @@ void DiscordClient::HandleGatewayMessage(std::string str) { case GatewayOp::InvalidSession: { HandleGatewayInvalidSession(m); } break; - case GatewayOp::Event: { + case GatewayOp::Dispatch: { auto iter = m_event_map.find(m.Type); if (iter == m_event_map.end()) { printf("Unknown event %s\n", m.Type.c_str()); diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 8d85f9a..0ee96dc 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -77,7 +77,7 @@ void from_json(const nlohmann::json &j, GuildMemberListUpdateMessage &m) { } void to_json(nlohmann::json &j, const LazyLoadRequestMessage &m) { - j["op"] = GatewayOp::LazyLoadRequest; + j["op"] = GatewayOp::GuildSubscriptions; j["d"] = nlohmann::json::object(); j["d"]["guild_id"] = m.GuildID; if (m.Channels.has_value()) { @@ -98,7 +98,7 @@ void to_json(nlohmann::json &j, const LazyLoadRequestMessage &m) { } void to_json(nlohmann::json &j, const UpdateStatusMessage &m) { - j["op"] = GatewayOp::UpdateStatus; + j["op"] = GatewayOp::PresenceUpdate; j["d"] = nlohmann::json::object(); j["d"]["since"] = m.Since; j["d"]["activities"] = m.Activities; diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 8568222..fae592a 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -24,16 +24,35 @@ // most stuff below should just be objects that get processed and thrown away immediately enum class GatewayOp : int { - Event = 0, + Dispatch = 0, Heartbeat = 1, Identify = 2, - UpdateStatus = 3, + PresenceUpdate = 3, + VoiceStateUpdate = 4, + VoiceServerPing = 5, Resume = 6, Reconnect = 7, + RequestGuildMembers = 8, InvalidSession = 9, Hello = 10, HeartbeatAck = 11, - LazyLoadRequest = 14, + // 12 unused + CallConnect = 13, + GuildSubscriptions = 14, + LobbyConnect = 15, + LobbyDisconnect = 16, + LobbyVoiceStatesUpdate = 17, + StreamCreate = 18, + StreamDelete = 19, + StreamWatch = 20, + StreamPing = 21, + StreamSetPaused = 22, + // 23 unused + RequestGuildApplicationCommands = 24, + EmbeddedActivityLaunch = 25, + EmbeddedActivityClose = 26, + EmbeddedActivityUpdate = 27, + RequestForumUnreads = 28, }; enum class GatewayEvent : int { -- cgit v1.2.3 From 7f1d3df4a5d640ae3a885886139236e8f9c5555c Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 3 Mar 2022 23:45:30 -0500 Subject: start sending request guild members for unknown members --- src/abaddon.cpp | 19 ++++++++++++++++++- src/abaddon.hpp | 2 ++ src/discord/discord.cpp | 16 ++++++++++++++++ src/discord/discord.hpp | 14 ++++++++++++++ src/discord/objects.cpp | 13 +++++++++++++ src/discord/objects.hpp | 22 ++++++++++++++++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 51f8052..b287e17 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -325,6 +325,22 @@ void Abaddon::ShowGuildVerificationGateDialog(Snowflake guild_id) { } } +void Abaddon::CheckMessagesForMembers(const ChannelData &chan, const std::vector &msgs) { + if (!chan.GuildID.has_value()) return; + + // TODO sql query + std::set fetch; + std::set ids; + for (const auto& msg : msgs) + ids.insert(msg.Author.ID); + for (const auto id : ids) { + const auto member = m_discord.GetMember(id, *chan.GuildID); + if (!member.has_value()) + fetch.insert(id); + } + m_discord.RequestMembers(*chan.GuildID, fetch.begin(), fetch.end()); +} + void Abaddon::SetupUserMenu() { m_user_menu = Gtk::manage(new Gtk::Menu); m_user_menu_insert_mention = Gtk::manage(new Gtk::MenuItem("Insert Mention")); @@ -536,7 +552,8 @@ void Abaddon::ActionChannelOpened(Snowflake id) { if (m_channels_requested.find(id) == m_channels_requested.end()) { // dont fire requests we know will fail if (can_access) { - m_discord.FetchMessagesInChannel(id, [this, id](const std::vector &msgs) { + m_discord.FetchMessagesInChannel(id, [channel, this, id](const std::vector &msgs) { + CheckMessagesForMembers(*channel, msgs); m_main_window->UpdateChatWindowContents(); m_channels_requested.insert(id); }); diff --git a/src/abaddon.hpp b/src/abaddon.hpp index d9d0bb0..311dcc5 100644 --- a/src/abaddon.hpp +++ b/src/abaddon.hpp @@ -93,6 +93,8 @@ public: protected: void ShowGuildVerificationGateDialog(Snowflake guild_id); + void CheckMessagesForMembers(const ChannelData &chan, const std::vector &msgs); + void SetupUserMenu(); void SaveState(); void LoadState(); diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 6ea0ea6..c11210d 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1464,6 +1464,9 @@ void DiscordClient::HandleGatewayMessage(std::string str) { case GatewayEvent::USER_GUILD_SETTINGS_UPDATE: { HandleGatewayUserGuildSettingsUpdate(m); } break; + case GatewayEvent::GUILD_MEMBERS_CHUNK: { + HandleGatewayGuildMembersChunk(m); + } break; } } break; default: @@ -2049,6 +2052,14 @@ void DiscordClient::HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &m } } +void DiscordClient::HandleGatewayGuildMembersChunk(const GatewayMessage &msg) { + GuildMembersChunkData data = msg.Data; + m_store.BeginTransaction(); + for (const auto &member : data.Members) + m_store.SetGuildMember(data.GuildID, member.User->ID, member); + m_store.EndTransaction(); +} + void DiscordClient::HandleGatewayReadySupplemental(const GatewayMessage &msg) { ReadySupplementalData data = msg.Data; for (const auto &p : data.MergedPresences.Friends) { @@ -2511,6 +2522,7 @@ void DiscordClient::LoadEventMap() { m_event_map["THREAD_MEMBER_LIST_UPDATE"] = GatewayEvent::THREAD_MEMBER_LIST_UPDATE; m_event_map["MESSAGE_ACK"] = GatewayEvent::MESSAGE_ACK; m_event_map["USER_GUILD_SETTINGS_UPDATE"] = GatewayEvent::USER_GUILD_SETTINGS_UPDATE; + m_event_map["GUILD_MEMBERS_CHUNK"] = GatewayEvent::GUILD_MEMBERS_CHUNK; } DiscordClient::type_signal_gateway_ready DiscordClient::signal_gateway_ready() { @@ -2677,6 +2689,10 @@ DiscordClient::type_signal_message_ack DiscordClient::signal_message_ack() { return m_signal_message_ack; } +DiscordClient::type_signal_guild_members_chunk DiscordClient::signal_guild_members_chunk() { + return m_signal_guild_members_chunk; +} + DiscordClient::type_signal_added_to_thread DiscordClient::signal_added_to_thread() { return m_signal_added_to_thread; } diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 4a7593d..63f8bd5 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -152,6 +152,16 @@ public: bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const; + // send op 8 to get member data for unknown members + template + void RequestMembers(Snowflake guild_id, Iter begin, Iter end) { + RequestGuildMembersMessage obj; + obj.GuildID = guild_id; + obj.Presences = false; + obj.UserIDs = { begin, end }; + m_websocket.Send(obj); + } + // real client doesn't seem to use the single role endpoints so neither do we template auto SetMemberRoles(Snowflake guild_id, Snowflake user_id, Iter begin, Iter end, sigc::slot callback) { @@ -262,6 +272,7 @@ private: void HandleGatewayThreadMemberListUpdate(const GatewayMessage &msg); void HandleGatewayMessageAck(const GatewayMessage &msg); void HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &msg); + void HandleGatewayGuildMembersChunk(const GatewayMessage &msg); void HandleGatewayReadySupplemental(const GatewayMessage &msg); void HandleGatewayReconnect(const GatewayMessage &msg); void HandleGatewayInvalidSession(const GatewayMessage &msg); @@ -372,6 +383,7 @@ public: typedef sigc::signal type_signal_thread_update; typedef sigc::signal type_signal_thread_member_list_update; typedef sigc::signal type_signal_message_ack; + typedef sigc::signal type_signal_guild_members_chunk; // not discord dispatch events typedef sigc::signal type_signal_added_to_thread; @@ -427,6 +439,7 @@ public: type_signal_thread_update signal_thread_update(); type_signal_thread_member_list_update signal_thread_member_list_update(); type_signal_message_ack signal_message_ack(); + type_signal_guild_members_chunk signal_guild_members_chunk(); type_signal_added_to_thread signal_added_to_thread(); type_signal_removed_from_thread signal_removed_from_thread(); @@ -479,6 +492,7 @@ protected: type_signal_thread_update m_signal_thread_update; type_signal_thread_member_list_update m_signal_thread_member_list_update; type_signal_message_ack m_signal_message_ack; + type_signal_guild_members_chunk m_signal_guild_members_chunk; type_signal_removed_from_thread m_signal_removed_from_thread; type_signal_added_to_thread m_signal_added_to_thread; diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 0ee96dc..3c9f770 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -119,6 +119,14 @@ void to_json(nlohmann::json &j, const UpdateStatusMessage &m) { } } +void to_json(nlohmann::json &j, const RequestGuildMembersMessage &m) { + j["op"] = GatewayOp::RequestGuildMembers; + j["d"] = nlohmann::json::object(); + j["d"]["guild_id"] = m.GuildID; + j["d"]["presences"] = m.Presences; + j["d"]["user_ids"] = m.UserIDs; +} + void from_json(const nlohmann::json &j, ReadStateEntry &m) { JS_ON("mention_count", m.MentionCount); JS_ON("last_message_id", m.LastMessageID); @@ -626,3 +634,8 @@ void to_json(nlohmann::json &j, const AckBulkData &m) { void from_json(const nlohmann::json &j, UserGuildSettingsUpdateData &m) { m.Settings = j; } + +void from_json(const nlohmann::json &j, GuildMembersChunkData &m) { + JS_D("members", m.Members); + JS_D("guild_id", m.GuildID); +} diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index fae592a..27542cc 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -99,6 +99,7 @@ enum class GatewayEvent : int { THREAD_MEMBER_LIST_UPDATE, MESSAGE_ACK, USER_GUILD_SETTINGS_UPDATE, + GUILD_MEMBERS_CHUNK, }; enum class GatewayCloseCode : uint16_t { @@ -245,6 +246,14 @@ struct UpdateStatusMessage { friend void to_json(nlohmann::json &j, const UpdateStatusMessage &m); }; +struct RequestGuildMembersMessage { + Snowflake GuildID; + bool Presences; + std::vector UserIDs; + + friend void to_json(nlohmann::json &j, const RequestGuildMembersMessage &m); +}; + struct ReadStateEntry { int MentionCount; Snowflake LastMessageID; @@ -841,3 +850,16 @@ struct UserGuildSettingsUpdateData { friend void from_json(const nlohmann::json &j, UserGuildSettingsUpdateData &m); }; + +struct GuildMembersChunkData { + /* + not needed so not deserialized + int ChunkCount; + int ChunkIndex; + std::vector NotFound; + */ + Snowflake GuildID; + std::vector Members; + + friend void from_json(const nlohmann::json &j, GuildMembersChunkData &m); +}; -- cgit v1.2.3 From 3583a5d2516f9b71d389ccb95224b21a3dae20a2 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 3 Mar 2022 23:57:48 -0500 Subject: dont request guild members if there are no user ids --- src/discord/discord.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/discord') diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 63f8bd5..dfe82cd 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -155,6 +155,8 @@ public: // send op 8 to get member data for unknown members template void RequestMembers(Snowflake guild_id, Iter begin, Iter end) { + if (std::distance(begin, end) == 0) return; + RequestGuildMembersMessage obj; obj.GuildID = guild_id; obj.Presences = false; -- cgit v1.2.3 From af60bceada7e55011f6d5ed2f13fef354ced45ef Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 4 Mar 2022 23:03:09 -0500 Subject: optimize sql for getting unknown member ids --- src/abaddon.cpp | 18 ++++++++---------- src/discord/discord.hpp | 11 +++++++++++ src/discord/store.cpp | 25 +++++++++++++++++++++++++ src/discord/store.hpp | 3 +++ 4 files changed, 47 insertions(+), 10 deletions(-) (limited to 'src/discord') diff --git a/src/abaddon.cpp b/src/abaddon.cpp index c9ff24e..55c6ee9 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -328,16 +328,14 @@ void Abaddon::ShowGuildVerificationGateDialog(Snowflake guild_id) { void Abaddon::CheckMessagesForMembers(const ChannelData &chan, const std::vector &msgs) { if (!chan.GuildID.has_value()) return; - // TODO sql query - std::set fetch; - std::set ids; - for (const auto &msg : msgs) - ids.insert(msg.Author.ID); - for (const auto id : ids) { - const auto member = m_discord.GetMember(id, *chan.GuildID); - if (!member.has_value()) - fetch.insert(id); - } + std::vector unknown; + std::transform(msgs.begin(), msgs.end(), + std::back_inserter(unknown), + [](const Message &msg) -> Snowflake { + return msg.Author.ID; + }); + + const auto fetch = m_discord.FilterUnknownMembersFrom(*chan.GuildID, unknown.begin(), unknown.end()); m_discord.RequestMembers(*chan.GuildID, fetch.begin(), fetch.end()); } diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index dfe82cd..6add18f 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -84,6 +84,17 @@ public: void GetArchivedPrivateThreads(Snowflake channel_id, sigc::slot callback); std::vector GetChildChannelIDs(Snowflake parent_id) const; + // get ids of given list of members for who we do not have the member data + template + std::unordered_set FilterUnknownMembersFrom(Snowflake guild_id, Iter begin, Iter end) { + std::unordered_set ret; + const auto known = m_store.GetMembersInGuild(guild_id); + for (auto iter = begin; iter != end; iter++) + if (known.find(*iter) == known.end()) + ret.insert(*iter); + return ret; + } + bool IsThreadJoined(Snowflake thread_id) const; bool HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const; diff --git a/src/discord/store.cpp b/src/discord/store.cpp index d96bb1f..8eb3613 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -576,6 +576,23 @@ std::vector Store::GetChannelIDsWithParentID(Snowflake channel_id) co return ret; } +std::unordered_set Store::GetMembersInGuild(Snowflake guild_id) const { + auto &s = m_stmt_get_guild_member_ids; + + s->Bind(1, guild_id); + + std::unordered_set ret; + while (s->FetchOne()) { + Snowflake x; + s->Get(0, x); + ret.insert(x); + } + + s->Reset(); + + return ret; +} + void Store::AddReaction(const MessageReactionAddObject &data, bool byself) { auto &s = m_stmt_add_reaction; @@ -2134,6 +2151,14 @@ bool Store::CreateStatements() { return false; } + m_stmt_get_guild_member_ids = std::make_unique(m_db, R"( + SELECT user_id FROM members WHERE guild_id = ? + )"); + if (!m_stmt_get_guild_member_ids->OK()) { + fprintf(stderr, "failed to prepare get guild member ids statement: %s\n", m_db.ErrStr()); + return false; + } + return true; } diff --git a/src/discord/store.hpp b/src/discord/store.hpp index 4320807..a1e5f81 100644 --- a/src/discord/store.hpp +++ b/src/discord/store.hpp @@ -44,6 +44,8 @@ public: std::vector GetPinnedMessages(Snowflake channel_id) const; std::vector GetActiveThreads(Snowflake channel_id) const; // public std::vector GetChannelIDsWithParentID(Snowflake channel_id) const; + std::unordered_set GetMembersInGuild(Snowflake guild_id) const; + // ^ not the same as GetUsersInGuild since users in a guild may include users who do not have retrieved member data void AddReaction(const MessageReactionAddObject &data, bool byself); void RemoveReaction(const MessageReactionRemoveObject &data, bool byself); @@ -302,5 +304,6 @@ private: STMT(sub_reaction); STMT(get_reactions); STMT(get_chan_ids_parent); + STMT(get_guild_member_ids); #undef STMT }; -- cgit v1.2.3 From 271d21c7bdf2682a6b26b8565fa1449051bc57c7 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 5 Mar 2022 01:01:19 -0500 Subject: fix UB --- src/discord/user.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/discord') diff --git a/src/discord/user.cpp b/src/discord/user.cpp index 6df53aa..c2e6069 100644 --- a/src/discord/user.cpp +++ b/src/discord/user.cpp @@ -17,7 +17,7 @@ bool UserData::HasAnimatedAvatar(Snowflake guild_id) const { const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id); if (member.has_value() && member->Avatar.has_value() && member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_') return true; - else if (!member->Avatar.has_value()) + else if (member.has_value() && !member->Avatar.has_value()) return HasAnimatedAvatar(); return false; } -- cgit v1.2.3