about summary refs log tree commit diff
path: root/ModerationBot/Commands
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-01 20:10:35 +0100
committerRory& <root@rory.gay>2025-11-01 20:10:35 +0100
commite0366831cf35b5d0f08a17fbde0b93cd977615a6 (patch)
treee504e0d1f3561f0cad98198c5d572c804a4aa9de /ModerationBot/Commands
parentdotnet10 (diff)
downloadModerationBot-master.tar.xz
Follow libmatrix changes HEAD master
Diffstat (limited to 'ModerationBot/Commands')
-rw-r--r--ModerationBot/Commands/BanMediaCommand.cs14
-rw-r--r--ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs2
-rw-r--r--ModerationBot/Commands/JoinSpaceMembersCommand.cs4
3 files changed, 6 insertions, 14 deletions
diff --git a/ModerationBot/Commands/BanMediaCommand.cs b/ModerationBot/Commands/BanMediaCommand.cs

index 07c9858..a41ad75 100644 --- a/ModerationBot/Commands/BanMediaCommand.cs +++ b/ModerationBot/Commands/BanMediaCommand.cs
@@ -64,7 +64,7 @@ public class BanMediaCommand(HomeserverResolverService hsResolver, PolicyEngine //hash file var mxcUri = (repliedMessage.TypedContent as RoomMessageEventContent).Url!; - var resolvedUri = await hsResolver.ResolveMediaUri(mxcUri.Split('/')[2], mxcUri); + var resolvedUri = await ctx.Homeserver.GetMediaUrlAsync(mxcUri); var hashAlgo = SHA3_256.Create(); var uriHash = hashAlgo.ComputeHash(mxcUri.AsBytes().ToArray()); byte[]? fileHash = null; @@ -74,17 +74,9 @@ public class BanMediaCommand(HomeserverResolverService hsResolver, PolicyEngine } catch (Exception ex) { await logRoom.SendMessageEventAsync( - MessageFormatter.FormatException($"Error calculating file hash for {mxcUri} via {mxcUri.Split('/')[2]}, retrying via {ctx.Homeserver.BaseUrl}...", + MessageFormatter.FormatException($"Error calculating file hash for {mxcUri}!", ex)); - try { - resolvedUri = await hsResolver.ResolveMediaUri(ctx.Homeserver.BaseUrl, mxcUri); - fileHash = await hashAlgo.ComputeHashAsync(await ctx.Homeserver.ClientHttpClient.GetStreamAsync(resolvedUri)); - } - catch (Exception ex2) { - await ctx.Room.SendMessageEventAsync(MessageFormatter.FormatException("Error calculating file hash", ex2)); - await logRoom.SendMessageEventAsync( - MessageFormatter.FormatException($"Error calculating file hash via {ctx.Homeserver.BaseUrl}!", ex2)); - } + return; } MediaPolicyFile policy; diff --git a/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs b/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs
index ac2036a..8c187d1 100644 --- a/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs +++ b/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs
@@ -39,7 +39,7 @@ public class DbgDumpAllStateTypesCommand(IServiceProvider services, HomeserverPr var joinedRooms = await ctx.Homeserver.GetJoinedRooms(); - var tasks = joinedRooms.Select(GetStateTypes).ToAsyncEnumerable(); + var tasks = joinedRooms.Select(GetStateTypes).ToAsyncResultEnumerable(); await foreach (var (room, (raw, html)) in tasks) { await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.text") { Body = $"States for {room.RoomId}:\n{raw}", diff --git a/ModerationBot/Commands/JoinSpaceMembersCommand.cs b/ModerationBot/Commands/JoinSpaceMembersCommand.cs
index 86ecf7e..c7b2c7d 100644 --- a/ModerationBot/Commands/JoinSpaceMembersCommand.cs +++ b/ModerationBot/Commands/JoinSpaceMembersCommand.cs
@@ -47,14 +47,14 @@ public class JoinSpaceMembersCommand(IServiceProvider services, HomeserverProvid var room = ctx.Homeserver.GetRoom(roomId); var tasks = new List<Task<bool>>(); - await foreach (var memberRoom in room.AsSpace.GetChildrenAsync()) { + await foreach (var memberRoom in room.AsSpace().GetChildrenAsync()) { if (currentRooms.Contains(memberRoom.RoomId)) continue; servers.Add(room.RoomId.Split(':', 2)[1]); servers = servers.Distinct().ToList(); tasks.Add(JoinRoom(memberRoom, string.Join(' ', ctx.Args[1..]), servers)); } - await foreach (var b in tasks.ToAsyncEnumerable()) { + await foreach (var b in tasks.ToAsyncResultEnumerable()) { await Task.Delay(50); } }