Ejemplo n.º 1
0
        public async Task <CommandResult> Pokedex(CommandContext context)
        {
            (Optional <User> optionalUser, Optional <string> optionalMode, Optional <User> optionalCompareUser) =
                await context.ParseArgs <Optional <User>, Optional <string>, Optional <User> >();

            User user   = optionalUser.OrElse(context.Message.User);
            bool isSelf = user == context.Message.User;

            if (!optionalMode.IsPresent)
            {
                int numUniqueSpecies = (await _badgeRepo.CountByUserPerSpecies(user.Id)).Count;
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {numUniqueSpecies} distinct Pokémon badge(s)"
                        : $"{user.Name} has collected {numUniqueSpecies} distinct Pokémon badge(s)"
                });
            }

            string mode = optionalMode.Value.ToLower();
            ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies =
                await _badgeRepo.CountByUserPerSpecies(user.Id);

            if (mode.Equals(PokedexModeMissing))
            {
                IEnumerable <PkmnSpecies> missingList     = _knownSpecies.Except(numBadgesPerSpecies.Keys);
                IEnumerable <string>      badgesFormatted = missingList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are currently missing the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} is currently missing the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeDupes))
            {
                var dupeList = numBadgesPerSpecies.Where(kvp => kvp.Value > 1).ToList();
                if (!dupeList.Any())
                {
                    return(new CommandResult
                    {
                        Response = isSelf
                            ? $"You do not own any duplicate Pokémon badges"
                            : $"{user.Name} does not own any duplicate Pokémon badges"
                    });
                }
                IEnumerable <string> badgesFormatted = dupeList.Select(kvp => $"{kvp.Key}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are owning duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} owns duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFromDupes))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFromDupes} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var compareUserDupeList = compareUser.Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key);

                var differenceList = compareUserDupeList.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any duplicate Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following duplicate badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFrom))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFrom} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var differenceList = compareUser.Keys.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (_pokedexModeRegions.ContainsKey(mode))
            {
                RegionInformation regionInformation = _pokedexModeRegions[mode];
                ImmutableSortedDictionary <PkmnSpecies, int> ownedPokemons = (await _badgeRepo.CountByUserPerSpecies(user.Id));
                int userOwnedRegionCount = mode.Equals(PokedexModeNational)
                    ? ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() != regionInformation.Generation)
                    : ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() == regionInformation.Generation);
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {userOwnedRegionCount}/{regionInformation.TotalRegionCount} "
                               + $"distinct {mode[0].ToString().ToUpper() + mode[1..].ToLower()} badge(s)"