Ejemplo n.º 1
0
Archivo: db.py Proyecto: bijij/BotBot
class OptInStatus(Table, schema="logging"):
    user_id: Column[SQLType.BigInt] = Column(primary_key=True, index=True)
    public: Column[bool] = Column(default=False)
    nsfw: Column[bool] = Column(default=False)

    @classmethod
    async def is_opted_in(cls, connection: asyncpg.Connection, ctx: Context):
        opt_in_status = await cls.fetch_row(connection, user_id=ctx.author.id)
        if opt_in_status is None:
            raise commands.BadArgument(
                f"You have not opted in to logging. You can do so with `{ctx.bot.prefix}logging start`"
            )

    @classmethod
    async def is_not_opted_in(cls, connection: asyncpg.Connection, ctx: Context):
        opt_in_status = await cls.fetch_row(connection, user_id=ctx.author.id)
        if opt_in_status is not None:
            raise commands.BadArgument("You have already opted into logging.")

    @classmethod
    async def is_public(cls, connection: asyncpg.Connection, ctx: Context, user: discord.User):
        opt_in_status = await cls.fetch_row(connection, user_id=user.id)
        if opt_in_status is None:
            if user == ctx.author:
                raise commands.BadArgument(
                    f"You have not opted in to logging. You can do so with `{ctx.bot.prefix}logging start`"
                )
            else:
                raise commands.BadArgument(f'User "{user}" has not opted in to logging.')

        if user != ctx.author and not opt_in_status["public"]:
            raise commands.BadArgument(f'User "{user}" has not made their logs public.')
Ejemplo n.º 2
0
class Timers(Table, schema='core'):  # type: ignore
    id: SQLType.Serial = Column(primary_key=True)
    created_at: SQLType.Timestamp = Column(
        default='NOW() AT TIME ZONE \'UTC\'')
    expires_at: SQLType.Timestamp = Column(index=True)
    event_type: str = Column(nullable=False, index=True)
    data: SQLType.JSONB = Column(default='\'{}\'::jsonb')
Ejemplo n.º 3
0
class Commands(Table, schema='core'):  # type: ignore
    message_id: SQLType.BigInt = Column(primary_key=True)
    guild_id: SQLType.BigInt = Column(index=True)
    channel_id: SQLType.BigInt
    user_id: SQLType.BigInt = Column(index=True)
    invoked_at: SQLType.Timestamp
    prefix: str
    command: str
    failed: bool
Ejemplo n.º 4
0
class Commands(Table, schema="logging"):  # type: ignore[call-arg]
    message_id: Column[SQLType.BigInt] = Column(primary_key=True)
    guild_id: Column[SQLType.BigInt] = Column(index=True)
    channel_id: Column[SQLType.BigInt] = Column(index=True)
    user_id: Column[SQLType.BigInt] = Column(index=True)
    invoked_at: Column[SQLType.Timestamp]
    prefix: Column[SQLType.Text]
    command: Column[SQLType.Text]
    failed: Column[SQLType.Boolean]
Ejemplo n.º 5
0
class TimeZones(Table, schema="core"):  # type: ignore[call-arg]
    user_id: Column[SQLType.BigInt] = Column(primary_key=True)
    time_zone: Column[SQLType.Text] = Column(nullable=False)

    @classmethod
    async def get_timezone(cls, connection: asyncpg.Connection, /,
                           user: User) -> Optional[zoneinfo.ZoneInfo]:
        record = await cls.fetch_row(connection, user_id=user.id)
        return zoneinfo.ZoneInfo(
            record["time_zone"]) if record is not None else None
Ejemplo n.º 6
0
class Opt_In_Status(Table, schema='logging'):  # type: ignore
    user_id: SQLType.BigInt = Column(primary_key=True, index=True)
    public: bool = Column(default=False)
    nsfw: bool = Column(default=False)

    @classmethod
    async def is_opted_in(cls,
                          ctx: Context,
                          *,
                          connection: asyncpg.Connection = None):
        opt_in_status = await cls.fetchrow(connection=connection,
                                           user_id=ctx.author.id)
        if opt_in_status is None:
            raise commands.BadArgument(
                f'You have not opted in to logging. You can do so with `{ctx.bot.prefix}logging start`'
            )

    @classmethod
    async def is_not_opted_in(cls,
                              ctx: Context,
                              *,
                              connection: asyncpg.Connection = None):
        opt_in_status = await cls.fetchrow(connection=connection,
                                           user_id=ctx.author.id)
        if opt_in_status is not None:
            raise commands.BadArgument('You have already opted into logging.')

    @classmethod
    async def is_public(cls,
                        ctx: Context,
                        user: discord.User,
                        *,
                        connection: asyncpg.Connection = None):
        opt_in_status = await cls.fetchrow(connection=connection,
                                           user_id=user.id)
        if opt_in_status is None:
            if user == ctx.author:
                raise commands.BadArgument(
                    f'You have not opted in to logging. You can do so with `{ctx.bot.prefix}logging start`'
                )
            else:
                raise commands.BadArgument(
                    f'User "{user}" has not opted in to logging.')

        if user != ctx.author and not opt_in_status['public']:
            raise commands.BadArgument(
                f'User "{user}" has not made their logs public.')
