Exemplo n.º 1
0
async def handle_alias_required_licenses(ctx, err):
    embed = EmbedWithAuthor(ctx)
    if not err.has_connected_ddb:
        # was the user blocked from nSRD by a feature flag?
        ddb_user = await ctx.bot.ddb.get_ddb_user(ctx, ctx.author.id)
        if ddb_user is None:
            blocked_by_ff = False
        else:
            blocked_by_ff = not (await ctx.bot.ldclient.variation(
                "entitlements-enabled", ddb_user.to_ld_dict(), False))

        if blocked_by_ff:
            embed.title = "D&D Beyond is currently unavailable"
            embed.description = f"I was unable to communicate with D&D Beyond to confirm access to:\n" \
                                f"{', '.join(e.name for e in err.entities)}"
        else:
            embed.title = f"Connect your D&D Beyond account to use this customization!"
            embed.url = "https://www.dndbeyond.com/account"
            embed.description = \
                "This customization requires access to one or more entities that are not in the SRD.\n" \
                "Linking your account means that you'll be able to use everything you own on " \
                "D&D Beyond in Avrae for free - you can link your accounts " \
                "[here](https://www.dndbeyond.com/account)."
            embed.set_footer(
                text=
                "Already linked your account? It may take up to a minute for Avrae to recognize the "
                "link.")
    else:
        missing_source_ids = {e.source for e in err.entities}
        if len(err.entities) == 1:  # 1 entity, display entity piecemeal
            embed.title = f"Purchase {err.entities[0].name} on D&D Beyond to use this customization!"
            marketplace_url = err.entities[0].marketplace_url
        elif len(missing_source_ids
                 ) == 1:  # 1 source, recommend purchasing source
            missing_source = next(iter(missing_source_ids))
            embed.title = f"Purchase {long_source_name(missing_source)} on D&D Beyond to use this customization!"
            marketplace_url = f"https://www.dndbeyond.com/marketplace?utm_source=avrae&utm_medium=marketplacelink"
        else:  # more than 1 source
            embed.title = f"Purchase {len(missing_source_ids)} sources on D&D Beyond to use this customization!"
            marketplace_url = "https://www.dndbeyond.com/marketplace?utm_source=avrae&utm_medium=marketplacelink"

        missing = natural_join(
            [f"[{e.name}]({e.marketplace_url})" for e in err.entities], "and")
        if len(missing) > 1400:
            missing = f"{len(err.entities)} items"
        missing_sources = natural_join(
            [long_source_name(e) for e in missing_source_ids], "and")

        embed.description = \
            f"To use this customization and gain access to more integrations in Avrae, unlock **{missing}** by " \
            f"purchasing {missing_sources} on D&D Beyond.\n\n" \
            f"[Go to Marketplace]({marketplace_url})"
        embed.url = marketplace_url

        embed.set_footer(
            text=
            "Already purchased? It may take up to a minute for Avrae to recognize the "
            "purchase.")
    await ctx.send(embed=embed)
Exemplo n.º 2
0
async def handle_required_license(ctx, err):
    """
    Logs a unlicensed search and displays a prompt.

    :type ctx: discord.ext.commands.Context
    :type err: cogs5e.models.errors.RequiresLicense
    """
    result = err.entity

    await ctx.bot.mdb.analytics_nsrd_lookup.update_one(
        {
            "type": result.entity_type,
            "name": result.name
        }, {"$inc": {
            "num_lookups": 1
        }},
        upsert=True)

    embed = EmbedWithAuthor(ctx)
    if not err.has_connected_ddb:
        # was the user blocked from nSRD by a feature flag?
        ddb_user = await ctx.bot.ddb.get_ddb_user(ctx, ctx.author.id)
        if ddb_user is None:
            blocked_by_ff = False
        else:
            blocked_by_ff = not (await ctx.bot.ldclient.variation(
                "entitlements-enabled", ddb_user.to_ld_dict(), False))

        if blocked_by_ff:
            # get the message from feature flag
            # replacements:
            # $entity_type$, $entity_name$, $source$, $long_source$
            unavailable_title = await ctx.bot.ldclient.variation(
                "entitlements-disabled-header", ddb_user.to_ld_dict(),
                f"{result.name} is not available")
            unavailable_desc = await ctx.bot.ldclient.variation(
                "entitlements-disabled-message", ddb_user.to_ld_dict(),
                f"{result.name} is currently unavailable")

            embed.title = unavailable_title \
                .replace('$entity_type$', result.entity_type) \
                .replace('$entity_name$', result.name) \
                .replace('$source$', result.source) \
                .replace('$long_source$', long_source_name(result.source))
            embed.description = unavailable_desc \
                .replace('$entity_type$', result.entity_type) \
                .replace('$entity_name$', result.name) \
                .replace('$source$', result.source) \
                .replace('$long_source$', long_source_name(result.source))
        else:
            embed.title = f"Connect your D&D Beyond account to view {result.name}!"
            embed.url = "https://www.dndbeyond.com/account"
            embed.description = \
                "It looks like you don't have your Discord account connected to your D&D Beyond account!\n" \
                "Linking your account means that you'll be able to use everything you own on " \
                "D&D Beyond in Avrae for free - you can link your accounts " \
                "[here](https://www.dndbeyond.com/account)."
            embed.set_footer(
                text=
                "Already linked your account? It may take up to a minute for Avrae to recognize the "
                "link.")
    else:
        embed.title = f"Purchase {result.name} on D&D Beyond to view it here!"
        embed.description = \
            f"To see and search this {result.entity_type}'s full details, unlock **{result.name}** by " \
            f"purchasing {long_source_name(result.source)} on D&D Beyond.\n\n" \
            f"[Go to Marketplace]({result.marketplace_url})"
        embed.url = result.marketplace_url

        embed.set_footer(
            text=
            "Already purchased? It may take up to a minute for Avrae to recognize the "
            "purchase.")
    await ctx.send(embed=embed)