Example #1
0
        public async Task ShowPokemonInventoryAsync(EduardoContext context)
        {
            Dictionary <PokemonSummary, int> pokemonInventory = await _pokemonRepository.GetPokemonAsync((long)context.Message.Author.Id,
                                                                                                         (long)((context.Message.Channel as SocketGuildChannel)?.Guild.Id ?? 0));

            if (pokemonInventory.Count > 0)
            {
                List <Embed> pageEmbeds = new List <Embed>();

                for (int i = 0; i < pokemonInventory.Count; i += _pokemonData.MaxPokemonPerPage)
                {
                    List <KeyValuePair <PokemonSummary, int> > pokemonPage = pokemonInventory
                                                                             .Skip(i)
                                                                             .Take(Math.Min(_pokemonData.MaxPokemonPerPage, pokemonInventory.Count - i)).ToList();

                    pageEmbeds.Add(new EmbedBuilder()
                                   .WithColor(new Color(255, 255, 0))
                                   .WithAuthor($"{context.User.Username}'s Pokemon",
                                               context.User.GetAvatarUrl())
                                   .WithFieldsForList(pokemonPage, x => x.Key.Name.UpperFirstChar(), x => x.Value)
                                   .WithFooter($"Page {i / _pokemonData.MaxPokemonPerPage + 1} of {Math.Ceiling(pokemonInventory.Count / (double)_pokemonData.MaxPokemonPerPage)} | Pokemon via pokeapi.co",
                                               @"https://maxcdn.icons8.com/Share/icon/color/Gaming/pokeball1600.png")
                                   .Build());
                }

                await context.SendMessageOrPaginatedAsync(new PaginatedMessage
                {
                    Embeds           = pageEmbeds,
                    Timeout          = TimeSpan.FromSeconds(Constants.PAGINATION_TIMEOUT_SECONDS),
                    TimeoutBehaviour = TimeoutBehaviour.Delete
                });
            }
            else
            {
                await context.Channel.SendMessageAsync($"{context.User.Mention} You don't have any Pokemon! Use `{Constants.CMD_PREFIX}pokemon` to find a wild Pokemon!");
            }
        }