From d438b6d34fd91b27cd02a54bf76f40310cd72cb3 Mon Sep 17 00:00:00 2001 From: "Jeremy \"EndenDragon\" Zhang" Date: Fri, 2 Mar 2018 19:59:40 -0800 Subject: [PATCH] Update cleanup db messages to message id --- discordbot/cleanup_db_messages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discordbot/cleanup_db_messages.py b/discordbot/cleanup_db_messages.py index c4f1d5e..fe2a89c 100644 --- a/discordbot/cleanup_db_messages.py +++ b/discordbot/cleanup_db_messages.py @@ -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() \ No newline at end of file + main()