mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 14:10:10 +00:00
support sending messages with @silent
prefix
This commit is contained in:
parent
ed1f54d1a7
commit
2da021b5ea
@ -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;
|
||||
|
||||
|
@ -17,6 +17,7 @@ struct ChatSubmitParams {
|
||||
std::string Filename;
|
||||
};
|
||||
|
||||
bool Silent = false;
|
||||
Snowflake ChannelID;
|
||||
Snowflake InReplyToID;
|
||||
Glib::ustring Message;
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user