1 files changed, 22 insertions, 7 deletions
diff --git a/MiniUtils/Commands/RedactCommand.cs b/MiniUtils/Commands/RedactCommand.cs
index cba06c9..e84191e 100644
--- a/MiniUtils/Commands/RedactCommand.cs
+++ b/MiniUtils/Commands/RedactCommand.cs
@@ -1,6 +1,6 @@
using System.Collections.Frozen;
using ArcaneLibs.Extensions;
-using LibMatrix.EventTypes.Spec;
+using LibMatrix;
using LibMatrix.EventTypes.Spec.State.RoomInfo;
using LibMatrix.Filters;
using LibMatrix.Helpers;
@@ -19,10 +19,6 @@ public class RedactCommand(IgnoreListManager ignoreListManager) : ICommand {
public string Description => "Redact all user's events";
public bool Unlisted => false;
- private const string ThumbsUp = "\ud83d\udc4d\ufe0e";
- private const string Recycle = "\u267b\ufe0e";
- private const string Bullseye = "\u25ce\ufe0e";
- private const string RightArrowWithTail = "\u21a3\ufe0e";
public async Task Invoke(CommandContext ctx) {
if (ctx.Args is ["banned"])
@@ -42,8 +38,7 @@ public class RedactCommand(IgnoreListManager ignoreListManager) : ICommand {
foreach (var chunk in resp.Chunk.Chunk(49)) {
foreach (var evt in chunk) {
if (!senders.Contains(evt.Sender!)) continue;
- if (evt is { StateKey: not null, Type: not RoomMemberEventContent.EventId }) continue;
- if (evt is { RawContent: null or { Count: 0 } }) continue;
+ if(!await IsRedactionNeeded(ctx.Room, evt.EventId!, evt)) continue;
tasks.Add(RedactEvent(ctx.Room, evt.EventId!));
count++;
}
@@ -64,6 +59,26 @@ public class RedactCommand(IgnoreListManager ignoreListManager) : ICommand {
// await ctx.Room.SendReactionAsync(ctx.MessageEvent.EventId!, $"{Emojis.Recycle} {count}");
}
+ private async Task<bool> IsRedactionNeeded(GenericRoom roomId, string eventId, StateEventResponse? evt = null) {
+ evt ??= await roomId.GetEventAsync(eventId);
+
+ // Ignore room member state events
+ if (evt is { StateKey: not null, Type: not RoomMemberEventContent.EventId }) return false;
+
+ // Ignore redaction events
+ if (evt is { Type: RoomRedactionEventContent.EventId }) return false;
+
+ // Ignore empty events
+ if (evt is { RawContent: null or { Count: 0 } }) return false;
+
+ // Ignore redacted events
+ if (evt.Unsigned?.ContainsKey("redacted_because") == true) return false;
+
+
+
+ throw new NotImplementedException("Redaction check not implemented");
+ }
+
private async Task RedactEvent(GenericRoom room, string eventId) {
bool success;
do {
|