From 3e781c746f65fb774008e2d754b0a15d08805727 Mon Sep 17 00:00:00 2001 From: Klemek Date: Tue, 16 Mar 2021 16:00:20 +0100 Subject: [PATCH] fix bug for forbidden channel --- src/logs/channel_logs.py | 1 + src/logs/guild_logs.py | 2 +- src/scanners/scanner.py | 58 ++++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/logs/channel_logs.py b/src/logs/channel_logs.py index 75c103e..6b0e352 100644 --- a/src/logs/channel_logs.py +++ b/src/logs/channel_logs.py @@ -70,6 +70,7 @@ class ChannelLogs: yield len(self.messages), False self.last_message_id = channel.last_message_id except discord.errors.HTTPException: + yield -1, True return # When an exception occurs (like Forbidden) yield len(self.messages), True diff --git a/src/logs/guild_logs.py b/src/logs/guild_logs.py index 5250a62..795c12f 100644 --- a/src/logs/guild_logs.py +++ b/src/logs/guild_logs.py @@ -154,7 +154,7 @@ class GuildLogs: workers += [Worker(self.channels[channel.id], channel)] warning_msg = "(this might take a while)" if len(target_channels) > 5 and loading_new > 5: - warning_msg = "(most channels are new, this might take a looong while)" + warning_msg = "(most channels are new, this will take a long while)" elif loading_new > 0: warning_msg = "(some channels are new, this might take a long while)" await code_message( diff --git a/src/scanners/scanner.py b/src/scanners/scanner.py index f1fb14e..079217b 100644 --- a/src/scanners/scanner.py +++ b/src/scanners/scanner.py @@ -123,38 +123,44 @@ class Scanner(ABC): self.msg_count += count self.chan_count += 1 if count > 0 else 0 logging.info(f"scan {guild.id} > scanned in {delta(t0):,}ms") - await progress.edit(content="```Computing results...```") - # Display results - t0 = datetime.now() - results = self.get_results( - get_intro( - self.intro_context, - self.full, - self.channels, - self.members, - self.msg_count, - self.chan_count, + if self.total_msg == 0: + await message.channel.send( + "There are no messages found matching the filters", + reference=message, ) - ) - logging.info(f"scan {guild.id} > results in {delta(t0):,}ms") - response = "" - first = True - for r in results: - if len(response + "\n" + r) > 2000: + else: + await progress.edit(content="```Computing results...```") + # Display results + t0 = datetime.now() + results = self.get_results( + get_intro( + self.intro_context, + self.full, + self.channels, + self.members, + self.msg_count, + self.chan_count, + ) + ) + logging.info(f"scan {guild.id} > results in {delta(t0):,}ms") + response = "" + first = True + for r in results: + if len(response + "\n" + r) > 2000: + await message.channel.send( + response, + reference=message if first else None, + allowed_mentions=discord.AllowedMentions.none(), + ) + first = False + response = "" + response += "\n" + r + if len(response) > 0: await message.channel.send( response, reference=message if first else None, allowed_mentions=discord.AllowedMentions.none(), ) - first = False - response = "" - response += "\n" + r - if len(response) > 0: - await message.channel.send( - response, - reference=message if first else None, - allowed_mentions=discord.AllowedMentions.none(), - ) # Delete custom progress message await progress.delete()