Пример #1
0
        /// <summary>
        /// This event is triggered every time the a user sends a message in a channel, dm etc. that the bot has access to view.
        /// </summary>
        /// <param name="socketMessage">
        /// The socket message.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        internal async Task MessageReceivedAsync(SocketMessage socketMessage)
        {
            if (!(socketMessage is SocketUserMessage Message) || Message.Channel is IDMChannel)
            {
                return;
            }

            var context = new Context(Client, Message, Provider);

            if (Config.LogUserMessages)
            {
                LogHandler.LogMessage(context);
            }

            var argPos = 0;

            if (DBConfig.Local.Developing && DBConfig.Local.PrefixOverride != null)
            {
                if (!Message.HasStringPrefix(DBConfig.Local.PrefixOverride, ref argPos))
                {
                    return;
                }
            }
            else
            {
                // Filter out all messages that don't start with our Bot Prefix, bot mention or server specific prefix.
                if (!(Message.HasStringPrefix(PrefixDictionary.Load().GuildPrefix(context.Guild.Id) ?? Config.Prefix, ref argPos) || Message.HasMentionPrefix(context.Client.CurrentUser, ref argPos)))
                {
                    return;
                }
            }

            // Here we attempt to execute a command based on the user message
            var result = await CommandService.ExecuteAsync(context, argPos, Provider, MultiMatchHandling.Best);

            // Generate an error message for users if a command is unsuccessful
            if (!result.IsSuccess)
            {
                var _ = Task.Run(() => CmdErrorAsync(context, result, argPos));
            }
            else
            {
                if (Config.LogCommandUsages)
                {
                    LogHandler.LogMessage(context);
                }
            }
        }
Пример #2
0
        public Task CustomPrefixAsync([Remainder] string prefix = null)
        {
            // Modify the prefix and then update the object within the database.
            var prefixDict = PrefixDictionary.Load();

            if (prefix == null)
            {
                prefixDict.PrefixList.Remove(Context.Guild.Id);
            }
            else
            {
                prefixDict.PrefixList.Add(Context.Guild.Id, prefix);
            }

            prefixDict.Save();

            // If prefix is null, we default back to the default bot prefix
            return(SimpleEmbedAsync($"Prefix is now: {prefix ?? ConfigModel.Prefix}"));
        }