2 files changed, 15 insertions, 3 deletions
diff --git a/LibMatrix.EventTypes/EventContent.cs b/LibMatrix.EventTypes/EventContent.cs
index 1011e88..07f56e2 100644
--- a/LibMatrix.EventTypes/EventContent.cs
+++ b/LibMatrix.EventTypes/EventContent.cs
@@ -53,6 +53,9 @@ public abstract class TimelineEventContent : EventContent {
// used for reactions
[JsonPropertyName("key")]
public string? Key { get; set; }
+
+ [JsonExtensionData]
+ public Dictionary<string, object>? AdditionalData { get; set; } = [];
public class EventInReplyTo {
[JsonPropertyName("event_id")]
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index 4719c1e..ff41b70 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -5,18 +5,27 @@ namespace LibMatrix.Utilities.Bot.Commands;
public class PingCommand : ICommand {
public string Name { get; } = "ping";
- public string[]? Aliases { get; } = [ ];
+ public string[]? Aliases { get; } = [];
public string Description { get; } = "Pong!";
public bool Unlisted { get; }
public async Task Invoke(CommandContext ctx) {
- await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!") {
+ var latency = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - ctx.MessageEvent.OriginServerTs;
+ await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: $"Pong! ({latency} ms)") {
AdditionalData = new() {
// maubot ping compatibility
["pong"] = new {
- ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - ctx.MessageEvent.OriginServerTs,
+ ms = latency,
from = ctx.Homeserver.ServerName,
ping = ctx.MessageEvent.EventId
+ },
+ },
+ RelatesTo = new() {
+ RelationType = "xyz.maubot.pong",
+ EventId = ctx.MessageEvent.EventId,
+ AdditionalData = new() {
+ ["ms"] = latency!,
+ ["from"] = ctx.Homeserver.ServerName
}
}
});
|