mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-04 15:57:02 +01:00 
			
		
		
		
	Use a more optimal primary key and integer to store snowflakes
This commit is contained in:
		@@ -2,8 +2,7 @@ from titanembeds.database import db
 | 
			
		||||
 | 
			
		||||
class Administrators(db.Model):
 | 
			
		||||
    __tablename__ = "administrators"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord user id of user of an administrator
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False, primary_key=True)             # Discord user id of user of an administrator
 | 
			
		||||
 | 
			
		||||
def get_administrators_list():
 | 
			
		||||
    q = db.session.query(Administrators).all()
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,8 @@ import time
 | 
			
		||||
class AuthenticatedUsers(db.Model):
 | 
			
		||||
    __tablename__ = "authenticated_users"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Guild pretaining to the authenticated user
 | 
			
		||||
    client_id = db.Column(db.String(255), nullable=False)           # Client ID of the authenticated user
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False)            # Guild pretaining to the authenticated user
 | 
			
		||||
    client_id = db.Column(db.BigInteger, nullable=False)           # Client ID of the authenticated user
 | 
			
		||||
 | 
			
		||||
    def __init__(self, guild_id, client_id):
 | 
			
		||||
        self.guild_id = guild_id
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,7 @@ import json
 | 
			
		||||
 | 
			
		||||
class Cosmetics(db.Model):
 | 
			
		||||
    __tablename__ = "cosmetics"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord user id of user of cosmetics
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False, primary_key=True)             # Discord user id of user of cosmetics
 | 
			
		||||
    css = db.Column(db.Boolean(), nullable=False)                   # If they can create/edit custom CSS
 | 
			
		||||
    css_limit = db.Column(db.Integer, nullable=False, server_default="0") # Custom CSS Limit
 | 
			
		||||
    guest_icon = db.Column(db.Boolean(), nullable=False, server_default=db.false()) # If they can set the guest icon for all guilds
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
from titanembeds.database import db
 | 
			
		||||
 | 
			
		||||
class DisabledGuilds(db.Model):
 | 
			
		||||
    __tablename__ = "disabled_guilds"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Server id that is disabled
 | 
			
		||||
    __tablename__ = "disabled_guilds"                  # Auto increment id
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False, primary_key=True)            # Server id that is disabled
 | 
			
		||||
    
 | 
			
		||||
    def __init__(self, guild_id):
 | 
			
		||||
        self.guild_id = guild_id
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,8 @@ import json
 | 
			
		||||
class GuildMembers(db.Model):
 | 
			
		||||
    __tablename__ = "guild_members"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto incremented id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Discord guild id
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord user id
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False)            # Discord guild id
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False)             # Discord user id
 | 
			
		||||
    username = db.Column(db.String(255), nullable=False)            # Name
 | 
			
		||||
    discriminator = db.Column(db.Integer, nullable=False)           # User discriminator
 | 
			
		||||
    nickname = db.Column(db.String(255))                            # User nickname
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,7 @@ from titanembeds.database import db
 | 
			
		||||
 | 
			
		||||
class Guilds(db.Model):
 | 
			
		||||
    __tablename__ = "guilds"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                                # Auto incremented id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)                        # Discord guild id
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False, primary_key=True)       # Discord guild id
 | 
			
		||||
    name = db.Column(db.String(255), nullable=False)                            # Name
 | 
			
		||||
    unauth_users = db.Column(db.Boolean(), nullable=False, default=1)           # If allowed unauth users
 | 
			
		||||
    visitor_view = db.Column(db.Boolean(), nullable=False, default=0)           # If users are automatically "signed in" and can view chat
 | 
			
		||||
