changed: You can now run .prune in dms to delete 100 of bot's messages

docs: Upped version to 5.3.7
docs: Updated commandlist
This commit is contained in:
Kwoth
2025-01-21 01:21:57 +00:00
parent eaab60898f
commit 86f9d901fe
3 changed files with 30 additions and 10 deletions

View File

@@ -32,6 +32,25 @@ public partial class Administration
} }
} }
[Cmd]
[RequireContext(ContextType.DM)]
[NadekoOptions<PruneOptions>]
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 //deletes her own messages, no perm required
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
@@ -114,9 +133,9 @@ public partial class Administration
await progressMsg.ModifyAsync(props => await progressMsg.ModifyAsync(props =>
{ {
props.Embed = CreateEmbed() props.Embed = CreateEmbed()
.WithPendingColor() .WithPendingColor()
.WithDescription(GetText(strs.prune_progress(deleted, total))) .WithDescription(GetText(strs.prune_progress(deleted, total)))
.Build(); .Build();
}); });
} }
catch catch

View File

@@ -18,7 +18,7 @@ public class PruneService : INService
} }
public async Task<PruneResult> PruneWhere( public async Task<PruneResult> PruneWhere(
ITextChannel channel, IMessageChannel channel,
int amount, int amount,
Func<IMessage, bool> predicate, Func<IMessage, bool> predicate,
IProgress<(int deleted, int total)> progress, IProgress<(int deleted, int total)> progress,
@@ -30,13 +30,14 @@ public class PruneService : INService
var originalAmount = amount; var originalAmount = amount;
var gid = (channel as ITextChannel)?.GuildId ?? channel.Id;
using var cancelSource = new CancellationTokenSource(); using var cancelSource = new CancellationTokenSource();
if (!_pruningGuilds.TryAdd(channel.GuildId, cancelSource)) if (!_pruningGuilds.TryAdd(gid, cancelSource))
return PruneResult.AlreadyRunning; return PruneResult.AlreadyRunning;
try 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; return PruneResult.FeatureLimit;
} }
@@ -74,9 +75,9 @@ public class PruneService : INService
singleDeletable.Add(x); 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; amount -= msgs.Length;
progress.Report((originalAmount - amount, originalAmount)); progress.Report((originalAmount - amount, originalAmount));
await Task.Delay(2000, cancelSource.Token); await Task.Delay(2000, cancelSource.Token);
@@ -97,7 +98,7 @@ public class PruneService : INService
} }
finally finally
{ {
_pruningGuilds.TryRemove(channel.GuildId, out _); _pruningGuilds.TryRemove(gid, out _);
} }
return PruneResult.Success; return PruneResult.Success;

View File

@@ -4,7 +4,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Version>5.3.6</Version> <Version>5.3.7</Version>
<!-- Output/build --> <!-- Output/build -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory> <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>