From ce31c40d38a83de386435c6cf5c3b0212c452523 Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Fri, 7 Jan 2022 14:29:29 -0500 Subject: [PATCH] Add SuppressEmbeds() method --- src/Discord.Net.Core/Entities/Messages/IMessage.cs | 9 ++++++++- src/Discord.Net.Rest/DiscordRestApiClient.cs | 13 +++++++++++++ src/Discord.Net.Rest/DiscordRestClient.cs | 4 +++- .../Entities/Messages/MessageHelper.cs | 9 +++++++++ .../Entities/Messages/RestMessage.cs | 3 +++ .../Entities/Messages/SocketMessage.cs | 3 +++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Messages/IMessage.cs b/src/Discord.Net.Core/Entities/Messages/IMessage.cs index f5f2ca007..eb9026f1d 100644 --- a/src/Discord.Net.Core/Entities/Messages/IMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IMessage.cs @@ -270,7 +270,14 @@ namespace Discord /// A task that represents the asynchronous removal operation. /// Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null); - + /// + /// Suppresses embeds for a specified message. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous operation to set the suppress embeds flags on a message. + /// + Task SuppressEmbeds(RequestOptions options = null); /// /// Gets all users that reacted to a message with a given emote. /// diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index c2f2fbc99..9290b564f 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -931,6 +931,19 @@ namespace Discord.API #endregion #region Stickers, Reactions, Crosspost, and Acks + public async Task SuppressEmbeds(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + Rest.ModifyMessageParams args = new Rest.ModifyMessageParams(); + args.Flags = MessageFlags.SuppressEmbeds; + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } public async Task GetStickerAsync(ulong id, RequestOptions options = null) { Preconditions.NotEqual(id, 0, nameof(id)); diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 93183161b..ac9e6e4f7 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -209,7 +209,9 @@ namespace Discord.Rest => MessageHelper.RemoveAllReactionsAsync(channelId, messageId, this, options); public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null) => MessageHelper.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote, this, options); -#endregion + public Task SuppressEmbeds(ulong channelId, ulong messageId, RequestOptions options = null) + => MessageHelper.SuppressEmbeds(channelId, messageId, this, options); + #endregion #region IDiscordClient /// diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 309500c96..8ced24055 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -160,6 +160,15 @@ namespace Discord.Rest await client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); } + public static async Task SuppressEmbeds(IMessage msg, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.SuppressEmbeds(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); + } + public static async Task SuppressEmbeds(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.SuppressEmbeds(channelId, messageId, options).ConfigureAwait(false); + } + public static IAsyncEnumerable> GetReactionUsersAsync(IMessage msg, IEmote emote, int? limit, BaseDiscordClient client, RequestOptions options) { diff --git a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs index c48a60aac..800a93d76 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs @@ -295,6 +295,9 @@ namespace Discord.Rest public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null) => MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options); /// + public Task SuppressEmbeds(RequestOptions options = null) + => MessageHelper.SuppressEmbeds(this, Discord, options); + /// public IAsyncEnumerable> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); } diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs index 4be9f4c5a..d6ec81531 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs @@ -343,6 +343,9 @@ namespace Discord.WebSocket public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null) => MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options); /// + public Task SuppressEmbeds(RequestOptions options = null) + => MessageHelper.SuppressEmbeds(this, Discord, options); + /// public IAsyncEnumerable> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); #endregion