def pokedex_(client: discord.Client, message: discord.Message, name_or_id: Annotate.LowerCleanContent): """ Display some information of the given pokémon. """ # Do some quick replacements for flexible parsing name_or_id = name_or_id.strip() if name_or_id.startswith("#"): name_or_id = name_or_id.replace("#", "") if " " in name_or_id: if "♀" in name_or_id or "♀" in name_or_id or name_or_id.endswith("f") or name_or_id.endswith("m"): name_or_id = name_or_id.replace(" ", "-").replace("♂", "m").replace("♀", "f") else: name_or_id = name_or_id.replace(" ", "") # Get the requested pokemon name name = name_or_id try: pokemon_id = int(name_or_id) except ValueError: # See if there's a pokemon with the locale name formatted like the given name for pokemon in pokedex.values(): if pokemon["locale_name"].lower() == name: name = pokemon["name"] break # Correct the name if it is very close to an existing pokemon and there's only one close match matches = get_close_matches(name, pokedex.keys(), n=2, cutoff=0.8) if matches and len(matches) == 1: name = matches[0] assert name in pokedex, "There is no pokémon called **{}** in my pokédex!\nPerhaps you meant: `{}`?".format( name, ", ".join(get_close_matches(name, pokedex.keys(), cutoff=0.5))) else: name = id_to_name(pokemon_id) assert name is not None, "There is no pokémon with ID **#{:03}** in my pokédex!".format(pokemon_id) # Get the server's scale factor if not message.channel.is_private \ and message.server.id in pokedex_config.data and "scale-factor" in pokedex_config.data[message.server.id]: scale_factor = pokedex_config.data[message.server.id]["scale-factor"] else: scale_factor = default_scale_factor # Assign our pokemon pokemon = pokedex[name] # Assign the sprite to use if pokemon["id"] in sprites: sprite = sprites[pokemon["id"]] else: sprite = sprites[0] # Resize (if PIL is enabled) and upload the sprite if resize and not round(scale_factor, 2) == 1: sprite = resize_sprite(sprite, scale_factor) yield from client.send_file(message.channel, sprite, filename="{}.png".format(name)) # Format Pokemon GO specific info pokemon_go_info = "" if "evolution_cost" in pokemon: pokemon_go_info += "Evolution cost: `{} {} Candy` ".format( pokemon["evolution_cost"], egg_name(pokemon["evolution"])) if "hatches_from" in pokemon: if pokemon_go_info: pokemon_go_info += "\n" pokemon_go_info += "Hatches from: `{}km Egg` ".format(pokemon["hatches_from"]) # Format the message formatted_message = ( "**#{id:03} {upper_name} - GEN {generation}**\n" "Weight: `{weight}kg` Height: `{height}m`\n" "Type: `{type}`\n" "**{genus} Pokémon**\n" "{pokemon_go}" "```\n{description}```" "**EVOLUTION**: {formatted_evolution}" ).format( upper_name=pokemon["locale_name"].upper(), type=format_type(pokemon["types"]), formatted_evolution=" **->** ".join(" **/** ".join(pokedex[name]["locale_name"].upper() for name in names) for names in pokemon["evolution"]), pokemon_go=pokemon_go_info, **pokemon ) yield from client.say(message, formatted_message)
async def pokedex_(message: discord.Message, name_or_id: Annotate.LowerCleanContent): """ Display some information of the given pokémon. **Examples**: <http://imgur.com/a/lqG9c> """ # Do some quick replacements for flexible parsing name_or_id = name_or_id.strip() if name_or_id.startswith("#"): name_or_id = name_or_id.replace("#", "") if " " in name_or_id: if "♀" in name_or_id or "♀" in name_or_id or name_or_id.endswith( "f") or name_or_id.endswith("m"): name_or_id = name_or_id.replace(" ", "-").replace("♂", "m").replace( "♀", "f") else: name_or_id = name_or_id.replace(" ", "") # Get the name of the specified pokemon name = get_pokemon(name_or_id) # Assign our pokemon pokemon = pokedex[name] # Send an image if the bots has Attach Files permission or the message is a dm if message.guild is None or message.channel.permissions_for( message.guild.me).attach_files: # Get the guild's scale factor if not isinstance(message.channel, discord.abc.PrivateChannel) \ and message.guild.id in pokedex_config.data and "scale-factor" in pokedex_config.data[message.guild.id]: scale_factor = pokedex_config.data[ message.guild.id]["scale-factor"] else: scale_factor = default_scale_factor # Assign our pokemon pokemon = pokedex[name] # Assign the sprite to use if pokemon["id"] in sprites: sprite = sprites[pokemon["id"]] else: sprite = sprites[0] # Resize (if PIL is enabled) and upload the sprite if resize and not round(scale_factor, 2) == 1: sprite = resize_sprite(sprite, scale_factor) elif resize: sprite = BytesIO(sprite) await client.send_file(message.channel, sprite, filename="{}.png".format(name)) # Format Pokemon GO specific info pokemon_go_info = "" if "evolution_cost" in pokemon: pokemon_go_info += "Evolution cost: `{} {} Candy` ".format( pokemon["evolution_cost"], egg_name(pokemon["evolution"])) if "hatches_from" in pokemon: if pokemon_go_info: pokemon_go_info += "\n" pokemon_go_info += "Hatches from: `{}km Egg` ".format( pokemon["hatches_from"]) # Format the message formatted_message = ("**#{id:03} {upper_name} - GEN {generation}**\n" "Weight: `{weight}kg` Height: `{height}m`\n" "Type: `{type}`\n" "**{genus} Pokémon**\n" "{pokemon_go}" "```\n{description}```" "**EVOLUTION**: {formatted_evolution}").format( upper_name=pokemon["locale_name"].upper(), type=format_type(*pokemon["types"]), formatted_evolution=" **->** ".join( " **/** ".join( pokedex[name]["locale_name"].upper() for name in names) for names in pokemon["evolution"]), pokemon_go=pokemon_go_info, **pokemon) await client.say(message, formatted_message)
async def pokedex_(message: discord.Message, name_or_id: Annotate.LowerCleanContent): """ Display some information of the given pokémon. **Examples**: <http://imgur.com/a/lqG9c> """ # Do some quick replacements for flexible parsing name_or_id = name_or_id.strip() if name_or_id.startswith("#"): name_or_id = name_or_id.replace("#", "") if " " in name_or_id: if "♀" in name_or_id or "♀" in name_or_id or name_or_id.endswith( "f") or name_or_id.endswith("m"): name_or_id = name_or_id.replace(" ", "-").replace("♂", "m").replace( "♀", "f") else: name_or_id = name_or_id.replace(" ", "") # Get the requested pokemon name name = name_or_id try: pokemon_id = int(name_or_id) except ValueError: # See if there's a pokemon with the locale name formatted like the given name for pokemon in pokedex.values(): if pokemon["locale_name"].lower() == name: name = pokemon["name"] break # Correct the name if it is very close to an existing pokemon and there's only one close match matches = get_close_matches(name, pokedex.keys(), n=2, cutoff=0.8) if matches and len(matches) == 1: name = matches[0] assert name in pokedex, "There is no pokémon called **{}** in my pokédex!\nPerhaps you meant: `{}`?".format( name, ", ".join(get_close_matches(name, pokedex.keys(), cutoff=0.5))) else: name = id_to_name(pokemon_id) assert name is not None, "There is no pokémon with ID **#{:03}** in my pokédex!".format( pokemon_id) # Get the server's scale factor if not message.channel.is_private \ and message.server.id in pokedex_config.data and "scale-factor" in pokedex_config.data[message.server.id]: scale_factor = pokedex_config.data[message.server.id]["scale-factor"] else: scale_factor = default_scale_factor # Assign our pokemon pokemon = pokedex[name] # Assign the sprite to use if pokemon["id"] in sprites: sprite = sprites[pokemon["id"]] else: sprite = sprites[0] # Resize (if PIL is enabled) and upload the sprite if resize and not round(scale_factor, 2) == 1: sprite = resize_sprite(sprite, scale_factor) elif resize: sprite = BytesIO(sprite) await client.send_file(message.channel, sprite, filename="{}.png".format(name)) # Format Pokemon GO specific info pokemon_go_info = "" if "evolution_cost" in pokemon: pokemon_go_info += "Evolution cost: `{} {} Candy` ".format( pokemon["evolution_cost"], egg_name(pokemon["evolution"])) if "hatches_from" in pokemon: if pokemon_go_info: pokemon_go_info += "\n" pokemon_go_info += "Hatches from: `{}km Egg` ".format( pokemon["hatches_from"]) # Format the message formatted_message = ("**#{id:03} {upper_name} - GEN {generation}**\n" "Weight: `{weight}kg` Height: `{height}m`\n" "Type: `{type}`\n" "**{genus} Pokémon**\n" "{pokemon_go}" "```\n{description}```" "**EVOLUTION**: {formatted_evolution}").format( upper_name=pokemon["locale_name"].upper(), type=format_type(pokemon["types"]), formatted_evolution=" **->** ".join( " **/** ".join( pokedex[name]["locale_name"].upper() for name in names) for names in pokemon["evolution"]), pokemon_go=pokemon_go_info, **pokemon) await client.say(message, formatted_message)