about summary refs log tree commit diff
path: root/Utilities
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-04-24 01:36:14 +0200
committerRory& <root@rory.gay>2025-04-24 01:36:14 +0200
commit6db2a6bf7a203c05d478d3b6b5a7636fe622ffb3 (patch)
tree5420a0757778e0e5f79dda9721fbfeb9c5b210a4 /Utilities
parentAllow early return in SyncHelper, trim access token if path used, fix shutdow... (diff)
downloadLibMatrix-6db2a6bf7a203c05d478d3b6b5a7636fe622ffb3.tar.xz
Fix command names with spaces, allow specifying formatted body in MessageBuilder#WithBody
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs8
1 files changed, 6 insertions, 2 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs

index f9b46d2..750e6a3 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
@@ -137,15 +137,19 @@ public class CommandListenerHostedService : IHostedService { var room = _hs.GetRoom(evt.RoomId!); var commandWithoutPrefix = message.BodyWithoutReplyFallback[usedPrefix.Length..].Trim(); + var usedCommand = _commands + .SelectMany<ICommand, string>(x => [x.Name, ..x.Aliases ?? []]) + .OrderByDescending(x => x.Length) + .FirstOrDefault(commandWithoutPrefix.StartsWith); var ctx = new CommandContext { Room = room, MessageEvent = @evt, Homeserver = _hs, Args = commandWithoutPrefix.Split(' ').Length == 1 ? [] : commandWithoutPrefix.Split(' ')[1..], - CommandName = commandWithoutPrefix.Split(' ')[0] + CommandName = usedCommand ?? commandWithoutPrefix.Split(' ')[0] }; try { - var command = _commands.SingleOrDefault(x => x.Name == commandWithoutPrefix.Split(' ')[0] || x.Aliases?.Contains(commandWithoutPrefix.Split(' ')[0]) == true); + var command = _commands.SingleOrDefault(x => x.Name == ctx.CommandName || x.Aliases?.Contains(ctx.CommandName) == true); if (command == null) { await room.SendMessageEventAsync( new RoomMessageEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!"));