From 0557fd17d424950ed9a16902443265bd4d2725e0 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 24 Apr 2025 10:07:38 +0200 Subject: Maubot ping compat, make json extensibility easier to use --- Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Utilities/LibMatrix.Utilities.Bot/Commands') diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs index 76e48f5..161832c 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs @@ -1,3 +1,5 @@ +using System.Text.Json; +using System.Text.Json.Nodes; using LibMatrix.EventTypes.Spec; using LibMatrix.Utilities.Bot.Interfaces; @@ -9,5 +11,16 @@ public class PingCommand : ICommand { public string Description { get; } = "Pong!"; public bool Unlisted { get; } - public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!")); + public async Task Invoke(CommandContext ctx) { + await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!") { + AdditionalData = new() { + // maubot ping compatibility + ["pong"] = new { + ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - ctx.MessageEvent.OriginServerTs, + from = ctx.Homeserver.ServerName, + ping = ctx.MessageEvent.EventId + } + } + }); + } } \ No newline at end of file -- cgit 1.5.1