diff --git a/src/NadekoBot/Modules/Administration/Prune/PruneCommands.cs b/src/NadekoBot/Modules/Administration/Prune/PruneCommands.cs index cc549dab5..b193a6fb9 100644 --- a/src/NadekoBot/Modules/Administration/Prune/PruneCommands.cs +++ b/src/NadekoBot/Modules/Administration/Prune/PruneCommands.cs @@ -32,6 +32,25 @@ public partial class Administration } } + [Cmd] + [RequireContext(ContextType.DM)] + [NadekoOptions] + public async Task Prune() + { + var progressMsg = await Response().Pending(strs.prune_progress(0, 100)).SendAsync(); + var progress = GetProgressTracker(progressMsg); + + var result = await _service.PruneWhere(ctx.Channel, + 100, + x => x.Author.Id == ctx.Client.CurrentUser.Id, + progress); + + ctx.Message.DeleteAfter(3); + + await SendResult(result); + await progressMsg.DeleteAsync(); + } + //deletes her own messages, no perm required [Cmd] [RequireContext(ContextType.Guild)] @@ -114,9 +133,9 @@ public partial class Administration await progressMsg.ModifyAsync(props => { props.Embed = CreateEmbed() - .WithPendingColor() - .WithDescription(GetText(strs.prune_progress(deleted, total))) - .Build(); + .WithPendingColor() + .WithDescription(GetText(strs.prune_progress(deleted, total))) + .Build(); }); } catch diff --git a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs index 4708e18bd..39857a219 100644 --- a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs +++ b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs @@ -18,7 +18,7 @@ public class PruneService : INService } public async Task PruneWhere( - ITextChannel channel, + IMessageChannel channel, int amount, Func predicate, IProgress<(int deleted, int total)> progress, @@ -30,13 +30,14 @@ public class PruneService : INService var originalAmount = amount; + var gid = (channel as ITextChannel)?.GuildId ?? channel.Id; using var cancelSource = new CancellationTokenSource(); - if (!_pruningGuilds.TryAdd(channel.GuildId, cancelSource)) + if (!_pruningGuilds.TryAdd(gid, cancelSource)) return PruneResult.AlreadyRunning; try { - if (!await _ps.LimitHitAsync(LimitedFeatureName.Prune, channel.Guild.OwnerId)) + if (channel is ITextChannel tc && !await _ps.LimitHitAsync(LimitedFeatureName.Prune, tc.Guild.OwnerId)) { return PruneResult.FeatureLimit; } @@ -74,9 +75,9 @@ public class PruneService : INService singleDeletable.Add(x); } - if (bulkDeletable.Count > 0) + if (channel is ITextChannel tc2 && bulkDeletable.Count > 0) { - await channel.DeleteMessagesAsync(bulkDeletable); + await tc2.DeleteMessagesAsync(bulkDeletable); amount -= msgs.Length; progress.Report((originalAmount - amount, originalAmount)); await Task.Delay(2000, cancelSource.Token); @@ -97,7 +98,7 @@ public class PruneService : INService } finally { - _pruningGuilds.TryRemove(channel.GuildId, out _); + _pruningGuilds.TryRemove(gid, out _); } return PruneResult.Success; diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 1996e2383..aaafe2b52 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -4,7 +4,7 @@ enable true en - 5.3.6 + 5.3.7 $(MSBuildProjectDirectory)