Ejemplo n.º 1
0
async def is_blacklisted(ctx):
    """Check command invocation context for blacklist triggers."""
    if ctx.guild is not None and ctx.guild.id in ctx.bot.cache.blacklist["global"]["guild"]:
        raise exceptions.BlacklistedGuild()
    elif ctx.channel.id in ctx.bot.cache.blacklist["global"]["channel"]:
        raise exceptions.BlacklistedChannel()
    elif ctx.author.id in ctx.bot.cache.blacklist["global"]["user"]:
        raise exceptions.BlacklistedUser()
    elif ctx.guild is not None and ctx.bot.cache.blacklist.get(str(ctx.guild.id)) is not None:
        if ctx.author.id in ctx.bot.cache.blacklist[str(ctx.guild.id)]["member"]:
            raise exceptions.BlacklistedMember()
        elif (
            ctx.command.qualified_name.lower()
            in ctx.bot.cache.blacklist[str(ctx.guild.id)]["command"]
        ):
            raise exceptions.BlacklistedCommand()
    return True
Ejemplo n.º 2
0
async def is_blacklisted(ctx):
    """Check command invocation context for blacklist triggers."""
    data = await ctx.bot.db.execute(
        """
        SELECT
        EXISTS (
            SELECT user_id FROM blacklisted_user WHERE user_id = %s
        ) AS global,
        EXISTS (
            SELECT guild_id FROM blacklisted_guild WHERE guild_id = %s
        ) AS guild,
        EXISTS (
            SELECT user_id FROM blacklisted_member WHERE user_id = %s AND guild_id = %s
        ) AS user,
        EXISTS (
            SELECT command_name FROM blacklisted_command WHERE command_name = %s AND guild_id = %s
        ) AS command,
        EXISTS (
            SELECT channel_id FROM blacklisted_channel WHERE channel_id = %s
        ) AS channel
        """,
        ctx.author.id,
        ctx.guild.id if ctx.guild is not None else None,
        ctx.author.id,
        ctx.guild.id if ctx.guild is not None else None,
        ctx.command.qualified_name,
        ctx.guild.id if ctx.guild is not None else None,
        ctx.channel.id,
        one_row=True,
    )

    if data[0]:
        raise exceptions.BlacklistedUser()
    if data[1]:
        raise exceptions.BlacklistedGuild()
    if data[2]:
        raise exceptions.BlacklistedMember()
    if data[3]:
        raise exceptions.BlacklistedCommand()
    if data[4]:
        raise exceptions.BlacklistedChannel()

    return True