コード例 #1
0
ファイル: lookuputils.py プロジェクト: leenephi/avrae
async def get_monster_choices(ctx, filter_by_license=True, homebrew=True):
    """
    Gets a list of monsters in the current context for the user to choose from.

    :param ctx: The context.
    :param filter_by_license: Whether to filter out entities the user cannot access.
    :param homebrew: Whether to include homebrew entities.
    """
    if filter_by_license:
        available_monsters = await available(ctx, compendium.monsters,
                                             'monster')
    else:
        available_monsters = compendium.monsters

    if not homebrew:
        return available_monsters

    # personal bestiary
    try:
        bestiary = await Bestiary.from_ctx(ctx)
        await bestiary.load_monsters(ctx)
        custom_monsters = bestiary.monsters
        bestiary_id = bestiary.id
    except NoActiveBrew:
        custom_monsters = []
        bestiary_id = None

    # server bestiaries
    choices = list(itertools.chain(available_monsters, custom_monsters))
    if ctx.guild:
        async for servbestiary in Bestiary.server_bestiaries(ctx):
            if servbestiary.id != bestiary_id:
                await servbestiary.load_monsters(ctx)
                choices.extend(servbestiary.monsters)
    return choices
コード例 #2
0
ファイル: homebrew.py プロジェクト: JulianGindi/avrae
 async def bestiary_server_list(self, ctx):
     """Shows what bestiaries are currently active on the server."""
     desc = []
     async for best in Bestiary.server_bestiaries(ctx):
         sharer = await best.get_server_sharer(ctx)
         desc.append(f"{best.name} (<@{sharer}>)")
     await ctx.send(embed=discord.Embed(title="Active Server Bestiaries", description="\n".join(desc)))
コード例 #3
0
ファイル: lookupFuncs.py プロジェクト: danielberes/avrae
async def select_monster_full(ctx, name, cutoff=5, return_key=False, pm=False, message=None, list_filter=None,
                              return_metadata=False):
    """
    Gets a Monster from the compendium and active bestiary/ies.
    """
    try:
        bestiary = await Bestiary.from_ctx(ctx)
        await bestiary.load_monsters(ctx)
        custom_monsters = bestiary.monsters
        bestiary_id = bestiary.id
    except NoActiveBrew:
        custom_monsters = []
        bestiary_id = None
    choices = list(itertools.chain(compendium.monster_mash, custom_monsters))
    if ctx.guild:
        async for servbestiary in Bestiary.server_bestiaries(ctx):
            if servbestiary.id == bestiary_id:
                continue
            await servbestiary.load_monsters(ctx)
            choices.extend(servbestiary.monsters)

    await Stats.increase_stat(ctx, "monsters_looked_up_life")

    def get_homebrew_formatted_name(monster):
        if monster.source == 'homebrew':
            return f"{monster.name} ({HOMEBREW_EMOJI})"
        return monster.name

    return await search_and_select(ctx, choices, name, lambda e: e.name, cutoff, return_key, pm, message, list_filter,
                                   selectkey=get_homebrew_formatted_name, return_metadata=return_metadata)
コード例 #4
0
 async def bestiary_server_list(self, ctx):
     """Shows what bestiaries are currently active on the server."""
     desc = []
     async for best in Bestiary.server_bestiaries(ctx):
         sharer = next(sh for sh in best.server_active
                       if sh['guild_id'] == str(ctx.guild.id))
         desc.append(f"{best.name} (<@{sharer['subscriber_id']}>)")
     await ctx.send(embed=discord.Embed(title="Active Server Bestiaries",
                                        description="\n".join(desc)))
コード例 #5
0
ファイル: homebrew.py プロジェクト: JulianGindi/avrae
    async def bestiary_server_remove(self, ctx, bestiary_name):
        """Removes a server bestiary."""
        bestiaries = []
        async for best in Bestiary.server_bestiaries(ctx):
            bestiaries.append(best)

        bestiary = await search_and_select(ctx, bestiaries, bestiary_name, lambda b: b.name)
        await bestiary.toggle_server_active(ctx)
        await ctx.send(f"Ok, {bestiary.name} is no longer active on {ctx.guild.name}.")