Example #1
0
async def flavortext(ctx, *query):
    """Display a card's flavortext"""

    async with ctx.typing():
        cards = await card_data.get()
    results = card_data.find(cards, query)
    if not results:
        raise CardNotFoundError(query)
    else:
        result = results[0]
        embed = discord.Embed.from_dict(card_data.flavor_embed(result))
        await ctx.send(embed=embed)
Example #2
0
async def voice(ctx, *query):
    async with ctx.typing():
        cards = await card_data.get()

    results = card_data.find(cards, query)
    if not results:
        raise CardNotFoundError(query)
    result = results[0]

    async with ctx.typing():
        embed = await card_voice.svgdb_embed(result)

    await ctx.send(embed=discord.Embed.from_dict(embed))
Example #3
0
async def art_gen(ctx, query: list, which: str):
    """Helper function for art commands"""

    async with ctx.typing():
        cards = await card_data.get()

    results = card_data.find(cards, query)
    if not results:
        raise CardNotFoundError(query)
    result = results[0]
    card_id = result["card_id"]
    card_name = card_data.effective_card_name(result)

    async with ctx.typing():
        image = await card_art.get_asset(card_id, which)

    if image is None:
        raise CardArtError(card_id, card_name)
    else:
        await ctx.send(card_name, file=discord.File(image, "0.png"))
Example #4
0
async def cards(ctx, *query):
    """List all matching cards.

    Keyword search is supported. Examples:
    - search 6pp shadow gold spell
    - search earth sigil
    - search havencraft "repair mode"
    - search legendary "steel rebellion"

    """

    async with ctx.typing():
        cards = await card_data.get()
    results = card_data.find(cards, query)
    if not results:
        raise CardNotFoundError(query)
    else:
        max_results = 20
        if len(results) <= max_results:
            lines = [f"Found {len(results)} cards:"]
            lines += [card_data.effective_card_name(card) for card in results]
            await ctx.send("\n".join(lines))
        else:
            lo = 0
            hi = max_results
            lines = [f"Found {len(results)} cards, displaying {lo+1}-{hi}:"]
            lines += [
                card_data.effective_card_name(card) for card in results[lo:hi]
            ]
            msg = await ctx.send("\n".join(lines))
            await msg.add_reaction("⬅️")
            await msg.add_reaction("➡️")

            def check(reaction, user):
                return (user != bot.user and reaction.message.id == msg.id
                        and reaction.emoji in ["➡️", "⬅️"])

            while True:
                try:
                    reaction, usr = await bot.wait_for("reaction_add",
                                                       timeout=30.0,
                                                       check=check)
                except asyncio.TimeoutError:
                    await msg.remove_reaction("➡️", bot.user)
                    await msg.remove_reaction("⬅️", bot.user)
                    break
                else:
                    if reaction.emoji == "➡️":
                        hi = min(len(results), hi + max_results)
                        lo = hi - max_results
                    elif reaction.emoji == "⬅️":
                        lo = max(0, lo - max_results)
                        hi = lo + max_results

                    lines = [
                        f"Found {len(results)} cards, displaying {lo+1}-{hi}:"
                    ]
                    lines += [
                        card_data.effective_card_name(card)
                        for card in results[lo:hi]
                    ]
                    await msg.edit(content="\n".join(lines))
Example #5
0
async def cards(ctx, *query):
    """List all matching cards.

    Keyword search is supported. Examples:
    - search 6pp shadow gold spell
    - search earth sigil
    - search havencraft "repair mode"
    - search legendary "steel rebellion"

    """

    async with ctx.typing():
        cards = await card_data.get()
    results = card_data.find(cards, query)
    if not results:
        raise CardNotFoundError(query)
    else:
        counter = 0
        max_results = 20
        lines = [f"Found {len(results)} cards:"]
        lines += [
            card_data.effective_card_name(card)
            for card in results[:max_results]
        ]
        lines += [
            f"(displaying {counter*max_results+1}-{min(len(results), counter*max_results+max_results)} of {len(results)})"
        ]

        msg = await ctx.send("\n".join(lines))

        if len(results) > max_results:
            await msg.add_reaction("➡️")

            def check(reaction, user):
                return (user != bot.user and reaction.message.id == msg.id
                        and (str(reaction.emoji) == "➡️"
                             or str(reaction.emoji) == "⬅️"))

            max_counter = int(len(results) / max_results)
            if len(results) % max_results == 0:
                max_counter -= 1

            while True:
                try:
                    Reaction, usr = await bot.wait_for("reaction_add",
                                                       timeout=30.0,
                                                       check=check)
                    # prevReact = discord.Reaction
                except asyncio.TimeoutError:
                    await msg.clear_reaction("➡️")
                    await msg.clear_reaction("⬅️")
                    break
                else:
                    if Reaction.emoji == "➡️":
                        counter += 1
                        lines = [
                            card_data.effective_card_name(card)
                            for card in results[counter * max_results:counter *
                                                max_results + max_results]
                        ]
                        lines += [
                            f"(displaying {counter*max_results+1}-{min(len(results), counter*max_results+max_results)} of {len(results)})"
                        ]
                        if len(lines) > 0:
                            await msg.edit(content="\n".join(lines))

                        if counter > 0:
                            await msg.add_reaction("⬅️")

                        if counter >= max_counter:
                            await msg.clear_reaction("➡️")

                    elif Reaction.emoji == "⬅️":
                        counter -= 1
                        lines = [
                            card_data.effective_card_name(card)
                            for card in results[counter * max_results:counter *
                                                max_results + max_results]
                        ]

                        if (counter * max_results + max_results < len(results)
                                and len(results[counter * max_results +
                                                max_results:]) > 0):
                            await msg.add_reaction("➡️")

                        if counter >= 0:
                            lines += [
                                f"(displaying {counter*max_results+1}-{min(len(results), counter*max_results+max_results)} of {len(results)})"
                            ]
                            await msg.edit(content="\n".join(lines))

                        if counter == 0:
                            await msg.clear_reaction("⬅️")
def find(cards, query):
    return [
        card_data.effective_card_name(card)
        for card in card_data.find(cards, query.split())
    ]