class DailyLog(TableBase): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) user_id = asyncqlio.Column(asyncqlio.BigInt) time = asyncqlio.Column(asyncqlio.Timestamp) # time_idx = asyncqlio.Index(time) amount = asyncqlio.Column(asyncqlio.BigInt)
class Plonks(_Table): guild_id = asyncqlio.Column(asyncqlio.BigInt, index=True, primary_key=True) # this can either be a channel_id or an author_id entity_id = asyncqlio.Column(asyncqlio.BigInt, index=True, primary_key=True)
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 _Schedule(_Table, table_name='schedule'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) expires = asyncqlio.Column(asyncqlio.Timestamp) schedule_expires_idx = asyncqlio.Index(expires) event = asyncqlio.Column(asyncqlio.String) created = asyncqlio.Column(asyncqlio.Timestamp) args_kwargs = asyncqlio.Column(dbtypes.JSON, default="'{}'::jsonb")
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 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 CommandPermissions(_Table, table_name='permissions'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt, index=True) permissions_guild_id_idx = asyncqlio.Index(guild_id) snowflake = asyncqlio.Column(asyncqlio.BigInt, nullable=True) name = asyncqlio.Column(asyncqlio.String) whitelist = asyncqlio.Column(asyncqlio.Boolean)
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 Tag(TableBase, table_name='tags'): name = asyncqlio.Column(asyncqlio.String, index=True, primary_key=True) # If this is an alias, this will be repurposed to point to the original tag. content = asyncqlio.Column(asyncqlio.String, default='') is_alias = asyncqlio.Column(asyncqlio.Boolean) # TODO: embed = asyncqlio.Column(asyncqlio.String, default='') # Some important metadata. owner_id = asyncqlio.Column(asyncqlio.BigInt) uses = asyncqlio.Column(asyncqlio.Integer, default=0) location_id = asyncqlio.Column(asyncqlio.BigInt, index=True, primary_key=True) created_at = asyncqlio.Column(asyncqlio.Timestamp)
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 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 ModLogConfig(TableBase, table_name='modlog_config'): guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) channel_id = asyncqlio.Column(asyncqlio.BigInt, default=0) # flags # XXX Should I store this as one integer and use bitwise? enabled = asyncqlio.Column(asyncqlio.Boolean, default=True) log_auto = asyncqlio.Column(asyncqlio.Boolean, default=True) dm_user = asyncqlio.Column(asyncqlio.Boolean, default=True) poll_audit_log = asyncqlio.Column(asyncqlio.Boolean, default=True) events = asyncqlio.Column(asyncqlio.Integer, default=_default_flags)
class MinesweeperGame(TableBase, table_name='minesweeper_games'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) level = asyncqlio.Column(asyncqlio.SmallInt) won = asyncqlio.Column(asyncqlio.Boolean) guild_id = asyncqlio.Column(asyncqlio.BigInt) user_id = asyncqlio.Column(asyncqlio.BigInt) played_at = asyncqlio.Column(asyncqlio.Timestamp) time = asyncqlio.Column(asyncqlio.Real) minesweeper_time_idx = asyncqlio.Index(time)
class Command(TableBase, table_name='commands'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt, index=True, nullable=True) commands_guild_id_idx = asyncqlio.Index(guild_id) channel_id = asyncqlio.Column(asyncqlio.BigInt) author_id = asyncqlio.Column(asyncqlio.BigInt, index=True) commands_author_id_idx = asyncqlio.Index(author_id) used = asyncqlio.Column(asyncqlio.Timestamp) prefix = asyncqlio.Column(asyncqlio.String) command = asyncqlio.Column(asyncqlio.String, index=True) commands_command_idx = asyncqlio.Index(command)
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 Currency(TableBase): user_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) amount = asyncqlio.Column(asyncqlio.Integer)
class MuteRole(TableBase, table_name='muted_roles'): guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) role_id = asyncqlio.Column(asyncqlio.BigInt)
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 SelfRoles(TableBase): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) guild_id = asyncqlio.Column(asyncqlio.BigInt) role_id = asyncqlio.Column(asyncqlio.BigInt, unique=True)
class CaseTarget(TableBase, table_name='modlog_targets'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) entry_id = asyncqlio.Column(asyncqlio.Integer, foreign_key=asyncqlio.ForeignKey(Case.id)) user_id = asyncqlio.Column(asyncqlio.BigInt)
class Blacklist(_Table): snowflake = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) blacklisted_at = asyncqlio.Column(asyncqlio.Timestamp) reason = asyncqlio.Column(asyncqlio.String(2000), default='')
class DailyCooldown(TableBase, table_name='daily_cash_cooldowns'): user_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) latest_time = asyncqlio.Column(asyncqlio.Timestamp)
class GiveEntry(TableBase, table_name='givelog'): id = asyncqlio.Column(asyncqlio.Serial, primary_key=True) giver = asyncqlio.Column(asyncqlio.BigInt) recipient = asyncqlio.Column(asyncqlio.BigInt) amount = asyncqlio.Column(asyncqlio.Integer) time = asyncqlio.Column(asyncqlio.Timestamp)
class WarnTimeout(TableBase, table_name='warn_timeouts'): guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) timeout = asyncqlio.Column(dbtypes.Interval)
class AutoRoles(TableBase): guild_id = asyncqlio.Column(asyncqlio.BigInt, primary_key=True) role_id = asyncqlio.Column(asyncqlio.BigInt)