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
for guild in guilds:
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:
channelsjson = json.loads(guild.channels)
except:
@ -85,8 +85,8 @@ class Titan(discord.Client):
for channel in channelsjson:
chanid = channel["id"]
active_channels.append(chanid)
keep_these = session.query(Messages.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)
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.message_id.in_(keep_these)).delete(synchronize_session=False)
session.commit()
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)
@ -102,4 +102,4 @@ def main():
gc.collect()
if __name__ == '__main__':
main()
main()