class Category(TableBase, table_name='trivia_categories'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt) guild_id_idx = asyncqlio.Index(guild_id) name = asyncqlio.Column(asyncqlio.String(256)) description = asyncqlio.Column(asyncqlio.String(512), nullable=True) # ---------Converter stuffs------------ _default_categories = {} @classmethod async def convert(cls, ctx, arg): lowered = arg.lower() with contextlib.suppress(KeyError): return cls._default_categories[lowered] query = ctx.session.select.from_(cls).where( (cls.guild_id == ctx.guild.id) & (cls.name == lowered)) result = await query.first() if result is None: raise commands.BadArgument( f"Category {lowered} doesn't exist... :(") return result
class Alias(_Table, table_name='command_aliases'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt, index=True) alias = asyncqlio.Column(asyncqlio.String(2000), index=True) command = asyncqlio.Column(asyncqlio.String(2000)) alias_idx = asyncqlio.Index(guild_id, alias, unique=True)
class Question(TableBase, table_name='trivia_questions'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) category_id = asyncqlio.Column(asyncqlio.Integer, foreign_key=asyncqlio.ForeignKey( Category.id)) category_id_idx = asyncqlio.Index(category_id) question = asyncqlio.Column(asyncqlio.String(1024)) answer = asyncqlio.Column(asyncqlio.String(512)) image = asyncqlio.Column(asyncqlio.String(512), nullable=True)
class Case(TableBase, table_name='modlog'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) channel_id = asyncqlio.Column(asyncqlio.BigInt) message_id = asyncqlio.Column(asyncqlio.BigInt) guild_id = asyncqlio.Column(asyncqlio.BigInt) modlog_guild_id_idx = asyncqlio.Index(guild_id) action = asyncqlio.Column(asyncqlio.String(16)) mod_id = asyncqlio.Column(asyncqlio.BigInt) reason = asyncqlio.Column(asyncqlio.String(1024)) # Can either be the duration, in the case of a mute or tempban, # or the role, in the case of a special role. extra = asyncqlio.Column(asyncqlio.Text, default='{}')
class Racehorse(TableBase, table_name='racehorses'): user_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) # For custom horses we're gonna support custom emojis here. # Custom emojis are in the format <:name:id> # The name has a maximum length of 32 characters, while the ID is at # most 21 digits long. Add that to the 2 colons and 2 angle brackets # for a total 57 characters. But we'll go with 64 just to play it safe. emoji = asyncqlio.Column(asyncqlio.String(64))
class Warn(TableBase, table_name='warn_entries'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt) user_id = asyncqlio.Column(asyncqlio.BigInt) mod_id = asyncqlio.Column(asyncqlio.BigInt) reason = asyncqlio.Column(asyncqlio.String(2000)) warned_at = asyncqlio.Column(asyncqlio.Timestamp)
class ServerMessage(TableBase, table_name='server_messages'): # Cannot use a auto-increment primary key because it f***s # with ON CONFLICT in a strange way. guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) is_welcome = asyncqlio.Column(asyncqlio.Boolean, primary_key=True) # When I make this per-channel I'll add a unique constraint to this later. channel_id = asyncqlio.Column(asyncqlio.BigInt, default=-1) message = asyncqlio.Column(asyncqlio.String(2000), default='', nullable=True) delete_after = asyncqlio.Column(asyncqlio.SmallInt, default=0) enabled = asyncqlio.Column(asyncqlio.Boolean, default=False)
class WarnPunishment(TableBase, table_name='warn_punishments'): guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) warns = asyncqlio.Column(asyncqlio.SmallInt, primary_key=True) type = asyncqlio.Column(asyncqlio.String(32)) duration = asyncqlio.Column(asyncqlio.Integer, default=0)
class Blacklist(_Table): snowflake = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) blacklisted_at = asyncqlio.Column(asyncqlio.Timestamp) reason = asyncqlio.Column(asyncqlio.String(2000), default='')