diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-06-24 16:48:44 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-06-24 16:48:44 -0400 |
commit | 2da021b5ea4b89d744e76c8b13180504916adc32 (patch) | |
tree | da5dfaa462f46f94338d13b5e4c02e3bf9cb441b /src | |
parent | ed1f54d1a7e8dea300e54c81951498b0f383dd52 (diff) | |
download | abaddon-portaudio-2da021b5ea4b89d744e76c8b13180504916adc32.tar.gz abaddon-portaudio-2da021b5ea4b89d744e76c8b13180504916adc32.zip |
support sending messages with `@silent` prefix
Diffstat (limited to 'src')
-rw-r--r-- | src/abaddon.cpp | 8 | ||||
-rw-r--r-- | src/discord/chatsubmitparams.hpp | 1 | ||||
-rw-r--r-- | src/discord/discord.cpp | 19 | ||||
-rw-r--r-- | src/discord/message.hpp | 26 | ||||
-rw-r--r-- | src/discord/objects.cpp | 1 | ||||
-rw-r--r-- | src/discord/objects.hpp | 1 |
6 files changed, 43 insertions, 13 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 2fe2941..ab2223e 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -920,8 +920,14 @@ void Abaddon::ActionChatLoadHistory(Snowflake id) { } void Abaddon::ActionChatInputSubmit(ChatSubmitParams data) { - if (data.Message.substr(0, 7) == "/shrug " || data.Message == "/shrug") + if (data.Message.substr(0, 7) == "/shrug " || data.Message == "/shrug") { data.Message = data.Message.substr(6) + "\xC2\xAF\x5C\x5F\x28\xE3\x83\x84\x29\x5F\x2F\xC2\xAF"; // this is important + } + + if (data.Message.substr(0, 8) == "@silent " || (data.Message.substr(0, 7) == "@silent" && !data.Attachments.empty())) { + data.Silent = true; + data.Message = data.Message.substr(7); + } if (!m_discord.HasChannelPermission(m_discord.GetUserData().ID, data.ChannelID, Permission::VIEW_CHANNEL)) return; diff --git a/src/discord/chatsubmitparams.hpp b/src/discord/chatsubmitparams.hpp index 6199634..24c6f50 100644 --- a/src/discord/chatsubmitparams.hpp +++ b/src/discord/chatsubmitparams.hpp @@ -17,6 +17,7 @@ struct ChatSubmitParams { std::string Filename; }; + bool Silent = false; Snowflake ChannelID; Snowflake InReplyToID; Glib::ustring Message; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index e0a26e8..817aca8 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -461,8 +461,13 @@ void DiscordClient::SendChatMessageNoAttachments(const ChatSubmitParams ¶ms, CreateMessageObject obj; obj.Content = params.Message; obj.Nonce = nonce; - if (params.InReplyToID.IsValid()) + if (params.Silent) { + obj.Flags |= MessageFlags::SUPPRESS_NOTIFICATIONS; + } + + if (params.InReplyToID.IsValid()) { obj.MessageReference.emplace().MessageID = params.InReplyToID; + } m_http.MakePOST("/channels/" + std::to_string(params.ChannelID) + "/messages", nlohmann::json(obj).dump(), @@ -494,8 +499,13 @@ void DiscordClient::SendChatMessageAttachments(const ChatSubmitParams ¶ms, c CreateMessageObject obj; obj.Content = params.Message; obj.Nonce = nonce; - if (params.InReplyToID.IsValid()) + if (params.Silent) { + obj.Flags |= MessageFlags::SUPPRESS_NOTIFICATIONS; + } + + if (params.InReplyToID.IsValid()) { obj.MessageReference.emplace().MessageID = params.InReplyToID; + } auto req = m_http.CreateRequest(http::REQUEST_POST, "/channels/" + std::to_string(params.ChannelID) + "/messages"); m_progress_cb_timer.start(); @@ -545,10 +555,11 @@ void DiscordClient::SendChatMessageAttachments(const ChatSubmitParams ¶ms, c } void DiscordClient::SendChatMessage(const ChatSubmitParams ¶ms, const sigc::slot<void(DiscordError)> &callback) { - if (params.Attachments.empty()) + if (params.Attachments.empty()) { SendChatMessageNoAttachments(params, callback); - else + } else { SendChatMessageAttachments(params, callback); + } } void DiscordClient::DeleteMessage(Snowflake channel_id, Snowflake id) { diff --git a/src/discord/message.hpp b/src/discord/message.hpp index df2cb38..5028104 100644 --- a/src/discord/message.hpp +++ b/src/discord/message.hpp @@ -8,6 +8,7 @@ #include "emoji.hpp" #include "member.hpp" #include "interactions.hpp" +#include "misc/bitwise.hpp" enum class MessageType { DEFAULT = 0, // yep @@ -35,14 +36,23 @@ enum class MessageType { enum class MessageFlags { NONE = 0, - CROSSPOSTED = 1 << 0, // this message has been published to subscribed channels (via Channel Following) - IS_CROSSPOST = 1 << 1, // this message originated from a message in another channel (via Channel Following) - 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 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" + CROSSPOSTED = 1 << 0, // this message has been published to subscribed channels (via Channel Following) + IS_CROSSPOST = 1 << 1, // this message originated from a message in another channel (via Channel Following) + 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 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" + FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8, // this message failed to mention some roles and add their members to the thread + SHOULD_SHOW_LINK_NOT_DISCORD_WARNING = 1 << 10, // + SUPPRESS_NOTIFICATIONS = 1 << 12, // this message will not trigger push and desktop notifications + IS_VOICE_MESSAGE = 1 << 13, // this message is a voice message +}; + +template<> +struct Bitwise<MessageFlags> { + static const bool enable = true; }; struct EmbedFooterData { diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 645a693..50002f9 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -308,6 +308,7 @@ void to_json(nlohmann::json &j, const HeartbeatMessage &m) { void to_json(nlohmann::json &j, const CreateMessageObject &m) { j["content"] = m.Content; + j["flags"] = m.Flags; JS_IF("message_reference", m.MessageReference); JS_IF("nonce", m.Nonce); } diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index cad37f1..7f3d05f 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -428,6 +428,7 @@ struct HeartbeatMessage : GatewayMessage { struct CreateMessageObject { std::string Content; + MessageFlags Flags = MessageFlags::NONE; std::optional<MessageReferenceData> MessageReference; std::optional<std::string> Nonce; |