using System.Collections.Generic; using System.Linq; using Discord; using Discord.Commands; using Discord.WebSocket; using PluginManager.Interfaces; using PluginManager.Loaders; using PluginManager.Others; namespace DiscordBot.Discord.Commands; /// /// The help command /// internal class Help : DBCommand { /// /// Command name /// public string Command => "help"; public List Aliases => null; /// /// Command Description /// public string Description => "This command allows you to check all loaded commands"; /// /// Command usage /// public string Usage => "help "; /// /// Check if the command can be used /> /// public bool canUseDM => true; /// /// Check if the command can be used in a server /// public bool canUseServer => true; /// /// Check if the command require administrator to be executed /// public bool requireAdmin => false; /// /// The main body of the command /// /// The command context /// The command message /// The discord bot client /// True if the message was sent from a DM channel, false otherwise public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) { var args = Functions.GetArguments(message); if (args.Count != 0) { foreach (var item in args) { var e = GenerateHelpCommand(item); if (e is null) context.Channel.SendMessageAsync("Unknown Command " + item); else context.Channel.SendMessageAsync(embed: e.Build()); } return; } var embedBuilder = new EmbedBuilder(); var adminCommands = ""; var normalCommands = ""; var DMCommands = ""; foreach (var cmd in PluginLoader.Commands!) { if (cmd.canUseDM) DMCommands += cmd.Command + " "; if (cmd.requireAdmin) adminCommands += cmd.Command + " "; if (cmd.canUseServer) normalCommands += cmd.Command + " "; } embedBuilder.AddField("Admin Commands", adminCommands); embedBuilder.AddField("Normal Commands", normalCommands); embedBuilder.AddField("DM Commands", DMCommands); context.Channel.SendMessageAsync(embed: embedBuilder.Build()); } private EmbedBuilder GenerateHelpCommand(string command) { var embedBuilder = new EmbedBuilder(); var cmd = PluginLoader.Commands!.Find(p => p.Command == command || (p.Aliases is not null && p.Aliases.Contains(command))); if (cmd == null) return null; embedBuilder.AddField("Usage", cmd.Usage); embedBuilder.AddField("Description", cmd.Description); if (cmd.Aliases is null) return embedBuilder; embedBuilder.AddField("Alias", cmd.Aliases.Count == 0 ? "-" : string.Join(", ", cmd.Aliases)); return embedBuilder; } }