@@ -17,7 +16,7 @@ class Guilds(db.Model):
 | 
			
		||||
    channels = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False)                   # Guild channels
 | 
			
		||||
    webhooks = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False)                   # Guild webhooks
 | 
			
		||||
    emojis = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False)                     # Guild Emojis
 | 
			
		||||
    owner_id = db.Column(db.String(255), nullable=False)                        # Snowflake of the owner
 | 
			
		||||
    owner_id = db.Column(db.BigInteger, nullable=False)                        # Snowflake of the owner
 | 
			
		||||
    icon = db.Column(db.String(255))                                            # The icon string, null if none
 | 
			
		||||
    invite_link = db.Column(db.String(255))                                     # Custom Discord Invite Link
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,10 +4,9 @@ import json
 | 
			
		||||
 | 
			
		||||
class Messages(db.Model):
 | 
			
		||||
    __tablename__ = "messages"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto incremented id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Discord guild id
 | 
			
		||||
    channel_id = db.Column(db.String(255), nullable=False)          # Channel id
 | 
			
		||||
    message_id = db.Column(db.String(255), nullable=False)          # Message snowflake
 | 
			
		||||
    message_id = db.Column(db.BigInteger, nullable=False, primary_key=True) # Message snowflake
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False)            # Discord guild id
 | 
			
		||||
    channel_id = db.Column(db.BigInteger, nullable=False)          # Channel id
 | 
			
		||||
    content = db.Column(db.Text(), nullable=False)                  # Message contents
 | 
			
		||||
    author = db.Column(db.Text(), nullable=False)                   # Author
 | 
			
		||||
    timestamp = db.Column(db.TIMESTAMP, nullable=False)             # Timestamp of when content is created
 | 
			
		||||
@@ -35,7 +34,7 @@ def get_channel_messages(guild_id, channel_id, after_snowflake=None):
 | 
			
		||||
    if not after_snowflake:
 | 
			
		||||
        q = db.session.query(Messages).filter(Messages.channel_id == channel_id).order_by(Messages.timestamp.desc()).limit(50)
 | 
			
		||||
    else:
 | 
			
		||||
        q = db.session.query(Messages).filter(cast(Messages.channel_id, db.BigInteger) == int(channel_id)).filter(cast(Messages.message_id, db.BigInteger) > after_snowflake).order_by(Messages.timestamp.desc()).limit(50)
 | 
			
		||||
        q = db.session.query(Messages).filter(Messages.channel_id == channel_id).filter(Messages.message_id > after_snowflake).order_by(Messages.timestamp.desc()).limit(50)
 | 
			
		||||
    msgs = []
 | 
			
		||||
    snowflakes = []
 | 
			
		||||
    for x in q:
 | 
			
		||||
@@ -48,11 +47,11 @@ def get_channel_messages(guild_id, channel_id, after_snowflake=None):
 | 
			
		||||
        message = {
 | 
			
		||||
            "attachments": json.loads(x.attachments),
 | 
			
		||||
            "timestamp": x.timestamp,
 | 
			
		||||
            "id": x.message_id,
 | 
			
		||||
            "id": str(x.message_id),
 | 
			
		||||
            "edited_timestamp": x.edited_timestamp,
 | 
			
		||||
            "author": json.loads(x.author),
 | 
			
		||||
            "content": x.content,
 | 
			
		||||
            "channel_id": x.channel_id,
 | 
			
		||||
            "channel_id": str(x.channel_id),
 | 
			
		||||
            "mentions": json.loads(x.mentions),
 | 
			
		||||
            "embeds": json.loads(embeds),
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,7 @@ from titanembeds.database import db
 | 
			
		||||
 | 
			
		||||
class Patreon(db.Model):
 | 
			
		||||
    __tablename__ = "patreon"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False) # User ID from patreon
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False, primary_key=True) # User ID from patreon
 | 
			
		||||
    total_synced = db.Column(db.Integer, nullable=False) # Total cents synced on our end
 | 
			
		||||
    
 | 
			
		||||
    def __init__(self, user_id, total_synced=0):
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,7 @@ from titanembeds.database import db
 | 
			
		||||
 | 
			
		||||
class TitanTokens(db.Model):
 | 
			
		||||
    __tablename__ = "titan_tokens"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord user id of user
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False, primary_key=True)             # Discord user id of user
 | 
			
		||||
    tokens = db.Column(db.Integer, nullable=False, default=0)       # Token amount
 | 
			
		||||
    
 | 
			
		||||
    def __init__(self, user_id, tokens):
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import time
 | 
			
		||||
