Maubot ping compat, make json extensibility easier to use
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
|