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());
			}*/
		}
Esempio n. 2
0
        public async Task <Embed> BuildLockedListAsync(ICommandContext context, CommandSetDetails commandSet)
        {
            IDbLockableContext lockContext = await Contexting.FindDbLockableContextAsync(context).ConfigureAwait(false);

            var embed = new EmbedBuilder()
            {
                Color       = configParser.EmbedColor,
                Title       = $"{configParser.EmbedPrefix}{configParser.ParseTitle("locked", LockedTitle)}",
                Description = configParser.ParseDescription("locked", LockedDesc),
            };

            foreach (ModuleDetails module in commandSet)
            {
                bool moduleLocked = module.IsModuleLocked(lockContext);

                /*StringBuilder str = new StringBuilder();
                 * foreach (CommandDetails command in module) {
                 *      string commandLocked = FormatCommandLocked(lockContext, command);
                 *      if (!string.IsNullOrEmpty(moduleLocked) || !string.IsNullOrEmpty(commandLocked)) {
                 *              str.AppendLine($"{commandLocked}{command.Alias}");
                 *      }
                 * }*/
                string lockedCommands = FormatLockedCommandList(lockContext, moduleLocked, module);
                if (lockedCommands.Length > 0)
                {
                    embed.AddField($"{FormatModuleLocked(moduleLocked)}{module.Name}", lockedCommands);
                }
            }
            return(embed.Build());
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the prefix and lock context of the bot.
        /// </summary>
        private async Task <(string prefix, IDbLockableContext lockContext)> GetPrefixAndLockContextAsync(
            ICommandContext context)
        {
            using (var db = Contexting.GetCommandContextDb()) {
                IDbPrefixContext prefixContext = await Contexting.FindDbPrefixContextAsync(db, context, false).ConfigureAwait(false);

                string prefix = prefixContext.GetPrefix(Contexting);
                if (prefixContext is IDbLockableContext lockContext)
                {
                    return(prefix, lockContext);
                }
                else
                {
                    return(prefix, await Contexting.FindDbLockableContextAsync(db, context, false).ConfigureAwait(false));
                }
            }
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        public async Task GetPrefix()
        {
            string prefix = await Contexting.GetPrefixAsync(Context).ConfigureAwait(false);

            await ReplyAsync($"**Prefix:** `{Format.Sanitize(prefix)}`").ConfigureAwait(false);
        }