Ejemplo n.º 1
0
async def egg(message: discord.Message, egg_type: Annotate.LowerCleanContent):
    """ Get the pokemon hatched from the specified egg_type
    (in distance, e.g. 2 or 5km) """
    # Strip any km suffix (or prefix, whatever)
    egg_type = egg_type.replace("km", "")

    try:
        distance = int(
            float(egg_type))  # Using float for anyone willing to type 2.0km
    except ValueError:
        await client.say(message,
                         "The egg type **{}** is invalid.".format(egg_type))
        return

    pokemon_criteria = []
    egg_types = []

    # Find all pokemon with the specified distance
    for pokemon in sorted(pokedex.values(), key=itemgetter("id")):
        # We've exceeded the generation and no longer need to search
        if pokemon["generation"] not in pokemon_go_gen:
            break

        if "hatches_from" not in pokemon:
            continue

        if pokemon["hatches_from"] not in egg_types:
            egg_types.append(pokemon["hatches_from"])

        if pokemon["hatches_from"] == distance:
            pokemon_criteria.append(pokemon["locale_name"])

    # The list might be empty
    assert pokemon_criteria, "No pokemon hatch from a **{}km** egg. **Valid distances are** ```\n{}```".format(
        distance, ", ".join("{}km".format(s) for s in sorted(egg_types)))

    # Respond with the list of matching criteria
    await client.say(
        message,
        "**The following Pokémon may hatch from a {}km egg**:```\n{}```".
        format(distance, ", ".join(sorted(pokemon_criteria))))
Ejemplo n.º 2
0
def egg(client: discord.Client, message: discord.Message, egg_type: Annotate.LowerCleanContent):
    """ Get the pokemon hatched from the specified egg_type
    (in distance, e.g. 2 or 5km) """
    # Strip any km suffix (or prefix, whatever)
    egg_type = egg_type.replace("km", "")

    try:
        distance = int(float(egg_type))  # Using float for anyone willing to type 2.0km
    except ValueError:
        yield from client.say(message, "The egg type **{}** is invalid.".format(egg_type))
        return

    pokemon_criteria = []
    egg_types = []

    # Find all pokemon with the specified distance
    for pokemon in sorted(pokedex.values(), key=itemgetter("id")):
        # We've exceeded the generation and no longer need to search
        if pokemon["generation"] not in pokemon_go_gen:
            break

        if "hatches_from" not in pokemon:
            continue

        if pokemon["hatches_from"] not in egg_types:
            egg_types.append(pokemon["hatches_from"])

        if pokemon["hatches_from"] == distance:
            pokemon_criteria.append(pokemon["locale_name"])

    # The list might be empty
    assert pokemon_criteria, "No pokemon hatch from a **{}km** egg. **Valid distances are** ```\n{}```".format(
        distance, ", ".join("{}km".format(s) for s in sorted(egg_types)))

    # Respond with the list of matching criteria
    yield from client.say(message, "**The following Pokémon may hatch from a {}km egg**:```\n{}```".format(
        distance, ", ".join(sorted(pokemon_criteria))))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)