about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/Commands
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/LibMatrix.Utilities.Bot/Commands')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs1
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs5
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs24
3 files changed, 23 insertions, 7 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs

index 5c9c480..9107c4c 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs
@@ -1,4 +1,3 @@ -using System.Collections.Frozen; using System.Text; using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
index 0abc76b..f29d6e9 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
@@ -1,6 +1,3 @@ -using System.Collections.Frozen; -using System.Text; -using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.DependencyInjection; @@ -9,7 +6,7 @@ namespace LibMatrix.Utilities.Bot.Commands; public class HelpCommand(IServiceProvider services) : ICommand { public string Name { get; } = "help"; - public string[]? Aliases { get; } = new[] { "?" }; + public string[]? Aliases { get; } = ["?"]; public string Description { get; } = "Displays this help message"; public bool Unlisted { get; } 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