class TokenTransactions(db.Model):
 | 
			
		||||
    __tablename__ = "token_transactions"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord user id of user
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False)             # Discord user id of user
 | 
			
		||||
    timestamp = db.Column(db.TIMESTAMP, nullable=False)             # The timestamp of when the action took place
 | 
			
		||||
    action = db.Column(db.String(255), nullable=False)              # Very short description of the action
 | 
			
		||||
    net_tokens = db.Column(db.Integer, nullable=False)              # Net change of the token amount
 | 
			
		||||
 
 | 
			
		||||
@@ -5,14 +5,14 @@ import time
 | 
			
		||||
class UnauthenticatedBans(db.Model):
 | 
			
		||||
    __tablename__ = "unauthenticated_bans"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Guild pretaining to the unauthenticated user
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False)            # Guild pretaining to the unauthenticated user
 | 
			
		||||
    ip_address = db.Column(db.String(255), nullable=False)          # The IP Address of the user
 | 
			
		||||
    last_username = db.Column(db.String(255), nullable=False)       # The username when they got banned
 | 
			
		||||
    last_discriminator = db.Column(db.Integer, nullable=False)      # The discrim when they got banned
 | 
			
		||||
    timestamp = db.Column(db.TIMESTAMP, nullable=False)             # The timestamp of when the user got banned
 | 
			
		||||
    reason = db.Column(db.Text())                                   # The reason of the ban set by the guild moderators
 | 
			
		||||
    lifter_id = db.Column(db.String(255))                           # Discord Client ID of the user who lifted the ban
 | 
			
		||||
    placer_id = db.Column(db.String(255), nullable=False)           # The id of who placed the ban
 | 
			
		||||
    lifter_id = db.Column(db.BigInteger)                           # Discord Client ID of the user who lifted the ban
 | 
			
		||||
    placer_id = db.Column(db.BigInteger, nullable=False)           # The id of who placed the ban
 | 
			
		||||
 | 
			
		||||
    def __init__(self, guild_id, ip_address, last_username, last_discriminator, reason, placer_id):
 | 
			
		||||
        self.guild_id = guild_id
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ import string
 | 
			
		||||
class UnauthenticatedUsers(db.Model):
 | 
			
		||||
    __tablename__ = "unauthenticated_users"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True, nullable=False)    # Auto increment id
 | 
			
		||||
    guild_id = db.Column(db.String(255), nullable=False)            # Guild pretaining to the unauthenticated user
 | 
			
		||||
    guild_id = db.Column(db.BigInteger, nullable=False)            # Guild pretaining to the unauthenticated user
 | 
			
		||||
    username = db.Column(db.String(255), nullable=False)            # The username of the user
 | 
			
		||||
    discriminator = db.Column(db.Integer, nullable=False)           # The discriminator to distinguish unauth users with each other
 | 
			
		||||
    user_key = db.Column(db.Text(), nullable=False)                 # The secret key used to identify the user holder
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ class UserCSS(db.Model):
 | 
			
		||||
    __tablename__ = "user_css"
 | 
			
		||||
    id = db.Column(db.Integer, primary_key=True)                    # Auto increment id
 | 
			
		||||
    name = db.Column(db.String(255), nullable=False)                # CSS Name
 | 
			
		||||
    user_id = db.Column(db.String(255), nullable=False)             # Discord client ID of the owner of the css (can edit)
 | 
			
		||||
    user_id = db.Column(db.BigInteger, nullable=False)             # Discord client ID of the owner of the css (can edit)
 | 
			
		||||
    css_var_bool = db.Column(db.Boolean(), nullable=False, server_default="0") # If css variables should be taken into consideration
 | 
			
		||||
    css_variables = db.Column(db.Text()) # Customizeable CSS Variables
 | 
			
		||||
    css = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql')) # CSS contents
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user