Beispiel #1
0
        public async Task DiscoverPokemonAsync(EduardoContext context)
        {
            int roll = new Random().Next(0, _pokemonData.PokemonCount);

            IMessage waitingMessage = await context.Channel.SendMessageAsync($"{Format.Bold(context.User.Username)} is looking for a Pokemon...");

            Pokemon pokemonRoll = await PokemonHelper.GetPokemonFromApiAsync(roll + 1);

            await waitingMessage.DeleteAsync();

            if (pokemonRoll.Id != 0)
            {
                using Stream stream = await NetworkHelper.GetStreamAsync(pokemonRoll.Sprites.FrontDefaultSpriteUrl);

                await context.Channel.SendFileAsync(stream, $"{pokemonRoll.Name}.png", $"{Format.Bold(context.User.Username)} has found a wild {Format.Bold(pokemonRoll.Name.UpperFirstChar())}!");

                await _pokemonRepository.AddPokemonAsync((long)context.Message.Author.Id,
                                                         (long)((context.Message.Channel as SocketGuildChannel)?.Guild.Id ?? 0), pokemonRoll);
            }
            else
            {
                await Logger.Log($"Error fetching Pokemon with id {roll}", LogSeverity.Error);
            }
        }