public static async Task ShowHelpCategory(ICommandContext context, string commandInfoDirectory, string category) { if (!System.IO.Directory.Exists(commandInfoDirectory)) { await BotUtils.ReplyAsync_Error(context, string.Format("Help information cannot be displayed, because the help directory \"{0}\" does not exist.", commandInfoDirectory)); return; } await _showHelpCategory(context, HelpUtils.GetCommandInfoFromDirectory(commandInfoDirectory), category); }
public static async Task ShowHelp(ICommandContext context, string command, string nestedCommand) { // Load the .json files containing command information. // If there is a subdirectory in the help directory with the same name as the command, load files in that subdirectory instead. string help_directory = HelpUtils.HELP_DIRECTORY; if (!string.IsNullOrEmpty(nestedCommand) && System.IO.Directory.Exists(System.IO.Path.Combine(help_directory, command))) { help_directory = System.IO.Path.Combine(help_directory, command); } if (System.IO.Directory.Exists(help_directory)) { CommandHelpInfoCollection commands = HelpUtils.GetCommandInfoFromDirectory(help_directory); if (!string.IsNullOrEmpty(command)) { // If the user provided a specific command name, show information about that command. CommandHelpInfo info = commands.FindCommandByName(string.IsNullOrEmpty(nestedCommand) ? command : nestedCommand); if (info is null) { await context.Channel.SendMessageAsync("The given command does not exist, or is not yet documented."); } else { // Prefix the command with is parent if applicable. if (!string.IsNullOrEmpty(nestedCommand)) { info.Name = command.Trim() + " " + info.Name; } EmbedBuilder builder = new EmbedBuilder(); builder.WithTitle(string.Format("Help: {0}", info.Name)); builder.AddField("Description", info.Description.Replace("\\prefix", OurFoodChainBot.Instance.Config.Prefix)); if (info.Aliases.Count() > 0) { builder.AddField("Aliases", string.Join(", ", info.Aliases.OrderBy(x => x))); } if (info.Examples.Count() > 0) { for (int i = 0; i < info.Examples.Count(); ++i) { info.Examples[i] = "`" + OurFoodChainBot.Instance.Config.Prefix + (string.IsNullOrEmpty(nestedCommand) ? "" : command.Trim() + " ") + info.Examples[i] + "`"; } builder.AddField("Example(s)", string.Join(Environment.NewLine, info.Examples)); } await context.Channel.SendMessageAsync("", false, builder.Build()); } } else { await _showHelpCategory(context, commands, ""); } } else { await BotUtils.ReplyAsync_Error(context, string.Format("Help information cannot be displayed, because the help directory \"{0}\" does not exist.", help_directory)); } }