Ejemplo n.º 7
0
class Message_Log(Table, schema='logging'):  # type: ignore
    channel_id: SQLType.BigInt = Column(primary_key=True)
    message_id: SQLType.BigInt = Column(primary_key=True)
    guild_id: SQLType.BigInt = Column(index=True)
    user_id: SQLType.BigInt = Column(index=True)
    content: str
    nsfw: bool = Column(default=False)

    @classmethod
    async def get_user_log(cls,
                           user: discord.User,
                           nsfw: bool = False,
                           flatten_case: bool = False,
                           *,
                           connection: asyncpg.Connection = None) -> List[str]:
        data = await cls.fetch_where(
            'user_id = $1 AND nsfw <= $2 AND content LIKE \'% %\'',
            user.id,
            nsfw,
            connection=connection)
        return [
            record['content'].lower() if flatten_case else record['content']
            for record in data
        ]

    @classmethod
    async def get_guild_log(
            cls,
            guild: discord.Guild,
            nsfw: bool = False,
            flatten_case: bool = False,
            *,
            connection: asyncpg.Connection = None) -> List[str]:
        data = await cls.fetch_where(
            'guild_id = $1 AND nsfw <= $2 AND content LIKE \'% %\'',
            guild.id,
            nsfw,
            connection=connection)
        return [
            record['content'].lower() if flatten_case else record['content']
            for record in data
        ]
Ejemplo n.º 8
0
class _Commands(Table):
    id: SQLType.Serial = Column(primary_key=True, auto_increment=True)
    guild_id: SQLType.BigInt = Column(index=True)
    channel_id: SQLType.BigInt
    author_id: SQLType.BigInt = Column(index=True)
    used_at: SQLType.Timestamp = Column(index=True)
    prefix: str
    command: str = Column(index=True)
    failed: bool = Column(index=True)
Ejemplo n.º 9
0
Archivo: db.py Proyecto: bijij/BotBot
class MessageLog(Table, schema="logging"):
    channel_id: Column[SQLType.BigInt] = Column(primary_key=True)
    message_id: Column[SQLType.BigInt] = Column(primary_key=True, unique=True)
    guild_id: Column[SQLType.BigInt] = Column(index=True)
    user_id: Column[SQLType.BigInt] = Column(index=True)
    content: Column[str]
    nsfw: Column[bool] = Column(default=False)
    deleted: Column[bool] = Column(default=False)

    @classmethod
    async def get_user_log(
        cls,
        connection: asyncpg.Connection,
        user: discord.User,
        nsfw: bool = False,
        flatten_case: bool = False,
    ) -> list[str]:
        query = f"""
            SELECT * FROM (SELECT message_id, content, user_id, deleted, nsfw from {MessageLog._name}
            UNION SELECT b.message_id, b.content, a.user_id, a.deleted, a.nsfw from {MessageAttachments._name}  AS b
            INNER JOIN {MessageLog._name} AS a ON (a.message_id = b.message_id)
            ) _ WHERE deleted = false AND user_id = $1 AND nsfw <= $2 AND content LIKE '% %';
        """
        data = await connection.fetch(query, user.id, nsfw)
        return [record["content"].lower() if flatten_case else record["content"] for record in data]

    @classmethod
    async def get_guild_log(
        cls,
        connection: asyncpg.Connection,
        guild: discord.Guild,
        nsfw: bool = False,
        flatten_case: bool = False,
    ) -> list[str]:
        query = f"""
            SELECT * FROM (SELECT message_id, content, guild_id, deleted, nsfw from {MessageLog._name}
            UNION SELECT b.message_id, b.content, a.guild_id, a.deleted, a.nsfw from {MessageAttachments._name} AS b
            INNER JOIN {MessageLog._name} AS a ON (a.message_id = b.message_id)
            ) _ WHERE deleted = false AND guild_id = $1 AND nsfw <= $2 AND content LIKE '% %';
        """
        data = await connection.fetch(query, guild.id, nsfw)
        return [record["content"].lower() if flatten_case else record["content"] for record in data]
Ejemplo n.º 10
0
class VoiceWoesWhitelist(Table):
    user_id: Column[SQLType.BigInt] = Column(primary_key=True)
Ejemplo n.º 11
0
class Voice_Woes_Whitelist(Table):
    user_id: SQLType.BigInt = Column(primary_key=True)
Ejemplo n.º 12
0
class Ranking(Table, schema="connect_four"):
    user_id: SQLType.BigInt = Column(primary_key=True)
    ranking: SQLType.Integer = Column(default='1000')
    games: SQLType.Integer = Column(default='0')
    wins: SQLType.Integer = Column(default='0')
    losses: SQLType.Integer = Column(default='0')
Ejemplo n.º 13
0
class Games(Table, schema="connect_four"):
    game_id: SQLType.Serial = Column(primary_key=True)
    players: [SQLType.BigInt]  # type: ignore
    winner: SQLType.SmallInt
    finished: SQLType.Boolean
