public static EmbedBuilder Embed(EmbedColors Color, string AuthorName = null, string AuthorPic = null, string Title = null, string Description = null, string FooterText = null, string FooterIcon = null, string ImageUrl = null, string ThumbUrl = null) { return(Embed(Color) .WithAuthor(x => { x.Name = AuthorName; x.IconUrl = AuthorPic; }) .WithTitle(Title) .WithDescription(Description) .WithImageUrl(ImageUrl) .WithThumbnailUrl(ThumbUrl) .WithFooter(x => { x.Text = FooterText; x.IconUrl = FooterIcon; })); }
public async Task HelpAsync() { List <ModuleInfo> modules; EmbedBuilder embed; modules = _commands.Modules.Where(x => !string.IsNullOrWhiteSpace(x.Summary)).ToList(); embed = new EmbedBuilder() .WithFooter(x => x.Text = $"Type `{_config.Prefix}help <module>` for more information"); foreach (var module in modules) { bool success; success = false; foreach (var command in module.Commands) { PreconditionResult result; result = await command.CheckPreconditionsAsync(Context, _provider); if (result.IsSuccess) { success = true; break; } } if (!success) { continue; } embed.AddField(module.Name, module.Summary); } embed.WithColor(EmbedColors.GetSuccessColor()); await ReplyAsync("", embed : embed.Build()); }
public async Task HelpAsync(string moduleName) { ModuleInfo module; List <CommandInfo> commands; EmbedBuilder builder; module = _commands.Modules.FirstOrDefault(x => string.Equals(x.Name.ToLower(), moduleName.ToLower())); if (string.Equals(moduleName[0].ToString(), _config.Prefix)) { string commandName; CommandInfo command; commandName = moduleName.Substring(1); command = _commands.Commands.FirstOrDefault(x => x.Aliases.Any(z => string.Equals(z.ToLower(), commandName.ToLower()))); await HelpAsync(command.Module.Name, moduleName.Substring(1)); return; } if (module == null) { await ReplyAsync($"The module `{moduleName}` does not exist."); return; } commands = module.Commands.Where(x => !string.IsNullOrWhiteSpace(x.Summary)) .GroupBy(x => x.Name) .FirstOrDefault() .ToList(); if (!commands.Any()) { await ReplyAsync($"The module `{module.Name}` has no available commands :("); return; } builder = new EmbedBuilder(); foreach (var command in commands) { PreconditionResult result; result = await command.CheckPreconditionsAsync(Context, _provider); if (result.IsSuccess) { string field; field = command.Aliases.First(); if (command.Aliases.Count > 1) { List <string> skipped; string aliases; skipped = command.Aliases.Skip(1).ToList(); aliases = ""; // Iterate over all the aliases skipping the first one (as that is the main command) // and if we have any then build a string to display them. for (var i = 0; i < skipped.Count; i++) { if (i == skipped.Count - 1) { aliases += $"{skipped[i]}"; } else { aliases += $"{skipped[i]}, "; } } // If we had any aliases, then surround them with brackets for formatting sake. if (!string.IsNullOrEmpty(aliases)) { field = $"{field} ({aliases})"; } } builder.AddField($"{_config.Prefix}{field}", command.Summary); } } builder.WithColor(EmbedColors.GetSuccessColor()); await ReplyAsync("", embed : builder.Build()); }
/// <summary> /// Handles help commands for a specific command in a module. /// </summary> /// <param name="moduleName">The name of the module.</param> /// <param name="commandName">The name of the command.</param> /// <returns>An awaitable task.</returns> private async Task HelpAsync(string moduleName, string commandName) { string alias; ModuleInfo module; List <CommandInfo> commands; alias = $"{commandName}".ToLower(); module = _commands.Modules.FirstOrDefault(x => string.Equals(x.Name.ToLower(), moduleName.ToLower())); if (module == null) { await ReplyAsync($"The module `{moduleName}` does not exist."); return; } commands = module.Commands.Where(x => !string.IsNullOrWhiteSpace(x.Summary)).ToList(); if (!commands.Any()) { await ReplyAsync($"The module `{module.Name}` has no available commands."); return; } EmbedBuilder builder; List <string> aliases; builder = new EmbedBuilder(); aliases = new List <string>(); foreach (var overload in commands.Where(x => x.Aliases.Contains(alias))) { PreconditionResult result; result = await overload.CheckPreconditionsAsync(Context, _provider); if (result.IsSuccess) { StringBuilder stringBuilder; stringBuilder = new StringBuilder(); stringBuilder.Append(_config.Prefix + overload.Aliases.First()); foreach (var parameter in overload.Parameters) { string name; name = StringHelper.FirstCharToUpper(parameter.Name); if (parameter.IsRemainder) { name += "..."; } if (parameter.IsOptional) { name = $"[{name}]"; } else { name = $"<{name}>"; } stringBuilder.Append(" " + name); } builder.AddField(stringBuilder.ToString(), overload.Remarks ?? overload.Summary); } aliases.AddRange(overload.Aliases); } builder.WithFooter(x => x.Text = $"Aliases: {string.Join(", ", aliases)}"); builder.WithColor(EmbedColors.GetSuccessColor()); await ReplyAsync("", embed : builder.Build()); }
private async Task OnMessageReceivedAsync(SocketMessage s) { SocketUserMessage message; // Ensure the message is from a user/bot message = s as SocketUserMessage; // If the message is null, return. if (message == null) { return; } // Ignore self when checking commands. if (message.Author == _discord.CurrentUser) { return; } SocketCommandContext context; int argPos = 0; // Create the command context. context = new SocketCommandContext(_discord, message); // Check if the message has a valid command prefix. if (message.HasStringPrefix(_config.Prefix, ref argPos) || message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) { // Look at the second character of the command, if it's the same as the prefix then ignore it. // This gets around the bot treating a message like '...' as a command and trying to process it. if (!string.Equals(message.Content.Substring(1, 1), _config.Prefix)) { IResult result; Console.WriteLine(message.Content.ToString()); // Execute the command. result = await _commands.ExecuteAsync(context, argPos, _provider); if (!result.IsSuccess) { if (!string.IsNullOrEmpty(result.ErrorReason)) { await context.Channel.SendMessageAsync(result.ErrorReason); } else { EmbedBuilder embed; embed = new EmbedBuilder(); embed.WithColor(EmbedColors.GetErrorColor()); embed.AddField(":warning: An unexpected error occurred.", $"The command: '{message.Content}' is not a registered command."); // If not successful, reply with the error. await context.Channel.SendMessageAsync("", embed : embed.Build()); } } } } }
public static EmbedBuilder Embed(EmbedColors Color) { var embed = new EmbedBuilder(); switch (Color) { case EmbedColors.Blurple: embed.Color = new Color(0x7289DA); break; case EmbedColors.Cyan: embed.Color = new Color(0x8cfff6); break; case EmbedColors.Dark: embed.Color = new Color(0x2C2F33); break; case EmbedColors.Gold: embed.Color = new Color(0xfdff28); break; case EmbedColors.Green: embed.Color = new Color(0x93ff89); break; case EmbedColors.Maroon: embed.Color = new Color(0x800000); break; case EmbedColors.NotQuiteBlack: embed.Color = new Color(0x23272A); break; case EmbedColors.Orange: embed.Color = new Color(0xffba63); break; case EmbedColors.Pastle: embed.Color = new Color(0xa91edf); break; case EmbedColors.Red: embed.Color = new Color(0xff0000); break; case EmbedColors.Teal: embed.Color = new Color(0x008080); break; case EmbedColors.White: embed.Color = new Color(0xFFFFFF); break; case EmbedColors.Yellow: embed.Color = new Color(0xfff863); break; case EmbedColors.Purple: embed.Color = new Color(0xad33ff); break; } return(embed); }