about summary refs log tree commit diff
path: root/MiniUtils/Commands/DumpTimelineCommand.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-05-18 22:52:39 +0200
committerRory& <root@rory.gay>2025-05-18 22:52:39 +0200
commit82e5660b63ea6466e22f855fe524b288b62da7f9 (patch)
treeb9aa304da0002c2b85d4063a84f4d6e59e8f9008 /MiniUtils/Commands/DumpTimelineCommand.cs
parentAdd more commands (diff)
downloadMiniUtils-master.tar.xz
More stuff HEAD master
Diffstat (limited to 'MiniUtils/Commands/DumpTimelineCommand.cs')
-rw-r--r--MiniUtils/Commands/DumpTimelineCommand.cs38
1 files changed, 38 insertions, 0 deletions
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