about summary refs log tree commit diff
path: root/Utilities
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-03-17 13:30:38 +0100
committerRory& <root@rory.gay>2024-03-17 13:30:38 +0100
commit677fe757733ab4af327ba74d047195be7d578e60 (patch)
treee4502c0ce8e021e0533f84706568669b36bbe0da /Utilities
parentAdd AddCollapsiblePart to MessageBuilder (diff)
downloadLibMatrix-677fe757733ab4af327ba74d047195be7d578e60.tar.xz
Bot related fixes, image size
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs4
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs14
3 files changed, 11 insertions, 9 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index 9959bf6..5e021a2 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -5,7 +5,7 @@ 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; }
 
diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
index 062e99f..c6abde2 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
@@ -14,8 +14,8 @@ public class CommandContext {
         .SkipWhile(x => x.StartsWith(">"))
         .Aggregate((x, y) => $"{x}\n{y}");
 
-    public string CommandName => MessageContentWithoutReply.Split(' ')[0][1..];
-    public string[] Args => MessageContentWithoutReply.Split(' ')[1..];
+    public required string CommandName;
+    public required string[] Args;
     public required AuthenticatedHomeserverGeneric Homeserver { get; set; }
 
     public async Task<EventIdResponse> Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content);
diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
index 1f91268..fdf919b 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
@@ -112,19 +112,21 @@ public class CommandListenerHostedService : IHostedService {
         var message = evt.TypedContent as RoomMessageEventContent;
         var room = _hs.GetRoom(evt.RoomId!);
         
-        var ctx = new CommandContext {
-            Room = room,
-            MessageEvent = @evt,
-            Homeserver = _hs
-        };
         
         var commandWithoutPrefix = message.BodyWithoutReplyFallback[usedPrefix.Length..];
         var command = _commands.OrderByDescending(x => x.Name.Length).FirstOrDefault(x => commandWithoutPrefix.StartsWith(x.Name));
         if (commandWithoutPrefix.Length != command.Name.Length && commandWithoutPrefix[command.Name.Length] != ' ') command = null;
 
+        var ctx = new CommandContext {
+            Room = room,
+            MessageEvent = @evt,
+            Homeserver = _hs,
+            Args = commandWithoutPrefix.Split(' ').Length == 1 ? [] : commandWithoutPrefix.Split(' ')[1..],
+            CommandName = commandWithoutPrefix.Split(' ')[0]
+        };
         if (command == null) {
             await room.SendMessageEventAsync(
-                new RoomMessageEventContent("m.notice", $"Command \"{commandWithoutPrefix.Split(' ')[0]}\" not found!"));
+                new RoomMessageEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!"));
             return new() {
                 Success = false,
                 Result = CommandResult.CommandResultType.Failure_InvalidCommand,