From 82e5660b63ea6466e22f855fe524b288b62da7f9 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 18 May 2025 22:52:39 +0200 Subject: More stuff --- MiniUtils/Commands/DumpTimelineCommand.cs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 MiniUtils/Commands/DumpTimelineCommand.cs (limited to 'MiniUtils/Commands/DumpTimelineCommand.cs') diff --git a/MiniUtils/Commands/DumpTimelineCommand.cs b/MiniUtils/Commands/DumpTimelineCommand.cs new file mode 100644 index 0000000..4ee53c9 --- /dev/null +++ b/MiniUtils/Commands/DumpTimelineCommand.cs @@ -0,0 +1,38 @@ +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"); + } +} \ No newline at end of file -- cgit 1.5.1