pokedex.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:pcbot 作者: pckv 项目源码 文件源码
def filter_type(message: discord.Message, slot_1: str.lower, slot_2: str.lower=None):
    matched_pokemon = []
    assert_type(slot_1, message.server)

    # Find all pokemon with the matched criteria
    if slot_2:
        assert_type(slot_2, message.server)

        # If two slots are provided, search for pokemon with both types matching
        for pokemon in pokedex.values():
            if pokemon["types"] == [slot_1, slot_2]:
                matched_pokemon.append(pokemon["locale_name"])
    else:
        # All pokemon have a type in their first slot, so check if these are equal
        for pokemon in pokedex.values():
            if pokemon["types"][0] == slot_1:
                matched_pokemon.append(pokemon["locale_name"])

    # There might not be any pokemon with the specified types
    assert matched_pokemon, "Looks like there are no pokemon of type **{}**!".format(format_type(slot_1, slot_2))

    await client.say(message, "**Pokemon with type {}**: ```\n{}```".format(
        format_type(slot_1, slot_2), ", ".join(sorted(matched_pokemon))))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号