From b992d20da79b9de020d629bf9574abefff9c4b12 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 20 Mar 2024 12:00:54 +0100 Subject: New messagebuilder stuff, table-based help command --- .../Commands/AliassesCommand.cs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs (limited to 'Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs') diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs new file mode 100644 index 0000000..5c9c480 --- /dev/null +++ b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs @@ -0,0 +1,43 @@ +using System.Collections.Frozen; +using System.Text; +using LibMatrix.EventTypes.Spec; +using LibMatrix.Helpers; +using LibMatrix.Utilities.Bot.Interfaces; +using Microsoft.Extensions.DependencyInjection; + +namespace LibMatrix.Utilities.Bot.Commands; + +public class AliassesCommand(IServiceProvider services) : ICommand { + public string Name { get; } = "aliasses"; + public string[]? Aliases { get; } + public string Description { get; } = "Displays aliasses for a command"; + public bool Unlisted { get; } = true; + //TODO: implement command + + public async Task Invoke(CommandContext ctx) { + var sb = new StringBuilder(); + sb.AppendLine("Available commands:"); + var commands = services.GetServices().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())); + + var msb = new MessageBuilder("m.notice"); + msb.WithHtmlTag("table", tb => { + tb.WithHtmlTag("thead", th => th.WithBody("Available commands")); + tb.WithHtmlTag("tr", tr => { + tr.WithHtmlTag("th", th => th.WithBody("Command")); + tr.WithHtmlTag("th", th => th.WithBody("Aliasses")); + tr.WithHtmlTag("th", th => th.WithBody("Description")); + }); + foreach (var command in commands) { + tb.WithHtmlTag("tr", tr => { + tr.WithHtmlTag("td", td => td.WithBody(command.Name)); + tr.WithHtmlTag("td", td => td.WithBody(string.Join(", ", command.Aliases))); + tr.WithHtmlTag("td", td => td.WithBody(command.Description)); + }); + } + }); + await ctx.Room.SendMessageEventAsync(msb.Build()); + } +} \ No newline at end of file -- cgit 1.4.1