Browse Source

Add SuppressEmbeds() method

pull/2021/head
Brendan McShane 3 years ago
parent
commit
ce31c40d38
6 changed files with 39 additions and 2 deletions
  1. +8
    -1
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  2. +13
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +3
    -1
      src/Discord.Net.Rest/DiscordRestClient.cs
  4. +9
    -0
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  5. +3
    -0
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  6. +3
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs

+ 8
- 1
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -270,7 +270,14 @@ namespace Discord
/// A task that represents the asynchronous removal operation.
/// </returns>
Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null);

/// <summary>
/// Suppresses embeds for a specified message.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation to set the suppress embeds flags on a message.
/// </returns>
Task SuppressEmbeds(RequestOptions options = null);
/// <summary>
/// Gets all users that reacted to a message with a given emote.
/// </summary>


+ 13
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -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<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
}
public async Task<Sticker> GetStickerAsync(ulong id, RequestOptions options = null)
{
Preconditions.NotEqual(id, 0, nameof(id));


+ 3
- 1
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -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
/// <inheritdoc />


+ 9
- 0
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -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<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
int? limit, BaseDiscordClient client, RequestOptions options)
{


+ 3
- 0
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -295,6 +295,9 @@ namespace Discord.Rest
public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options);
/// <inheritdoc />
public Task SuppressEmbeds(RequestOptions options = null)
=> MessageHelper.SuppressEmbeds(this, Discord, options);
/// <inheritdoc />
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
}


+ 3
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -343,6 +343,9 @@ namespace Discord.WebSocket
public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options);
/// <inheritdoc />
public Task SuppressEmbeds(RequestOptions options = null)
=> MessageHelper.SuppressEmbeds(this, Discord, options);
/// <inheritdoc />
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
#endregion


Loading…
Cancel
Save