From 49eba40d2bc6a98553e57e6f9b8496ff649147a8 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 3 Jun 2024 20:19:21 +0200 Subject: Initial commit --- Jenny/Commands/ConfigureCommand.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Jenny/Commands/ConfigureCommand.cs (limited to 'Jenny/Commands/ConfigureCommand.cs') diff --git a/Jenny/Commands/ConfigureCommand.cs b/Jenny/Commands/ConfigureCommand.cs new file mode 100644 index 0000000..efd3417 --- /dev/null +++ b/Jenny/Commands/ConfigureCommand.cs @@ -0,0 +1,38 @@ +using System.Text; +using LibMatrix.EventTypes.Spec; +using LibMatrix.Utilities.Bot.Commands; +using LibMatrix.Utilities.Bot.Interfaces; +using Microsoft.Extensions.DependencyInjection; + +namespace Jenny.Commands; + +public class ConfigureCommand(IServiceProvider svcs) : ICommandGroup { + public string Name { get; } = "configure"; + public string[]? Aliases { get; } = ["config", "cfg"]; + public string Description { get; } + public bool Unlisted { get; } = true; + + public async Task Invoke(CommandContext ctx) { + var commands = svcs.GetServices().Where(x => x.GetType().IsAssignableTo(typeof(ICommand<>).MakeGenericType(GetType()))).ToList(); + + if (ctx.Args.Length == 0) { + await ctx.Room.SendMessageEventAsync(HelpCommand.GenerateCommandList(commands).Build()); + } + else { + var subcommand = ctx.Args[0]; + var command = commands.FirstOrDefault(x => x.Name == subcommand || x.Aliases?.Contains(subcommand) == true); + if (command == null) { + await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", "Unknown subcommand")); + return; + } + + await command.Invoke(new CommandContext { + Room = ctx.Room, + MessageEvent = ctx.MessageEvent, + CommandName = ctx.CommandName, + Args = ctx.Args.Skip(1).ToArray(), + Homeserver = ctx.Homeserver + }); + } + } +} \ No newline at end of file -- cgit 1.5.1