diff --git a/locale/Messages.resx b/locale/Messages.resx index ab821ac..31ed7b3 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -564,4 +564,10 @@ Boost count + + There are no messages matching your filter! + + + Cleared {0} messages from {1} + diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index f38032b..cb65749 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -564,4 +564,10 @@ Количество бустов + + Нет сообщений, которые подходят под твой фильтр! + + + Очищено {0} сообщений от {1} + diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index 52d6c7e..b5f6ad1 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -564,4 +564,10 @@ кол-во бустов + + алло а чё мне удалять-то + + + вырезано {0} забавных сообщений от {1} + diff --git a/src/Commands/ClearCommandGroup.cs b/src/Commands/ClearCommandGroup.cs index a6ac188..714c9de 100644 --- a/src/Commands/ClearCommandGroup.cs +++ b/src/Commands/ClearCommandGroup.cs @@ -45,9 +45,10 @@ public class ClearCommandGroup : CommandGroup } /// - /// A slash command that clears messages in the channel it was executed. + /// A slash command that clears messages in the channel it was executed, optionally filtering by message author. /// /// The amount of messages to clear. + /// The user whose messages will be cleared. /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that any messages /// were cleared and vice-versa. @@ -62,7 +63,8 @@ public class ClearCommandGroup : CommandGroup [UsedImplicitly] public async Task ExecuteClear( [Description("Number of messages to remove (2-100)")] [MinValue(2)] [MaxValue(100)] - int amount) + int amount, + IUser? author = null) { if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { @@ -92,11 +94,11 @@ public class ClearCommandGroup : CommandGroup var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await ClearMessagesAsync(executor, amount, data, channelId, messages, bot, CancellationToken); + return await ClearMessagesAsync(executor, author, data, channelId, messages, bot, CancellationToken); } private async Task ClearMessagesAsync( - IUser executor, int amount, GuildData data, Snowflake channelId, IReadOnlyList messages, IUser bot, + IUser executor, IUser? author, GuildData data, Snowflake channelId, IReadOnlyList messages, IUser bot, CancellationToken ct = default) { var idList = new List(messages.Count); @@ -104,12 +106,27 @@ public class ClearCommandGroup : CommandGroup for (var i = messages.Count - 1; i >= 1; i--) // '>= 1' to skip last message ('Octobot is thinking...') { var message = messages[i]; + if (author is not null && message.Author.ID != author.ID) + { + continue; + } + idList.Add(message.ID); builder.AppendLine(string.Format(Messages.MessageFrom, Mention.User(message.Author))); builder.Append(message.Content.InBlockCode()); } - var title = string.Format(Messages.MessagesCleared, amount.ToString()); + if (idList.Count == 0) + { + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.NoMessagesToClear, bot) + .WithColour(ColorsList.Red).Build(); + + return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); + } + + var title = author is not null + ? string.Format(Messages.MessagesClearedFiltered, idList.Count.ToString(), author.GetTag()) + : string.Format(Messages.MessagesCleared, idList.Count.ToString()); var description = builder.ToString(); var deleteResult = await _channelApi.BulkDeleteMessagesAsync( diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs index ebf7fec..4a771d0 100644 --- a/src/Messages.Designer.cs +++ b/src/Messages.Designer.cs @@ -980,5 +980,21 @@ namespace Octobot { return ResourceManager.GetString("GuildInfoBoostCount", resourceCulture); } } + + internal static string NoMessagesToClear + { + get + { + return ResourceManager.GetString("NoMessagesToClear", resourceCulture); + } + } + + internal static string MessagesClearedFiltered + { + get + { + return ResourceManager.GetString("MessagesClearedFiltered", resourceCulture); + } + } } }