about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-03-15 18:10:58 +0100
committerRory& <root@rory.gay>2024-03-15 18:11:18 +0100
commit096375344ef87fe53ca009b7a7eaa34c9c9f5407 (patch)
tree76d666cd6961ca04ae9e91e47c43d91eed27a87a /Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
parentFix README (diff)
downloadLibMatrix-096375344ef87fe53ca009b7a7eaa34c9c9f5407.tar.xz
Bot changes, move named filters to subclass
Diffstat (limited to 'Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs21
1 files changed, 20 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()));