Update cleanup db messages to message id

This commit is contained in:
Jeremy "EndenDragon" Zhang 2018-03-02 19:59:40 -08:00 committed by GitHub
parent a0edd06d36
commit d438b6d34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,7 @@ class Titan(discord.Client):
count = 0 count = 0
for guild in guilds: for guild in guilds:
count += 1 count += 1
print("[{}] id-{} snowflake-{} name-{}".format(count, guild.id, guild.guild_id, guild.name)) print("[{}] snowflake-{} name-{}".format(count, guild.guild_id, guild.name))
try: try:
channelsjson = json.loads(guild.channels) channelsjson = json.loads(guild.channels)
except: except:
@ -85,8 +85,8 @@ class Titan(discord.Client):
for channel in channelsjson: for channel in channelsjson:
chanid = channel["id"] chanid = channel["id"]
active_channels.append(chanid) active_channels.append(chanid)
keep_these = session.query(Messages.id).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).limit(50) keep_these = session.query(Messages.message_id).filter(Messages.channel_id == chanid).order_by(Messages.timestamp.desc()).limit(50)
d = session.query(Messages).filter(Messages.channel_id == chanid, ~Messages.id.in_(keep_these)).delete(synchronize_session=False) d = session.query(Messages).filter(Messages.channel_id == chanid, ~Messages.message_id.in_(keep_these)).delete(synchronize_session=False)
session.commit() session.commit()
print(" --{} [{}]".format(channel["name"], d)) print(" --{} [{}]".format(channel["name"], d))
d = session.query(Messages).filter(Messages.guild_id == guild.guild_id, ~Messages.channel_id.in_(active_channels)).delete(synchronize_session=False) d = session.query(Messages).filter(Messages.guild_id == guild.guild_id, ~Messages.channel_id.in_(active_channels)).delete(synchronize_session=False)