Ejemplo n.º 14
0
class Voice_Log_Configuration(Table, schema="logging"):  # type: ignore
    guild_id: SQLType.BigInt = Column(primary_key=True)
    log_channel_id: SQLType.BigInt
    display_hidden_channels: bool = Column(default=True)
Ejemplo n.º 15
0
class UserEmoji(Table, schema="core"):  # type: ignore[call-arg]
    emoji_id: Column[SQLType.BigInt] = Column(primary_key=True,
                                              references=Emoji.emoji_id,
                                              cascade=True)
    user_id: Column[SQLType.BigInt] = Column(index=True, unique=True)
Ejemplo n.º 16
0
class ChannelWhitelist(Table):
    channel_id: Column[SQLType.BigInt] = Column(primary_key=True)
    user_id: Column[SQLType.BigInt] = Column(primary_key=True)
Ejemplo n.º 17
0
Archivo: db.py Proyecto: bijij/BotBot
class MessageAttachments(Table, schema="logging"):
    message_id: Column[SQLType.BigInt] = Column(primary_key=True, references=MessageLog.message_id)
    attachment_id: Column[SQLType.BigInt]
    content: Column[str]
Ejemplo n.º 18
0
Archivo: spam.py Proyecto: bijij/BotBot
class SpamChecker(Table, schema="moderation"):
    guild_id: Column[SQLType.BigInt] = Column(primary_key=True)
    max_mentions: Column[int]
Ejemplo n.º 19
0
class Games(Table, schema="connect_four"):
    game_id: Column[SQLType.Serial] = Column(primary_key=True)
    players: Column[list[SQLType.BigInt]]
    winner: Column[SQLType.SmallInt]
    finished: Column[SQLType.Boolean]
Ejemplo n.º 20
0
class VoiceLogConfiguration(Table, schema="logging"):
    guild_id: Column[SQLType.BigInt] = Column(primary_key=True)
    log_channel_id: Column[SQLType.BigInt]
    display_hidden_channels: Column[bool] = Column(default=True)
Ejemplo n.º 21
0
class Timezones(Table, schema='logging'):  # type: ignore
    user_id: SQLType.BigInt = Column(primary_key=True, index=True)
    timezone: str = Column(nullable=False)
Ejemplo n.º 22
0
Archivo: db.py Proyecto: bijij/BotBot
class StatusLog(Table, schema="logging"):
    user_id: Column[SQLType.BigInt] = Column(primary_key=True, index=True)
    timestamp: Column[SQLType.Timestamp] = Column(primary_key=True)
    status: Column[_Status]
Ejemplo n.º 23
0
Archivo: db.py Proyecto: bijij/BotBot
class MessageEditHistory(Table, schema="logging"):
    message_id: Column[SQLType.BigInt] = Column(primary_key=True, references=MessageLog.message_id)
    created_at: Column[SQLType.Timestamp] = Column(primary_key=True)
    content: Column[str]
Ejemplo n.º 24
0
class Status_Log(Table, schema='logging'):  # type: ignore
    user_id: SQLType.BigInt = Column(primary_key=True, index=True)
    timestamp: datetime.datetime = Column(primary_key=True)
    status: Status  # type: ignore
Ejemplo n.º 25
0
class Events(Table, schema="core"):  # type: ignore[call-arg]
    id: Column[SQLType.Serial] = Column(primary_key=True)
    created_at: Column[SQLType.Timestamp] = Column(default="NOW()")
    scheduled_for: Column[SQLType.Timestamp] = Column(index=True)
    event_type: Column[SQLType.Text] = Column(nullable=False, index=True)
    data: Column[SQLType.JSONB] = Column(default="'{}'::jsonb")
Ejemplo n.º 26
0
class _Timers(Table):
    id: int = Column(primary_key=True, auto_increment=True)
    created_at: datetime.datetime = Column(nullable=False, default='NOW()')
    expires_at: datetime.datetime = Column(nullable=False, index=True)
    event_type: str = Column(nullable=False)
    data: dict = Column(nullable=False, default={})
Ejemplo n.º 27
0
class Emoji(Table, schema="core"):  # type: ignore[call-arg]
    emoji_id: Column[SQLType.BigInt] = Column(primary_key=True)
    guild_id: Column[SQLType.BigInt] = Column(index=True, nullable=False)
    last_fetched: Column[SQLType.Timestamp] = Column(default="NOW()")
Ejemplo n.º 28
0
class Ranking(Table, schema="connect_four"):
    user_id: Column[SQLType.BigInt] = Column(primary_key=True)
    ranking: Column[SQLType.Integer] = Column(default="1000")
    games: Column[SQLType.Integer] = Column(default="0")
    wins: Column[SQLType.Integer] = Column(default="0")
    losses: Column[SQLType.Integer] = Column(default="0")
Ejemplo n.º 29
0
class Spam_Checker(Table, schema='moderation'):  # type: ignore
    guild_id: SQLType.BigInt = Column(primary_key=True)
    max_mentions: int