From 495a08ea12ab6d864773dcb6b6a7642b30827d03 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Fri, 22 Sep 2017 01:33:55 +0000 Subject: [PATCH] Fixes to cleanup and fetch scripts --- discordbot/cleanup_db_messages.py | 2 +- discordbot/fetch_last_messages.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/discordbot/cleanup_db_messages.py b/discordbot/cleanup_db_messages.py index 5105ba3..c437cc9 100644 --- a/discordbot/cleanup_db_messages.py +++ b/discordbot/cleanup_db_messages.py @@ -89,7 +89,7 @@ class Titan(discord.Client): d = session.query(Messages).filter(Messages.channel_id == chanid, ~Messages.id.in_(keep_these)).delete(synchronize_session=False) session.commit() print(" --{} [{}]".format(channel["name"], d)) - d = session.query(Messages).filter(~Messages.channel_id.in_(active_channels)).delete(synchronize_session=False) + d = session.query(Messages).filter(Messages.guild_id == guild.id, ~Messages.channel_id.in_(active_channels)).delete(synchronize_session=False) session.commit() print(" INACTIVE {}".format(d)) print("done!") diff --git a/discordbot/fetch_last_messages.py b/discordbot/fetch_last_messages.py index 8aa7700..d2635f2 100644 --- a/discordbot/fetch_last_messages.py +++ b/discordbot/fetch_last_messages.py @@ -69,10 +69,13 @@ class Titan(discord.Client): print("working on this...") for channel in self.get_all_channels(): - if str(channel.type) == "text": - print("Processing channel: ID-{} Name-'{}' ServerID-{} Server-'{}'".format(channel.id, channel.name, channel.server.id, channel.server.name)) - async for message in self.logs_from(channel, limit=50, reverse=True): - await self.database.push_message(message) + try: + if str(channel.type) == "text": + print("Processing channel: ID-{} Name-'{}' ServerID-{} Server-'{}'".format(channel.id, channel.name, channel.server.id, channel.server.name)) + async for message in self.logs_from(channel, limit=50, reverse=True): + await self.database.push_message(message) + except: + continue print("done!") await self.logout()