about summary refs log tree commit diff
path: root/MatrixUtils.RoomUpgradeCLI/Commands/DevCommands/DevDeleteAllRoomsCommand.cs
blob: abae488172a53c33b388b3eea1ef51278a4c7437 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using LibMatrix.Homeservers;

namespace MatrixUtils.RoomUpgradeCLI.Commands;

public class DevDeleteAllRoomsCommand(ILogger<DevDeleteAllRoomsCommand> logger, IHost host, RuntimeContext ctx, AuthenticatedHomeserverGeneric hs) : IHostedService {
    public async Task StartAsync(CancellationToken cancellationToken) {
        var synapse = hs as AuthenticatedHomeserverSynapse;
        await foreach (var room in synapse.Admin.SearchRoomsAsync())
        {
            try
            {
                await synapse.Admin.DeleteRoom(room.RoomId, new() { ForcePurge = true });
                Console.WriteLine($"Deleted room: {room.RoomId}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to delete room {room.RoomId}: {ex.Message}");
            }
        }

        await host.StopAsync(cancellationToken);
    }

    public async Task StopAsync(CancellationToken cancellationToken) { }

    private async Task PrintHelp() {
        Console.WriteLine("Usage: execute [filename]");
        Console.WriteLine("Options:");
        Console.WriteLine("  --help     Show this help message");
        await host.StopAsync();
    }
}