using System.Text.Json; using System.Text.Json.Serialization; using LibMatrix; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; namespace MiniUtils.Commands; public class DumpTimelineCommand(MiniUtilsConfiguration config, HomeserverProviderService hsProvider) : ICommand { public string Name => "dump timeline"; public string[]? Aliases => ["dt"]; public string Description => "Dump timeline"; public bool Unlisted => false; public async Task Invoke(CommandContext ctx) { MessagesResponse res; if (ctx.Args.Length < 1) { res = await ctx.Room.GetMessagesAsync(limit: 250); } else { var profile = config.ExternalProfiles[ctx.Args[0]]; var rhs = await hsProvider.GetAuthenticatedWithToken(profile.Homeserver, profile.AccessToken, enableServer: false, useGeneric: true); res = await rhs.GetRoom(ctx.Room.RoomId).GetMessagesAsync(limit: 250); } var ms = new MemoryStream(); await JsonSerializer.SerializeAsync(ms, res, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, WriteIndented = true }); ms.Seek(0, SeekOrigin.Begin); await ctx.Room.SendFileAsync("timeline.json", ms, contentType: "application/json"); } }