From 377012cf4ad0bd7cb8a4b1383d00e4961a699b2a Mon Sep 17 00:00:00 2001 From: klemek Date: Thu, 7 Jan 2021 10:59:11 +0100 Subject: [PATCH] fixing log manager messages --- log_manager.py | 20 +++++++++++--------- utils.py | 4 ++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/log_manager.py b/log_manager.py index d5a4e21..d83895e 100644 --- a/log_manager.py +++ b/log_manager.py @@ -6,6 +6,8 @@ import gzip from datetime import datetime import logging +from utils import code_message + LOG_DIR = "logs" if not os.path.exists(LOG_DIR): @@ -154,12 +156,11 @@ class GuildLogs: async def load( self, progress: discord.Message, target_channels: List[discord.TextChannel] = [] ) -> Tuple[int, int]: + global current_analysis if self.log_file in current_analysis: return -1, -1 current_analysis += [self.log_file] - await progress.edit( - content=f"```Reading history...\n(this might take a while)```" - ) + await code_message(progress, "Reading history...\n(this might take a while)") # read logs t0 = datetime.now() if os.path.exists(self.log_file): @@ -205,15 +206,16 @@ class GuildLogs: "(some channels are new, this might take a long while)" ) dt = (datetime.now() - t0).total_seconds() - await progress.edit( - content=f"```Reading history...\n{tmp_msg} messages in {total_chan + 1}/{max_chan} channels ({round(tmp_msg/dt)}m/s)\n{warning_msg}```" + await code_message( + progress, + f"Reading history...\n{tmp_msg} messages in {total_chan + 1}/{max_chan} channels ({round(tmp_msg/dt)}m/s)\n{warning_msg}", ) if done: total_chan += 1 total_msg += len(self.channels[channel.id].messages) dt = (datetime.now() - t0).total_seconds() - await progress.edit( - content=f"```Saving...\n{total_msg} messages in {total_chan} channels```" + await code_message( + progress, f"Saving...\n{total_msg} messages in {total_chan} channels" ) logging.info(f"log {self.guild.id} > queried in {dt} s -> {total_msg / dt} m/s") # write logs @@ -222,8 +224,8 @@ class GuildLogs: f.write(gzip.compress(bytes(json.dumps(self.dict()), "utf-8"))) dt = (datetime.now() - t0).total_seconds() logging.info(f"log {self.guild.id} > written in {dt} s") - await progress.edit( - content=f"```Analysing...\n{total_msg} messages in {total_chan} channels```" + await code_message( + progress, f"Analysing...\n{total_msg} messages in {total_chan} channels" ) current_analysis.remove(self.log_file) return total_msg, total_chan diff --git a/utils.py b/utils.py index b56cfc9..41ffd89 100644 --- a/utils.py +++ b/utils.py @@ -9,6 +9,10 @@ def debug(message: discord.Message, txt: str): logging.info(f"{message.guild} > #{message.channel}: {txt}") +async def code_message(message: discord.Message, content: str): + await message.edit(content=f"```\n{content}\n```") + + # LISTS