about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/Commands
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs21
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs2
2 files changed, 22 insertions, 1 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
index 9937b3c..979fab6 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
@@ -1,3 +1,4 @@
+using System.Collections.Frozen;
 using System.Text;
 using LibMatrix.EventTypes.Spec;
 using LibMatrix.Utilities.Bot.Interfaces;
@@ -7,12 +8,30 @@ namespace LibMatrix.Utilities.Bot.Commands;
 
 public class HelpCommand(IServiceProvider services) : ICommand {
     public string Name { get; } = "help";
+    public string[]? Aliases { get; } = new[] { "?" };
     public string Description { get; } = "Displays this help message";
+    public bool Unlisted { get; }
 
     public async Task Invoke(CommandContext ctx) {
         var sb = new StringBuilder();
         sb.AppendLine("Available commands:");
-        var commands = services.GetServices<ICommand>().ToList();
+        var commands = services.GetServices<ICommand>().Where(x => !x.Unlisted).ToList();
+        foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}");
+
+        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", sb.ToString()));
+    }
+}
+
+public class HelpCommandWithSubCommands<T>(T command) where T : ICommandGroup {
+    public string Name { get; } = "help";
+    public string[]? Aliases { get; } = new[] { "?" };
+    public string Description { get; } = "Displays this help message";
+
+    public async Task Invoke(CommandContext ctx) {
+        var sb = new StringBuilder();
+        sb.AppendLine("Available subcommands:");
+        var commands = command.SubCommands;
+
         foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}");
 
         await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", sb.ToString()));
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index b5fb868..9959bf6 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -5,7 +5,9 @@ namespace LibMatrix.Utilities.Bot.Commands;
 
 public class PingCommand : ICommand {
     public string Name { get; } = "ping";
+    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!"));
 }
\ No newline at end of file