예제 #1
0
        private async Task MessageReceivedAsync(MessageReceivedEventArgs args)
        {
            if (!(args.Message is CachedUserMessage userMessage))
            {
                return;
            }
            if (userMessage.Author.IsBot)
            {
                return;
            }

            var guildChannel = userMessage.Channel as CachedTextChannel;

            if (guildChannel != null)
            {
                await RunTaskAsync(_botService.AddAssignableRoleAsync((CachedMember)userMessage.Author));
                await RunTaskAsync(_xpService.AddUserXpAsync(userMessage.Author));
                await RunTaskAsync(_xpService.AddGuildUserXpAsync((CachedMember)userMessage.Author, userMessage.Channel));
            }

            var prefix = await GetGuildPrefixAsync(guildChannel?.Guild);

            if (CommandUtilities.HasPrefix(userMessage.Content, prefix, out var output) ||
                RiasUtilities.HasMentionPrefix(userMessage, out output))
            {
                await RunTaskAsync(ExecuteCommandAsync(userMessage, userMessage.Channel, prefix, output));

                return;
            }

            if (userMessage.Client.CurrentUser is null)
            {
                return;
            }

            if (CommandUtilities.HasPrefix(userMessage.Content, userMessage.Client.CurrentUser.Name, StringComparison.InvariantCultureIgnoreCase, out output))
            {
                await RunTaskAsync(ExecuteCommandAsync(userMessage, userMessage.Channel, prefix, output));
            }
        }