about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-04-24 10:07:38 +0200
committerRory& <root@rory.gay>2025-04-24 10:07:38 +0200
commit0557fd17d424950ed9a16902443265bd4d2725e0 (patch)
tree8d06c100ded6479431ae78050a10b85d4ee8e5c5
parentFix args when using commands with spaces (diff)
downloadLibMatrix-0557fd17d424950ed9a16902443265bd4d2725e0.tar.xz
Maubot ping compat, make json extensibility easier to use
-rw-r--r--LibMatrix.EventTypes/EventContent.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs15
2 files changed, 15 insertions, 2 deletions
diff --git a/LibMatrix.EventTypes/EventContent.cs b/LibMatrix.EventTypes/EventContent.cs

index 89686ae..1011e88 100644 --- a/LibMatrix.EventTypes/EventContent.cs +++ b/LibMatrix.EventTypes/EventContent.cs
@@ -7,7 +7,7 @@ namespace LibMatrix.EventTypes; public abstract class EventContent { [JsonExtensionData] - public Dictionary<string, JsonElement>? AdditionalData { get; set; } = []; + public Dictionary<string, object>? AdditionalData { get; set; } = []; public static List<string> GetMatchingEventTypes<T>() where T : EventContent { var type = typeof(T); 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