From f17866085e308bfdb340fef607fcb406d3e10ada Mon Sep 17 00:00:00 2001 From: Pusheon <59923820+Pusheon@users.noreply.github.com> Date: Tue, 2 Aug 2022 05:24:37 -0400 Subject: [PATCH] fix: Add DeleteMessagesAsync to IVoiceChannel (#2367) Also adds remaining rate-limit information to client log. --- .../Entities/Channels/IVoiceChannel.cs | 39 +++++++++++++++++++ src/Discord.Net.Rest/BaseDiscordClient.cs | 4 +- .../MockedEntities/MockedVoiceChannel.cs | 3 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs index d921a2474..d75a4e29c 100644 --- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace Discord @@ -25,6 +26,44 @@ namespace Discord /// int? UserLimit { get; } + /// + /// Bulk-deletes multiple messages. + /// + /// + /// The following example gets 250 messages from the channel and deletes them. + /// + /// var messages = await voiceChannel.GetMessagesAsync(250).FlattenAsync(); + /// await voiceChannel.DeleteMessagesAsync(messages); + /// + /// + /// + /// This method attempts to remove the messages specified in bulk. + /// + /// Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days! + /// + /// + /// The messages to be bulk-deleted. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous bulk-removal operation. + /// + Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null); + /// + /// Bulk-deletes multiple messages. + /// + /// + /// This method attempts to remove the messages specified in bulk. + /// + /// Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days! + /// + /// + /// The snowflake identifier of the messages to be bulk-deleted. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous bulk-removal operation. + /// + Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null); + /// /// Modifies this voice channel. /// diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 75f477c7c..af43e9f4e 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -57,7 +57,7 @@ namespace Discord.Rest if (info == null) await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); else - await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); + await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} Remaining: {info.Value.RetryAfter}s {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); }; ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); } @@ -257,6 +257,6 @@ namespace Discord.Rest /// Task IDiscordClient.StopAsync() => Task.Delay(0); - #endregion + #endregion } } diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs index fdbdeda5e..2ffc75a24 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs @@ -12,6 +12,9 @@ namespace Discord public int Bitrate => throw new NotImplementedException(); public int? UserLimit => throw new NotImplementedException(); + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => throw new NotImplementedException(); + + public Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) => throw new NotImplementedException(); public ulong? CategoryId => throw new NotImplementedException();