/// <summary>Executes the command.</summary> /// <param name="actionInput">The full input specified for executing the command.</param> public override void Execute(ActionInput actionInput) { IController sender = actionInput.Controller; string requestedCategory = actionInput.Tail.ToLower(); // Get a command array of all commands available to this controller List <Command> commands = CommandManager.Instance.GetCommandsForController(sender); var output = new StringBuilder(); CommandCategory category = CommandCategory.None; Enum.TryParse(requestedCategory, true, out category); if (requestedCategory == "all" || category != CommandCategory.None) { if (category == CommandCategory.None) { output.AppendLine("All commands:"); } else { output.AppendFormat("{0} commands:\n", category.ToString()); } // Sort and then output commands in this category commands.Sort((Command a, Command b) => a.Name.CompareTo(b.Name)); foreach (Command c in commands) { if (c.Category.HasFlag(category)) { output.AppendFormat("{0}{1}\n", c.Name.PadRight(15), c.Description); } } } else { // Build a list of categories for the commands available to this player. output.AppendLine("Please specify a command category:\nAll"); foreach (CommandCategory c in Enum.GetValues(typeof(CommandCategory))) { if (c != CommandCategory.None) { List <Command> matchingcommands = commands.FindAll(c2 => c2.Category.HasFlag(c)); if (matchingcommands.Count() > 0) { output.AppendFormat("{0} ({1})\n", c.ToString(), matchingcommands.Count()); } } } } sender.Write(output.ToString()); }
public static EmbedBuilder GetCommandHelp(ulong guildId, string c = null, int page = 1) { BotConfig conf = BotConfig.Load(); IndividualConfig gconf = conf.GetConfig(guildId); List <BotCommand> commands = conf.Commands; int pages; CommandCategory category = CommandCategory.Main; if (c != null) { c = c.ToLower().Trim(); switch (c) { case "fun": category = CommandCategory.Fun; break; case "user": category = CommandCategory.User; break; case "server": category = CommandCategory.Server; break; case "botrelated": category = CommandCategory.BotRelated; break; case "moderation": category = CommandCategory.Moderation; break; case "games": category = CommandCategory.Games; break; case "nsfw": category = CommandCategory.NSFW; break; case "currency": category = CommandCategory.Currency; break; default: category = CommandCategory.Main; break; } } List <CommandCategory> cats = new List <CommandCategory>(); List <BotCommand> commandsToShow = new List <BotCommand>(); bool displayCommandInfo = false; BotCommand commandToDisplay = null; foreach (BotCommand command in commands) { if (c != null) { if (command.Handle.ToLower() == c.ToLower().Trim()) { commandToDisplay = command; displayCommandInfo = true; break; } } if (category == CommandCategory.Main) { if (!cats.Contains(command.Category)) { cats.Add(command.Category); } } if (command.Category == category) { if (!commandsToShow.Contains(command)) { commandsToShow.Add(command); } } } EmbedBuilder embed; if (!displayCommandInfo) { if (category == CommandCategory.Main) { pages = (cats.Count / 10); } else { pages = (commandsToShow.Count / 8); } if (page > pages) { page = pages; } embed = new EmbedBuilder() { Title = "Help: " + StringUtil.ToUppercaseFirst(category.ToString()), Color = Color.DarkPurple, Footer = new EmbedFooterBuilder() { Text = $"{EmojiUtil.GetRandomEmoji()} Server Prefix: {gconf.Prefix}" } }; if (category == CommandCategory.Main) { embed.Description = $"For further help use `{gconf.Prefix}help <commandCategory>`, for example `{gconf.Prefix}help fun`"; foreach (var cat in cats) { embed.AddField(new EmbedFieldBuilder() { Name = StringUtil.ToUppercaseFirst(cat.ToString()), Value = "category description", IsInline = true }); } } else { embed.Description = $"For further help use `{gconf.Prefix}help <commandName>`, for example `{gconf.Prefix}help roast`"; foreach (var command in commandsToShow) { embed.AddField(new EmbedFieldBuilder() { Name = StringUtil.ToUppercaseFirst(command.Handle), Value = command.Description, IsInline = true }); } } } else { embed = new EmbedBuilder() { Title = "Help: " + StringUtil.ToUppercaseFirst(commandToDisplay.Handle), Color = Color.DarkPurple, Footer = new EmbedFooterBuilder() { Text = $"{EmojiUtil.GetRandomEmoji()} <> - Required argument, [] - Optional argument" } }; string desc = $"{commandToDisplay.Description}\n\n**Usage:**"; foreach (var usage in commandToDisplay.Usage) { desc += $"\n**{gconf.Prefix}{usage.ToString()}** (eg. {gconf.Prefix}{usage.ToExample()})"; } embed.Description = desc; } return(embed); }