From d21b51c4dd850465d477efc306b38685b537dc94 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 21 Apr 2021 18:18:26 -0400 Subject: [PATCH 1/6] bump to api v9 now that it's live --- discord/discord.cpp | 3 +- discord/discord.hpp | 4 +- discord/message.hpp | 2 +- discord/objects.cpp | 1 + discord/objects.hpp | 1 + discord/permissions.hpp | 75 +++++++++++++++-------------- windows/guildsettings/rolespane.cpp | 2 +- 7 files changed, 47 insertions(+), 41 deletions(-) diff --git a/discord/discord.cpp b/discord/discord.cpp index 1dc8fe9..93e5ff4 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -1667,6 +1667,7 @@ void DiscordClient::SendIdentify() { msg.Properties.OS = "Windows"; msg.Properties.Browser = ""; msg.Properties.Device = "Chrome"; + msg.Properties.SystemLocale = "en-US"; msg.Properties.BrowserUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"; msg.Properties.BrowserVersion = "67.0.3396.87"; msg.Properties.OSVersion = "10"; @@ -1675,7 +1676,7 @@ void DiscordClient::SendIdentify() { msg.Properties.ReferrerCurrent = ""; msg.Properties.ReferringDomainCurrent = ""; msg.Properties.ReleaseChannel = "stable"; - msg.Properties.ClientBuildNumber = 73785; + msg.Properties.ClientBuildNumber = 82826; msg.Properties.ClientEventSource = ""; msg.Presence.Status = "online"; msg.Presence.Since = 0; diff --git a/discord/discord.hpp b/discord/discord.hpp index 0234014..1d732b7 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -50,8 +50,8 @@ class DiscordClient { friend class Abaddon; public: - static const constexpr char *DiscordGateway = "wss://gateway.discord.gg/?v=8&encoding=json&compress=zlib-stream"; - static const constexpr char *DiscordAPI = "https://discord.com/api/v8"; + static const constexpr char *DiscordGateway = "wss://gateway.discord.gg/?v=9&encoding=json&compress=zlib-stream"; + static const constexpr char *DiscordAPI = "https://discord.com/api/v9"; public: DiscordClient(bool mem_store = false); diff --git a/discord/message.hpp b/discord/message.hpp index ca60f08..ee6153e 100644 --- a/discord/message.hpp +++ b/discord/message.hpp @@ -40,7 +40,7 @@ enum class MessageFlags { SUPPRESS_EMBEDS = 1 << 2, // do not include any embeds when serializing this message SOURCE_MESSAGE_DELETE = 1 << 3, // the source message for this crosspost has been deleted (via Channel Following) URGENT = 1 << 4, // this message came from the urgent message system - HAS_THREAD = 1 << 5, // this message was used to start a thread (?) + HAS_THREAD = 1 << 5, // this message has an associated thread, with the same id as the message EPHEMERAL = 1 << 6, // this message is only visible to the user who invoked the Interaction LOADING = 1 << 7, // this message is an Interaction Response and the bot is "thinking" }; diff --git a/discord/objects.cpp b/discord/objects.cpp index 131afda..d2a3f4c 100644 --- a/discord/objects.cpp +++ b/discord/objects.cpp @@ -147,6 +147,7 @@ void to_json(nlohmann::json &j, const IdentifyProperties &m) { j["os"] = m.OS; j["browser"] = m.Browser; j["device"] = m.Device; + j["system_locale"] = m.SystemLocale; j["browser_user_agent"] = m.BrowserUserAgent; j["browser_version"] = m.BrowserVersion; j["os_version"] = m.OSVersion; diff --git a/discord/objects.hpp b/discord/objects.hpp index 80bad17..5335dc0 100644 --- a/discord/objects.hpp +++ b/discord/objects.hpp @@ -265,6 +265,7 @@ struct IdentifyProperties { std::string OS; std::string Browser; std::string Device; + std::string SystemLocale; std::string BrowserUserAgent; std::string BrowserVersion; std::string OSVersion; diff --git a/discord/permissions.hpp b/discord/permissions.hpp index 6c5a882..d9cff11 100644 --- a/discord/permissions.hpp +++ b/discord/permissions.hpp @@ -7,40 +7,43 @@ constexpr static uint64_t PERMISSION_MAX_BIT = 31; enum class Permission : uint64_t { NONE = 0, - CREATE_INSTANT_INVITE = (1ULL << 0), - KICK_MEMBERS = (1ULL << 1), - BAN_MEMBERS = (1ULL << 2), - ADMINISTRATOR = (1ULL << 3), - MANAGE_CHANNELS = (1ULL << 4), - MANAGE_GUILD = (1ULL << 5), - ADD_REACTIONS = (1ULL << 6), - VIEW_AUDIT_LOG = (1ULL << 7), - PRIORITY_SPEAKER = (1ULL << 8), - STREAM = (1ULL << 9), - VIEW_CHANNEL = (1ULL << 10), - SEND_MESSAGES = (1ULL << 11), - SEND_TTS_MESSAGES = (1ULL << 12), - MANAGE_MESSAGES = (1ULL << 13), - EMBED_LINKS = (1ULL << 14), - ATTACH_FILES = (1ULL << 15), - READ_MESSAGE_HISTORY = (1ULL << 16), - MENTION_EVERYONE = (1ULL << 17), - USE_EXTERNAL_EMOJIS = (1ULL << 18), - VIEW_GUILD_INSIGHTS = (1ULL << 19), - CONNECT = (1ULL << 20), - SPEAK = (1ULL << 21), - MUTE_MEMBERS = (1ULL << 22), - DEAFEN_MEMBERS = (1ULL << 23), - MOVE_MEMBERS = (1ULL << 24), - USE_VAD = (1ULL << 25), // voice activity detection - CHANGE_NICKNAME = (1ULL << 26), - MANAGE_NICKNAMES = (1ULL << 27), - MANAGE_ROLES = (1ULL << 28), - MANAGE_WEBHOOKS = (1ULL << 29), - MANAGE_EMOJIS = (1ULL << 30), - USE_APPLICATION_COMMANDS = (1ULL << 31), + CREATE_INSTANT_INVITE = (1ULL << 0), // Allows creation of instant invites + KICK_MEMBERS = (1ULL << 1), // Allows kicking members + BAN_MEMBERS = (1ULL << 2), // Allows banning members + ADMINISTRATOR = (1ULL << 3), // Allows all permissions and bypasses channel permission overwrites + MANAGE_CHANNELS = (1ULL << 4), // Allows management and editing of channels + MANAGE_GUILD = (1ULL << 5), // Allows management and editing of the guild + ADD_REACTIONS = (1ULL << 6), // Allows for the addition of reactions to messages + VIEW_AUDIT_LOG = (1ULL << 7), // Allows for viewing of audit logs + PRIORITY_SPEAKER = (1ULL << 8), // Allows for using priority speaker in a voice channel + STREAM = (1ULL << 9), // Allows the user to go live + VIEW_CHANNEL = (1ULL << 10), // Allows guild members to view a channel, which includes reading messages in text channels + SEND_MESSAGES = (1ULL << 11), // Allows for sending messages in a channel + SEND_TTS_MESSAGES = (1ULL << 12), // Allows for sending of /tts messages + MANAGE_MESSAGES = (1ULL << 13), // Allows for deletion of other users messages + EMBED_LINKS = (1ULL << 14), // Links sent by users with this permission will be auto-embedded + ATTACH_FILES = (1ULL << 15), // Allows for uploading images and files + READ_MESSAGE_HISTORY = (1ULL << 16), // Allows for reading of message history + MENTION_EVERYONE = (1ULL << 17), // Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel + USE_EXTERNAL_EMOJIS = (1ULL << 18), // Allows the usage of custom emojis from other servers + VIEW_GUILD_INSIGHTS = (1ULL << 19), // Allows for viewing guild insights + CONNECT = (1ULL << 20), // Allows for joining of a voice channel + SPEAK = (1ULL << 21), // Allows for speaking in a voice channel + MUTE_MEMBERS = (1ULL << 22), // Allows for muting members in a voice channel + DEAFEN_MEMBERS = (1ULL << 23), // Allows for deafening of members in a voice channel + MOVE_MEMBERS = (1ULL << 24), // Allows for moving of members between voice channels + USE_VAD = (1ULL << 25), // Allows for using voice-activity-detection in a voice channel + CHANGE_NICKNAME = (1ULL << 26), // Allows for modification of own nickname + MANAGE_NICKNAMES = (1ULL << 27), // Allows for modification of other users nicknames + MANAGE_ROLES = (1ULL << 28), // Allows management and editing of roles + MANAGE_WEBHOOKS = (1ULL << 29), // Allows management and editing of webhooks + MANAGE_EMOJIS = (1ULL << 30), // Allows management and editing of emojis + USE_SLASH_COMMANDS = (1ULL << 31), // Allows members to use slash commands in text channels + REQUEST_TO_SPEAK = (1ULL << 32), // Allows for requesting to speak in stage channels + USE_THREADS = (1ULL << 33), // Allows for creating and participating in threads + USE_PRIVATE_THREADS = (1ULL << 34), // Allows for creating and participating in private threads - ALL = 0xFFFFFFFF, + ALL = 0x7FFFFFFFFULL, }; template<> struct Bitwise { @@ -127,14 +130,14 @@ constexpr const char *GetPermissionString(Permission perm) { return "Manage Webhooks"; case Permission::MANAGE_EMOJIS: return "Manage Emojis"; - case Permission::USE_APPLICATION_COMMANDS: + case Permission::USE_SLASH_COMMANDS: return "Use Slash Commands"; default: return "Unknown Permission"; } } -constexpr const char* GetPermissionDescription(Permission perm) { +constexpr const char *GetPermissionDescription(Permission perm) { switch (perm) { case Permission::NONE: return ""; @@ -200,7 +203,7 @@ constexpr const char* GetPermissionDescription(Permission perm) { return "Allows members to create, edit, or delete webhooks, which can post messages from other apps or sites into this server."; case Permission::MANAGE_EMOJIS: return "Allows members to add or remove custom emojis in this server."; - case Permission::USE_APPLICATION_COMMANDS: + case Permission::USE_SLASH_COMMANDS: return "Allows members to use slash commands in text channels."; default: return ""; diff --git a/windows/guildsettings/rolespane.cpp b/windows/guildsettings/rolespane.cpp index 007be23..635c2e2 100644 --- a/windows/guildsettings/rolespane.cpp +++ b/windows/guildsettings/rolespane.cpp @@ -283,7 +283,7 @@ GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id) Permission::MANAGE_MESSAGES, Permission::READ_MESSAGE_HISTORY, Permission::SEND_TTS_MESSAGES, - Permission::USE_APPLICATION_COMMANDS }); + Permission::USE_SLASH_COMMANDS }); add_perms("Voice Channels", RIGHT, { Permission::CONNECT, From 687a336bc9f91e1c20dd2e6205b22bcaf841743a Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 24 Apr 2021 03:29:06 -0400 Subject: [PATCH 2/6] handle CHANNEL_NAME_CHANGE messages --- components/chatmessage.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 8ab3b72..b251a38 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -254,6 +254,10 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { else b->insert_markup(s, "" + adder->Username + " removed " + added.Username + ""); } break; + case MessageType::CHANNEL_NAME_CHANGE: { + const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); + b->insert_markup(s, "" + author->GetEscapedBoldName() + " changed the name to " + Glib::Markup::escape_text(data->Content) + ""); + } break; default: break; } } From 71d314ebc3603949ba1de373ea4ea4e1fb4ffe3e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 24 Apr 2021 03:46:57 -0400 Subject: [PATCH 3/6] handle CHANNEL_ICON_CHANGE message --- components/chatmessage.cpp | 4 ++++ discord/message.hpp | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index b251a38..a6bdef5 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -258,6 +258,10 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); b->insert_markup(s, "" + author->GetEscapedBoldName() + " changed the name to " + Glib::Markup::escape_text(data->Content) + ""); } break; + case MessageType::CHANNEL_ICON_CHANGE: { + const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); + b->insert_markup(s, "" + author->GetEscapedBoldName() + " changed the channel icon"); + } break; default: break; } } diff --git a/discord/message.hpp b/discord/message.hpp index ee6153e..c8aa0c1 100644 --- a/discord/message.hpp +++ b/discord/message.hpp @@ -14,11 +14,11 @@ enum class MessageType { RECIPIENT_ADD = 1, // yep RECIPIENT_REMOVE = 2, // yep CALL = 3, // nope - CHANNEL_NAME_CHANGE = 4, // nope - CHANNEL_ICON_CHANGE = 5, // nope + CHANNEL_NAME_CHANGE = 4, // yep + CHANNEL_ICON_CHANGE = 5, // yep CHANNEL_PINNED_MESSAGE = 6, // yep GUILD_MEMBER_JOIN = 7, // yep - USER_PREMIUM_GUILD_SUBSCRIPTION = 8, // nope + USER_PREMIUM_GUILD_SUBSCRIPTION = 8, // yep USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9, // nope USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10, // nope USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, // nope From a346a0493fa9ecf7bdf82d84186f215a0ff46727 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 24 Apr 2021 03:59:21 -0400 Subject: [PATCH 4/6] handle USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_ messages --- components/chatmessage.cpp | 8 ++++++++ discord/message.hpp | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index a6bdef5..a5c2665 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -262,6 +262,14 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); b->insert_markup(s, "" + author->GetEscapedBoldName() + " changed the channel icon"); } break; + case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1: + case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2: + case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3: { + const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); + const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(*data->GuildID); + b->insert_markup(s, "" + author->GetEscapedBoldName() + " just boosted the server " + Glib::Markup::escape_text(data->Content) + " times! " + + Glib::Markup::escape_text(guild->Name) + " has achieved Level " + std::to_string(static_cast(data->Type) - 8) + "!"); // oo cheeky me !!! + } break; default: break; } } diff --git a/discord/message.hpp b/discord/message.hpp index c8aa0c1..8316bbd 100644 --- a/discord/message.hpp +++ b/discord/message.hpp @@ -19,9 +19,9 @@ enum class MessageType { CHANNEL_PINNED_MESSAGE = 6, // yep GUILD_MEMBER_JOIN = 7, // yep USER_PREMIUM_GUILD_SUBSCRIPTION = 8, // yep - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9, // nope - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10, // nope - USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, // nope + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9, // yep + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10, // yep + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, // yep CHANNEL_FOLLOW_ADD = 12, // nope GUILD_DISCOVERY_DISQUALIFIED = 14, // nope GUILD_DISCOVERY_REQUALIFIED = 15, // nope From a120cbda2cf0a247d5189e12d93c0c4c40503910 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 24 Apr 2021 04:11:26 -0400 Subject: [PATCH 5/6] handle CHANNEL_FOLLOW_ADD messages --- components/chatmessage.cpp | 6 +++++- discord/message.hpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index a5c2665..4d38806 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -60,7 +60,7 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(Snowflake id) { container->m_main->add(*container->m_text_component); } - if (data->MessageReference.has_value() || data->Interaction.has_value()) { + if ((data->MessageReference.has_value() || data->Interaction.has_value()) && data->Type != MessageType::CHANNEL_FOLLOW_ADD) { auto *widget = container->CreateReplyComponent(*data); container->m_main->add(*widget); container->m_main->child_property_position(*widget) = 0; // eek @@ -270,6 +270,10 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { b->insert_markup(s, "" + author->GetEscapedBoldName() + " just boosted the server " + Glib::Markup::escape_text(data->Content) + " times! " + Glib::Markup::escape_text(guild->Name) + " has achieved Level " + std::to_string(static_cast(data->Type) - 8) + "!"); // oo cheeky me !!! } break; + case MessageType::CHANNEL_FOLLOW_ADD: { + const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); + b->insert_markup(s, "" + author->GetEscapedBoldName() + " has added " + Glib::Markup::escape_text(data->Content) + " to this channel. Its most important updates will show up here."); + } break; default: break; } } diff --git a/discord/message.hpp b/discord/message.hpp index 8316bbd..66d0afd 100644 --- a/discord/message.hpp +++ b/discord/message.hpp @@ -22,7 +22,7 @@ enum class MessageType { USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9, // yep USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10, // yep USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, // yep - CHANNEL_FOLLOW_ADD = 12, // nope + CHANNEL_FOLLOW_ADD = 12, // yep GUILD_DISCOVERY_DISQUALIFIED = 14, // nope GUILD_DISCOVERY_REQUALIFIED = 15, // nope GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = 16, // nope From 3deb2b10020529ac36cf7ab298e0be425887c88f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 24 Apr 2021 04:23:28 -0400 Subject: [PATCH 6/6] basic handling of CALL messages --- components/chatmessage.cpp | 3 +++ discord/message.hpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 4d38806..03398dd 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -274,6 +274,9 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); b->insert_markup(s, "" + author->GetEscapedBoldName() + " has added " + Glib::Markup::escape_text(data->Content) + " to this channel. Its most important updates will show up here."); } break; + case MessageType::CALL: { + b->insert_markup(s, "[started a call]"); + } break; default: break; } } diff --git a/discord/message.hpp b/discord/message.hpp index 66d0afd..baf147e 100644 --- a/discord/message.hpp +++ b/discord/message.hpp @@ -13,7 +13,7 @@ enum class MessageType { DEFAULT = 0, // yep RECIPIENT_ADD = 1, // yep RECIPIENT_REMOVE = 2, // yep - CALL = 3, // nope + CALL = 3, // yep (sorta) CHANNEL_NAME_CHANGE = 4, // yep CHANNEL_ICON_CHANGE = 5, // yep CHANNEL_PINNED_MESSAGE = 6, // yep