Exemple #1
0
        private async Task ProcessCharacters(List <string> args)
        {
            if (args.Count != 1 || !Regex.IsMatch(args[0], RegexConstants.MentionRegex, RegexOptions.CultureInvariant))
            {
                await _messageService.SendMessage(_event.Message.ChannelId, new OutgoingMessage
                {
                    Content = "Incorrect command format: !plog characters [@discordusername]"
                });

                return;
            }

            var mentionId  = args[0].StripMentionExtras();
            var characters = await _plogDbContext.Plogs.Where(p => p.DiscordId == mentionId).OrderBy(u => u.MainId).ToListAsync();

            var powers = (await _powerService.GetWhaleScoresForUser(mentionId)).ToDictionary(x => x.Name, x => x);

            if (characters.Count == 0)
            {
                await _messageService.SendMessage(_event.Message.ChannelId, new OutgoingMessage
                {
                    Content = "That user doesn't have any characters in Ploggystyle."
                });

                return;
            }

            var user = await _userService.GetUser(mentionId);

            var fields = new List <EmbedField>();

            characters.ForEach(c =>
            {
                var power = "Whale Score: 0";
                if (powers.ContainsKey(c.Name))
                {
                    power = $"Whale Score: {powers[c.Name].Score}";
                }
                fields.Add(new EmbedField
                {
                    Name  = $"{_bladeAndSoulService.GetClassEmojiByClass(c.Class)} {c.Name}",
                    Value = power
                });
            });

            var main  = characters.Where(c => c.MainId == null).FirstOrDefault();
            var embed = new Embed
            {
                Title     = "Blade and Soul Characters",
                Url       = $"http://na-bns.ncsoft.com/ingame/bs/character/search/info?c={HttpUtility.UrlEncode(main.Name)}",
                Timestamp = DateTime.UtcNow,
                Color     = HexConstants.Green,
                Thumbnail = new EmbedItem
                {
                    Url = main.ImageUrl
                },
                Author = new EmbedItem
                {
                    Name    = main.RealName,
                    Url     = $"http://na-bns.ncsoft.com/ingame/bs/character/profile?c={HttpUtility.UrlEncode(main.Name)}",
                    IconUrl = user.Avatar != null ? $"https://cdn.discordapp.com/avatars/{user.Id}/{user.Avatar}.jpg" : null
                },
                Footer = new EmbedItem
                {
                    IconUrl = EmojiConstants.PlogUrl,
                    Text    = "PlogBot"
                },
                Fields = fields
            };

            await _messageService.SendMessage(_event.Message.ChannelId, new OutgoingMessage
            {
                Content = args[0],
                Embed   = embed
            });
        }