1 files changed, 22 insertions, 2 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index 76e48f5..ff41b70 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -5,9 +5,29 @@ 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!"));
+ public async Task Invoke(CommandContext ctx) {
+ 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 = 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
+ }
+ }
+ });
+ }
}
\ No newline at end of file
|