示例#1
0
        private async Task ProcessCommand(SocketMessage messageParam)
        {
            if (messageParam.Author.IsBot)
            {
                return;
            }

            //Are we able to do XP for this message?
            if (!messageParam.Author.IsBot && !XpCooldowns.Contains(messageParam.Author.Id))
            {
                XpHandler(messageParam);
            }

            //Are we able to do karma for this message?
            if (!messageParam.Author.IsBot && messageParam.MentionedUsers.Count > 0)
            {
                KarmaHandlerAsync(messageParam);
            }

            //Is this an introduction message?
            if (!messageParam.Author.IsBot && messageParam.Channel.Id == PrivateSettings.IntrosChannel)
            {
                HandleIntroductionsMessage(messageParam);
                return;
            }

            //Warning: The following code is a direct copy from 2Bdroid Discord bot

            // Don't process the command if it was a System Message
            if (!(messageParam is SocketUserMessage message))
            {
                return;
            }
            // Create a number to track where the prefix ends and the command begins
            int argPos = 0;

            //char prefix = PrivateSettings.Prefix;
            // Determine if the message is a command, based on if it starts with '!' or a mention prefix
            if (!(message.HasStringPrefix(PrivateSettings.Prefix, ref argPos) || message.HasMentionPrefix(Client.CurrentUser, ref argPos)))
            {
                return;
            }
            // Create a Command Context
            CommandContext context = new CommandContext(Client, message);

            // Execute the command. (result does not indicate a return value,
            // rather an object stating if the command executed successfully)
            IResult result = await commandService.ExecuteAsync(context, argPos, services);

            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync(result.ErrorReason).DeleteAfterSeconds(10);

                //redirects commands channel exclusive commands there
                if (result.ErrorReason.StartsWith("That command can only be used in"))
                {
                    await RedirectCommand(message, argPos, CommandsChannel);

                    await messageParam.DeleteAsync();
                }
                else
                {
                    messageParam.DeleteAfterSeconds(10);
                }
            }
        }