private async Task OnMessageReceived(SocketMessage rawMessage) { // Ignore system messages, or messages from other bots if (!(rawMessage is SocketUserMessage message)) return; // Don't process my own output dumbass! if (message.Author.Id == Client.CurrentUser.Id) return; // Modules use the AllowBots precondition attribute, so let them pass... for now. if (message.Source != MessageSource.User && message.Source != MessageSource.Bot) return; var context = Contexting.CreateCommandContext(message); // Check if the message has a valid command prefix // This value holds the offset where the prefix ends int argPos = 0; string prefix = await Contexting.GetPrefixAsync(context).ConfigureAwait(false); bool hasMention = message.HasMentionPrefix(Client.CurrentUser, ref argPos); bool hasPrefix = message.HasStringPrefix(prefix, ref argPos, StringComparison.InvariantCultureIgnoreCase); if (!hasMention && !hasPrefix) return; context.ArgPos = argPos; if (!(await AllowCommandAsync(context).ConfigureAwait(false))) return; var result = await Commands.ExecuteAsync(context, argPos, Services).ConfigureAwait(false); /*if (result.Error.HasValue && !result.Reacted) { if (!string.IsNullOrWhiteSpace(result.ErrorReason)) await context.Channel.SendMessageAsync(result.ErrorReason); else await context.Channel.SendMessageAsync(result.Error.ToString()); }*/ }
public async Task <Embed> BuildAboutEmbedAsync(ICommandContext context, Func <EmbedBuilder, Task> addFields) { var embed = new EmbedBuilder { Color = configParser.EmbedColor, Title = $"{configParser.EmbedPrefix}{configParser.ParseTitle("about", AboutTitle)}", }; //embed.WithThumbnailUrl(Client.CurrentUser.GetAvatarUrl()); embed.Description = configParser.ParseLinks("about"); string aboutDesc = configParser.ParseDescription("about", AboutDesc); if (aboutDesc != null) { embed.AddField("About", aboutDesc); } string prefix = await Contexting.GetPrefixAsync(context).ConfigureAwait(false); embed.AddField("Prefix", $"The command prefix is `{prefix}`"); // is present on **{Client.Guilds.Count}** servers!"); /*TimeSpan uptime = DiscordBot.Uptime; * int d = (int) uptime.TotalDays; * int h = uptime.Hours; * int m = uptime.Minutes; * int s = uptime.Seconds; * uptime = DiscordBot.TotalUptime; * int d2 = (int) uptime.TotalDays; * int h2 = uptime.Hours; * int m2 = uptime.Minutes; * int s2 = uptime.Seconds; * int guilds = Client.Guilds.Count; * long spoilers = await this.spoilers.GetSpoilerCountAsync().ConfigureAwait(false); * long spoiledUsers = await this.spoilers.GetSpoiledUserCountAsync().ConfigureAwait(false); * long members = Client.Guilds.Sum(g => g.Users.Count); * * embed.AddField("Stats", $"**{spoilers}** spoiler{Plural(spoilers)} have been revealed " + * $"**{spoiledUsers}** time{Plural(spoiledUsers)}"); * embed.AddField("Uptime", $"`Current:` " + * $"**{d}** day{Plural(d)}, " + * $"**{h}** hour{Plural(h)}, " + * $"**{m}** minute{Plural(m)}, and " + * $"**{s}** second{Plural(s)}\n" + * $"`Total:` " + * $"**{d2}** day{Plural(d)}, " + * $"**{h2}** hour{Plural(h)}, " + * $"**{m2}** minute{Plural(m)}, and " + * $"**{s2}** second{Plural(s)}"); * embed.AddField("Servers", $"Active on **{guilds}** server{Plural(guilds)} with " + * $"**{members}** member{Plural(members)}");*/ await addFields(embed).ConfigureAwait(false); return(embed.Build()); }
public async Task <Embed> BuildHelpListAsync(ICommandContext context, CommandSetDetails commandSet) { string prefix = await Contexting.GetPrefixAsync(context).ConfigureAwait(false); var embed = new EmbedBuilder() { Color = configParser.EmbedColor, Title = $"{configParser.EmbedPrefix}{configParser.ParseTitle("help", HelpTitle)}", Description = FormatDescription(prefix), }; foreach (ModuleDetails module in commandSet) { List <CommandDetails> usableCommands = module.GetUsableCommands(context).ToList(); if (usableCommands.Any()) { embed.AddField(module.Name, FormatCommandList(usableCommands)); } } //embed.WithThumbnailUrl(Client.CurrentUser.GetAvatarUrl()); return(embed.Build()); }
public async Task GetPrefix() { string prefix = await Contexting.GetPrefixAsync(Context).ConfigureAwait(false); await ReplyAsync($"**Prefix:** `{Format.Sanitize(prefix)}`").ConfigureAwait(false); }