diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-01-11 07:31:09 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-01-11 07:31:09 +0100 |
commit | 8dadf547033d71480fd7756809992c0f32549f59 (patch) | |
tree | a23631cc840047e3ad9e32dda9c043511af1a583 /ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs | |
parent | Try-create factory for RemoteHomeserver, more reliable RemoteHomeserver creation (diff) | |
download | LibMatrix-8dadf547033d71480fd7756809992c0f32549f59.tar.xz |
Cleanup, more message formatters, messagebuilder start
Diffstat (limited to '')
-rw-r--r-- | ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs b/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs index da77b05..6564e71 100644 --- a/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs +++ b/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs @@ -30,6 +30,7 @@ public class JoinSpaceMembersCommand(IServiceProvider services, HomeserverProvid public async Task Invoke(CommandContext ctx) { var botData = await ctx.Homeserver.GetAccountDataAsync<BotData>("gay.rory.moderation_bot_data"); logRoom = ctx.Homeserver.GetRoom(botData.LogRoom ?? botData.ControlRoom); + var currentRooms = (await ctx.Homeserver.GetJoinedRooms()).Select(x=>x.RoomId).ToList(); await logRoom.SendMessageEventAsync(MessageFormatter.FormatSuccess($"Joining space children of {ctx.Args[0]} with reason: {string.Join(' ', ctx.Args[1..])}")); var roomId = ctx.Args[0]; @@ -47,6 +48,7 @@ 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()) { + 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)); @@ -59,8 +61,8 @@ public class JoinSpaceMembersCommand(IServiceProvider services, HomeserverProvid private async Task<bool> JoinRoom(GenericRoom memberRoom, string reason, List<string> servers) { try { - await memberRoom.JoinAsync(servers.ToArray(), reason); - await logRoom.SendMessageEventAsync(MessageFormatter.FormatSuccess($"Joined room {memberRoom.RoomId}")); + var resp = await memberRoom.JoinAsync(servers.ToArray(), reason, checkIfAlreadyMember: false); + await logRoom.SendMessageEventAsync(MessageFormatter.FormatSuccess($"Joined room {memberRoom.RoomId} (resp={resp.RoomId})")); } catch (Exception e) { await logRoom.SendMessageEventAsync(MessageFormatter.FormatException($"Failed to join {memberRoom.RoomId}", e)); |