Пример #1
0
        private async Task HandleMessageReceived(SocketMessage rawMessage)
        {
            // Ignore system messages and messages from bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }

            if (message.Source != MessageSource.User)
            {
                return;
            }

            var commandContext = new SocketCommandContext(client, message);

            var argumentPosition = 0;

            if (!message.HasMentionPrefix(client.CurrentUser, ref argumentPosition))
            {
                // The message @Bot will come as <@{Id}> but client.CurrentUser.Mention is <@!{Id}>
                // So to be safe check for both in case it is changed...
                if (message.Content.Equals(client.CurrentUser.Mention) ||
                    message.Content.Equals(client.CurrentUser.Mention.Replace("!", string.Empty)))
                {
                    IResult defaultResponseResult =
                        await commandService.ExecuteDefaultResponse(commandContext, argumentPosition);
                    await LogResult(commandContext, defaultResponseResult);
                }

                argumentPosition = 0;
                if (!message.HasCharPrefix('!', ref argumentPosition))
                {
                    // Not going to respond
                    return;
                }
            }

            IResult result = await commandService.ExecuteAsync(commandContext, argumentPosition);

            await LogResult(commandContext, result);
        }