diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index 82c77ab..95c5e4d 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -54,9 +54,9 @@ class DatabaseInterface(object): edit_ts = str(edit_ts) msg = Messages( - message.server.id, - message.channel.id, - message.id, + int(message.server.id), + int(message.channel.id), + int(message.id), message.content, json.dumps(get_message_author(message)), str(message.timestamp), @@ -91,9 +91,9 @@ class DatabaseInterface(object): async with threadpool(): with self.get_session() as session: msg = session.query(Messages) \ - .filter(Messages.guild_id == message.server.id) \ - .filter(Messages.channel_id == message.channel.id) \ - .filter(Messages.message_id == message.id).first() + .filter(Messages.guild_id == int(message.server.id)) \ + .filter(Messages.channel_id == int(message.channel.id)) \ + .filter(Messages.message_id == int(message.id)).first() if msg: session.delete(msg) session.commit() @@ -108,13 +108,13 @@ class DatabaseInterface(object): gui = session.query(Guilds).filter(Guilds.guild_id == guild.id).first() if not gui: gui = Guilds( - guild.id, + int(guild.id), guild.name, json.dumps(get_roles_list(guild.roles)), json.dumps(get_channels_list(guild.channels)), json.dumps(get_webhooks_list(server_webhooks)), json.dumps(get_emojis_list(guild.emojis)), - guild.owner_id, + int(guild.owner_id), guild.icon ) session.add(gui) @@ -124,7 +124,7 @@ class DatabaseInterface(object): gui.channels = json.dumps(get_channels_list(guild.channels)) gui.webhooks = json.dumps(get_webhooks_list(server_webhooks)) gui.emojis = json.dumps(get_emojis_list(guild.emojis)) - gui.owner_id = guild.owner_id + gui.owner_id = int(guild.owner_id) gui.icon = guild.icon session.commit() @@ -137,7 +137,7 @@ class DatabaseInterface(object): disguild = discord.utils.get(guilds, id=guild.guild_id) if not disguild: changed = True - dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.guild_id).all() + dbmsgs = session.query(Messages).filter(Messages.guild_id == int(guild.guild_id)).all() for msg in dbmsgs: session.delete(msg) session.delete(guild) @@ -147,9 +147,9 @@ class DatabaseInterface(object): async def remove_guild(self, guild): async with threadpool(): with self.get_session() as session: - gui = session.query(Guilds).filter(Guilds.guild_id == guild.id).first() + gui = session.query(Guilds).filter(Guilds.guild_id == int(guild.id)).first() if gui: - dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.id).all() + dbmsgs = session.query(Messages).filter(Messages.guild_id == int(guild.id)).all() for msg in dbmsgs: session.delete(msg) session.delete(gui) @@ -159,13 +159,13 @@ class DatabaseInterface(object): async with threadpool(): with self.get_session() as session: dbmember = session.query(GuildMembers) \ - .filter(GuildMembers.guild_id == member.server.id) \ - .filter(GuildMembers.user_id == member.id) \ - .order_by(GuildMembers.id).all() + .filter(GuildMembers.guild_id == int(member.server.id)) \ + .filter(GuildMembers.user_id == int(member.id)) \ + .order_by(int(GuildMembers.id)).all() if not dbmember: dbmember = GuildMembers( - member.server.id, - member.id, + int(member.server.id), + int(member.id), member.name, member.discriminator, member.nick, @@ -193,8 +193,8 @@ class DatabaseInterface(object): async with threadpool(): with self.get_session() as session: dbmember = session.query(GuildMembers) \ - .filter(GuildMembers.guild_id == server.id) \ - .filter(GuildMembers.user_id == user.id).first() + .filter(GuildMembers.guild_id == int(server.id)) \ + .filter(GuildMembers.user_id == int(user.id)).first() if dbmember: dbmember.banned = False session.commit() @@ -204,7 +204,7 @@ class DatabaseInterface(object): with self.get_session() as session: changed = False dbmembers = session.query(GuildMembers) \ - .filter(GuildMembers.guild_id == guild_id) \ + .filter(GuildMembers.guild_id == int(guild_id)) \ .filter(GuildMembers.active == True).all() for member in dbmembers: dismember = discord.utils.get(guild_members, id=member.user_id) @@ -220,16 +220,16 @@ class DatabaseInterface(object): changed = False for usr in guildbans: dbusr = session.query(GuildMembers) \ - .filter(GuildMembers.guild_id == guild_id) \ - .filter(GuildMembers.user_id == usr.id) \ + .filter(GuildMembers.guild_id == int(guild_id)) \ + .filter(GuildMembers.user_id == int(usr.id)) \ .filter(GuildMembers.active == False).first() changed = True if dbusr: dbusr.banned = True else: dbusr = GuildMembers( - guild_id, - usr.id, + int(guild_id), + int(usr.id), usr.name, usr.discriminator, None, @@ -248,26 +248,26 @@ class DatabaseInterface(object): dbuser = None if discriminator: dbuser = session.query(UnauthenticatedUsers) \ - .filter(UnauthenticatedUsers.guild_id == guild_id) \ + .filter(UnauthenticatedUsers.guild_id == int(guild_id)) \ .filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \ .filter(UnauthenticatedUsers.discriminator == discriminator) \ .order_by(UnauthenticatedUsers.id.desc()).first() else: dbuser = session.query(UnauthenticatedUsers) \ - .filter(UnauthenticatedUsers.guild_id == guild_id) \ + .filter(UnauthenticatedUsers.guild_id == int(guild_id)) \ .filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \ .order_by(UnauthenticatedUsers.id.desc()).first() if not dbuser: return "Ban error! Guest user cannot be found." dbban = session.query(UnauthenticatedBans) \ - .filter(UnauthenticatedBans.guild_id == guild_id) \ + .filter(UnauthenticatedBans.guild_id == int(guild_id)) \ .filter(UnauthenticatedBans.last_username == dbuser.username) \ .filter(UnauthenticatedBans.last_discriminator == dbuser.discriminator).first() if dbban is not None: if dbban.lifter_id is None: return "Ban error! Guest user, **{}#{}**, has already been banned.".format(dbban.last_username, dbban.last_discriminator) session.delete(dbban) - dbban = UnauthenticatedBans(guild_id, dbuser.ip_address, dbuser.username, dbuser.discriminator, "", placer_id) + dbban = UnauthenticatedBans(int(guild_id), dbuser.ip_address, dbuser.username, dbuser.discriminator, "", int(placer_id)) session.add(dbban) session.commit() return "Guest user, **{}#{}**, has successfully been added to the ban list!".format(dbban.last_username, dbban.last_discriminator) @@ -278,13 +278,13 @@ class DatabaseInterface(object): dbuser = None if discriminator: dbuser = session.query(UnauthenticatedUsers) \ - .filter(UnauthenticatedUsers.guild_id == guild_id) \ + .filter(UnauthenticatedUsers.guild_id == int(guild_id)) \ .filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \ .filter(UnauthenticatedUsers.discriminator == discriminator) \ .order_by(UnauthenticatedUsers.id.desc()).first() else: dbuser = session.query(UnauthenticatedUsers) \ - .filter(UnauthenticatedUsers.guild_id == guild_id) \ + .filter(UnauthenticatedUsers.guild_id == int(guild_id)) \ .filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \ .order_by(UnauthenticatedUsers.id.desc()).first() if not dbuser: @@ -298,5 +298,5 @@ class DatabaseInterface(object): async def delete_all_messages_from_channel(self, channel_id): async with threadpool(): with self.get_session() as session: - session.query(Messages).filter(Messages.channel_id == channel_id).delete() + session.query(Messages).filter(Messages.channel_id == int(channel_id)).delete() session.commit() \ No newline at end of file diff --git a/discordbot/titanembeds/database/guild_members.py b/discordbot/titanembeds/database/guild_members.py index 28d5532..2b4494e 100644 --- a/discordbot/titanembeds/database/guild_members.py +++ b/discordbot/titanembeds/database/guild_members.py @@ -3,8 +3,8 @@ from titanembeds.database import db, Base class GuildMembers(Base): __tablename__ = "guild_members" id = db.Column(db.Integer, primary_key=True) # Auto incremented id - guild_id = db.Column(db.String(255)) # Discord guild id - user_id = db.Column(db.String(255)) # Discord user id + guild_id = db.Column(db.BigInteger) # Discord guild id + user_id = db.Column(db.BigInteger) # Discord user id username = db.Column(db.String(255)) # Name discriminator = db.Column(db.Integer) # User discriminator nickname = db.Column(db.String(255)) # User nickname diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py index 80ed764..1ad8de9 100644 --- a/discordbot/titanembeds/database/guilds.py +++ b/discordbot/titanembeds/database/guilds.py @@ -2,8 +2,7 @@ from titanembeds.database import db, Base class Guilds(Base): __tablename__ = "guilds" - id = db.Column(db.Integer, primary_key=True) # Auto incremented id - guild_id = db.Column(db.String(255)) # Discord guild id + guild_id = db.Column(db.BigInteger, primary_key=True # Discord guild id name = db.Column(db.String(255)) # Name unauth_users = db.Column(db.Boolean()) # If allowed unauth users visitor_view = db.Column(db.Boolean()) # If users are automatically "signed in" and can view chat @@ -17,7 +16,7 @@ class Guilds(Base): channels = db.Column(db.Text().with_variant(db.Text(length=4294967295), 'mysql'))# Guild channels webhooks = db.Column(db.Text().with_variant(db.Text(length=4294967295), 'mysql'))# Guild webhooks emojis = db.Column(db.Text().with_variant(db.Text(length=4294967295), 'mysql')) # Guild Emojis - owner_id = db.Column(db.String(255)) # Snowflake of the owner + owner_id = db.Column(db.BigInteger # 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 diff --git a/discordbot/titanembeds/database/messages.py b/discordbot/titanembeds/database/messages.py index b758ace..91b469a 100644 --- a/discordbot/titanembeds/database/messages.py +++ b/discordbot/titanembeds/database/messages.py @@ -2,10 +2,9 @@ from titanembeds.database import db, Base class Messages(Base): __tablename__ = "messages" - id = db.Column(db.Integer, primary_key=True) # Auto incremented id - guild_id = db.Column(db.String(255)) # Discord guild id - channel_id = db.Column(db.String(255)) # Channel id - message_id = db.Column(db.String(255)) # Message snowflake + message_id = db.Column(db.BigInteger, primary_key=True) # Message snowflake + guild_id = db.Column(db.BigInteger) # Discord guild id + channel_id = db.Column(db.BigInteger) # Channel id content = db.Column(db.Text()) # Message contents author = db.Column(db.Text()) # Author json timestamp = db.Column(db.TIMESTAMP) # Timestamp of when content is created diff --git a/discordbot/titanembeds/database/unauthenticated_bans.py b/discordbot/titanembeds/database/unauthenticated_bans.py index b68e8c2..5acd51d 100644 --- a/discordbot/titanembeds/database/unauthenticated_bans.py +++ b/discordbot/titanembeds/database/unauthenticated_bans.py @@ -11,8 +11,8 @@ class UnauthenticatedBans(Base): last_discriminator = db.Column(db.Integer) # The discrim when they got banned timestamp = db.Column(db.TIMESTAMP) # 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)) # 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) # 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 diff --git a/discordbot/titanembeds/database/unauthenticated_users.py b/discordbot/titanembeds/database/unauthenticated_users.py index 931b118..03966bb 100644 --- a/discordbot/titanembeds/database/unauthenticated_users.py +++ b/discordbot/titanembeds/database/unauthenticated_users.py @@ -7,7 +7,7 @@ import string class UnauthenticatedUsers(Base): __tablename__ = "unauthenticated_users" id = db.Column(db.Integer, primary_key=True) # Auto increment id - guild_id = db.Column(db.String(255)) # Guild pretaining to the unauthenticated user + guild_id = db.Column(db.BigInteger) # Guild pretaining to the unauthenticated user username = db.Column(db.String(255)) # The username of the user discriminator = db.Column(db.Integer) # The discriminator to distinguish unauth users with each other user_key = db.Column(db.Text()) # The secret key used to identify the user holder diff --git a/webapp/alembic/versions/dffebf852b41_updated_primary_keys_away_from_the_auto_.py b/webapp/alembic/versions/dffebf852b41_updated_primary_keys_away_from_the_auto_.py new file mode 100644 index 0000000..c096532 --- /dev/null +++ b/webapp/alembic/versions/dffebf852b41_updated_primary_keys_away_from_the_auto_.py @@ -0,0 +1,171 @@ +"""Updated Primary keys away from the auto increment and use bigints for ids + +Revision ID: dffebf852b41 +Revises: 5642232899cf +Create Date: 2018-01-23 19:32:40.846345 + +""" + +# revision identifiers, used by Alembic. +revision = 'dffebf852b41' +down_revision = '5642232899cf' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.execute("ALTER TABLE administrators ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.drop_column('administrators', 'id') + op.execute("ALTER TABLE administrators ADD PRIMARY KEY (user_id);") + op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id DROP DEFAULT") + op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id TYPE BIGINT USING client_id::bigint") + op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE cosmetics ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.drop_column('cosmetics', 'id') + op.execute("ALTER TABLE cosmetics ADD PRIMARY KEY (user_id);") + op.execute("ALTER TABLE disabled_guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.drop_column('disabled_guilds', 'id') + op.execute("ALTER TABLE disabled_guilds ADD PRIMARY KEY (guild_id);") + op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE guild_members ALTER COLUMN user_id DROP DEFAULT") + op.execute("ALTER TABLE guild_members ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.execute("ALTER TABLE guilds ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE guilds ALTER COLUMN owner_id DROP DEFAULT") + op.execute("ALTER TABLE guilds ALTER COLUMN owner_id TYPE BIGINT USING owner_id::bigint") + op.drop_column('guilds', 'id') + op.execute("ALTER TABLE guilds ADD PRIMARY KEY (guild_id);") + op.execute("ALTER TABLE messages ALTER COLUMN channel_id DROP DEFAULT") + op.execute("ALTER TABLE messages ALTER COLUMN channel_id TYPE BIGINT USING channel_id::bigint") + op.execute("ALTER TABLE messages ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE messages ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE messages ALTER COLUMN message_id DROP DEFAULT") + op.execute("ALTER TABLE messages ALTER COLUMN message_id TYPE BIGINT USING message_id::bigint") + op.drop_column('messages', 'id') + op.execute("ALTER TABLE messages ADD PRIMARY KEY (message_id);") + op.execute("ALTER TABLE patreon ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.drop_column('patreon', 'id') + op.execute("ALTER TABLE patreon ADD PRIMARY KEY (user_id);") + op.execute("ALTER TABLE titan_tokens ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.drop_column('titan_tokens', 'id') + op.execute("ALTER TABLE titan_tokens ADD PRIMARY KEY (user_id);") + op.execute("ALTER TABLE token_transactions ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN lifter_id TYPE BIGINT USING lifter_id::bigint") + op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id DROP DEFAULT") + op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id TYPE BIGINT USING placer_id::bigint") + op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id DROP DEFAULT") + op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") + op.execute("ALTER TABLE user_css ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('user_css', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False) + op.alter_column('unauthenticated_users', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('unauthenticated_bans', 'placer_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('unauthenticated_bans', 'lifter_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=True) + op.alter_column('unauthenticated_bans', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('token_transactions', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False) + op.add_column('titan_tokens', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('titan_tokens', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False) + op.add_column('patreon', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('patreon', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False) + op.add_column('messages', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('messages', 'message_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('messages', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('messages', 'channel_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.add_column('guilds', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('guilds', 'owner_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('guilds', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('guild_members', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('guild_members', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.add_column('disabled_guilds', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('disabled_guilds', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False) + op.add_column('cosmetics', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('cosmetics', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False) + op.alter_column('authenticated_users', 'guild_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.alter_column('authenticated_users', 'client_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + existing_nullable=False, + existing_server_default=sa.text("''::character varying")) + op.add_column('administrators', sa.Column('id', sa.INTEGER(), nullable=False)) + op.alter_column('administrators', 'user_id', + existing_type=sa.BigInteger(), + type_=sa.VARCHAR(length=255), + autoincrement=False) + # ### end Alembic commands ### diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index a9fa7a2..33c4fac 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -448,7 +448,7 @@ def user_info(guild_id, user_id): } member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.user_id == user_id).first() if member: - usr["id"] = member.user_id + usr["id"] = str(member.user_id) usr["username"] = member.username usr["nickname"] = member.nickname usr["discriminator"] = member.discriminator diff --git a/webapp/titanembeds/blueprints/gateway/gateway.py b/webapp/titanembeds/blueprints/gateway/gateway.py index 9532d35..4bcf237 100644 --- a/webapp/titanembeds/blueprints/gateway/gateway.py +++ b/webapp/titanembeds/blueprints/gateway/gateway.py @@ -32,14 +32,14 @@ class Gateway(Namespace): if session.get("unauthenticated", True) and guild_id in session.get("user_keys", {}): join_room("IP_"+get_client_ipaddr()) elif not session.get("unauthenticated", True): - join_room("USER_"+session["user_id"]) + join_room("USER_"+str(session["user_id"])) visitor_mode = data["visitor_mode"] if not visitor_mode: if session["unauthenticated"]: emit("embed_user_connect", {"unauthenticated": True, "username": session["username"], "discriminator": session["user_id"]}, room="GUILD_"+guild_id) else: nickname = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.user_id == session["user_id"]).first().nickname - emit("embed_user_connect", {"unauthenticated": False, "id": session["user_id"], "nickname": nickname, "username": session["username"],"discriminator": session["discriminator"], "avatar_url": session["avatar"]}, room="GUILD_"+guild_id) + emit("embed_user_connect", {"unauthenticated": False, "id": str(session["user_id"]), "nickname": nickname, "username": session["username"],"discriminator": session["discriminator"], "avatar_url": session["avatar"]}, room="GUILD_"+guild_id) emit("identified") self.teardown_db_session() @@ -51,7 +51,7 @@ class Gateway(Namespace): if session["unauthenticated"]: msg = {"unauthenticated": True, "username": session["username"], "discriminator": session["user_id"]} else: - msg = {"unauthenticated": False, "id": session["user_id"]} + msg = {"unauthenticated": False, "id": str(session["user_id"])} emit("embed_user_disconnect", msg, room="GUILD_"+guild_id) if guild_webhooks_enabled(guild_id): # Delete webhooks dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() @@ -111,7 +111,7 @@ class Gateway(Namespace): 'username': dbMember.username, 'nickname': dbMember.nickname, 'discriminator': dbMember.discriminator, - 'user_id': session['user_id'], + 'user_id': str(session['user_id']), } emit("current_user_info", usr) self.teardown_db_session() @@ -157,7 +157,7 @@ class Gateway(Namespace): } member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.username == name, GuildMembers.discriminator == discriminator).first() if member: - usr["id"] = member.user_id + usr["id"] = str(member.user_id) usr["username"] = member.username usr["nickname"] = member.nickname usr["avatar"] = member.avatar @@ -169,7 +169,7 @@ class Gateway(Namespace): else: member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.nickname == name, GuildMembers.discriminator == discriminator).first() if member: - usr["id"] = member.user_id + usr["id"] = str(member.user_id) usr["username"] = member.username usr["nickname"] = member.nickname usr["avatar"] = member.avatar diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py index 1fa66a1..1b1e97c 100644 --- a/webapp/titanembeds/blueprints/user/user.py +++ b/webapp/titanembeds/blueprints/user/user.py @@ -41,7 +41,7 @@ def callback(): session['unauthenticated'] = False session.permanent = True user = get_current_authenticated_user() - session['user_id'] = user['id'] + session['user_id'] = int(user['id']) session['username'] = user['username'] session['discriminator'] = user['discriminator'] session['avatar'] = generate_avatar_url(user['id'], user['avatar'], user['discriminator']) diff --git a/webapp/titanembeds/database/administrators.py b/webapp/titanembeds/database/administrators.py index 41cf3a5..8deebf0 100644 --- a/webapp/titanembeds/database/administrators.py +++ b/webapp/titanembeds/database/administrators.py @@ -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() diff --git a/webapp/titanembeds/database/authenticated_users.py b/webapp/titanembeds/database/authenticated_users.py index 01b0df3..1556f83 100644 --- a/webapp/titanembeds/database/authenticated_users.py +++ b/webapp/titanembeds/database/authenticated_users.py @@ -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 diff --git a/webapp/titanembeds/database/cosmetics.py b/webapp/titanembeds/database/cosmetics.py index 21b149a..b7890fc 100644 --- a/webapp/titanembeds/database/cosmetics.py +++ b/webapp/titanembeds/database/cosmetics.py @@ -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 diff --git a/webapp/titanembeds/database/disabled_guilds.py b/webapp/titanembeds/database/disabled_guilds.py index 18e5caf..b60b201 100644 --- a/webapp/titanembeds/database/disabled_guilds.py +++ b/webapp/titanembeds/database/disabled_guilds.py @@ -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 diff --git a/webapp/titanembeds/database/guild_members.py b/webapp/titanembeds/database/guild_members.py index 1f735a1..0c262b8 100644 --- a/webapp/titanembeds/database/guild_members.py +++ b/webapp/titanembeds/database/guild_members.py @@ -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 diff --git a/webapp/titanembeds/database/guilds.py b/webapp/titanembeds/database/guilds.py index 8957f16..8e35fb5 100644 --- a/webapp/titanembeds/database/guilds.py +++ b/webapp/titanembeds/database/guilds.py @@ -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 diff --git a/webapp/titanembeds/database/messages.py b/webapp/titanembeds/database/messages.py index abc58dc..2f44d78 100644 --- a/webapp/titanembeds/database/messages.py +++ b/webapp/titanembeds/database/messages.py @@ -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), } diff --git a/webapp/titanembeds/database/patreon.py b/webapp/titanembeds/database/patreon.py index 64b61ab..da28bb0 100644 --- a/webapp/titanembeds/database/patreon.py +++ b/webapp/titanembeds/database/patreon.py @@ -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): diff --git a/webapp/titanembeds/database/titan_tokens.py b/webapp/titanembeds/database/titan_tokens.py index 3ea2bff..55835c2 100644 --- a/webapp/titanembeds/database/titan_tokens.py +++ b/webapp/titanembeds/database/titan_tokens.py @@ -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): diff --git a/webapp/titanembeds/database/token_transactions.py b/webapp/titanembeds/database/token_transactions.py index 7f184f5..108f88b 100644 --- a/webapp/titanembeds/database/token_transactions.py +++ b/webapp/titanembeds/database/token_transactions.py @@ -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 diff --git a/webapp/titanembeds/database/unauthenticated_bans.py b/webapp/titanembeds/database/unauthenticated_bans.py index 7160f41..1510ae2 100644 --- a/webapp/titanembeds/database/unauthenticated_bans.py +++ b/webapp/titanembeds/database/unauthenticated_bans.py @@ -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 diff --git a/webapp/titanembeds/database/unauthenticated_users.py b/webapp/titanembeds/database/unauthenticated_users.py index 6989d66..a425c61 100644 --- a/webapp/titanembeds/database/unauthenticated_users.py +++ b/webapp/titanembeds/database/unauthenticated_users.py @@ -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 diff --git a/webapp/titanembeds/database/user_css.py b/webapp/titanembeds/database/user_css.py index ce7cf7a..d471612 100644 --- a/webapp/titanembeds/database/user_css.py +++ b/webapp/titanembeds/database/user_css.py @@ -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 diff --git a/webapp/titanembeds/utils.py b/webapp/titanembeds/utils.py index 7ba62fc..0f4ab74 100644 --- a/webapp/titanembeds/utils.py +++ b/webapp/titanembeds/utils.py @@ -130,7 +130,7 @@ def update_user_status(guild_id, username, user_key=None): 'nickname': None, 'user_key': user_key, 'guild_id': guild_id, - 'user_id': session['user_id'], + 'user_id': str(session['user_id']), 'banned': checkUserBanned(guild_id, ip_address), 'revoked': checkUserRevoke(guild_id, user_key), } @@ -151,7 +151,7 @@ def update_user_status(guild_id, username, user_key=None): 'nickname': None, 'discriminator': session['discriminator'], 'guild_id': guild_id, - 'user_id': session['user_id'], + 'user_id': str(session['user_id']), 'banned': checkUserBanned(guild_id), 'revoked': checkUserRevoke(guild_id) }