From 45538eec6f6a91c3955016f67e2b1fe38c46e530 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:56:57 +0200 Subject: [PATCH] logfilereader: Fix analysing every attachment (#44) * logfilereader: Fix analysing every attachment Now Ryuko will only analyse logs again * logfilereader: Stop analysing message.txt Most of the time these won't contain all the info we need anyway. * Apply black formatting --- robocop_ng/cogs/logfilereader.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/robocop_ng/cogs/logfilereader.py b/robocop_ng/cogs/logfilereader.py index ea59b76..c840005 100644 --- a/robocop_ng/cogs/logfilereader.py +++ b/robocop_ng/cogs/logfilereader.py @@ -25,8 +25,7 @@ class LogFileReader(Cog): @staticmethod def is_valid_log_name(attachment: Attachment) -> tuple[bool, bool]: filename = attachment.filename - # Any message over 2000 chars is uploaded as message.txt, so this is accounted for - ryujinx_log_file_regex = re.compile(r"^Ryujinx_.*\.log|message\.txt$") + ryujinx_log_file_regex = re.compile(r"^Ryujinx_.*\.log$") log_file = re.compile(r"^.*\.log|.*\.txt$") is_ryujinx_log_file = re.match(ryujinx_log_file_regex, filename) is not None is_log_file = re.match(log_file, filename) is not None @@ -832,19 +831,20 @@ class LogFileReader(Cog): self.uploaded_log_info = self.uploaded_log_info[-5:] # fmt: on return await reply_message.edit(content=None, embed=embed) - except UnicodeDecodeError: - return await message.channel.send( + except UnicodeDecodeError as error: + await reply_message.edit( content=author_mention, embed=Embed( description="This log file appears to be invalid. Please re-check and re-upload your log file.", colour=self.ryujinx_blue, ), ) + logging.warning(error) except Exception as error: await reply_message.edit( content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception." ) - print(logging.warning(error)) + logging.warning(error) else: duplicate_log_file = next( ( @@ -898,20 +898,17 @@ class LogFileReader(Cog): for attachment in message.attachments: is_log_file, is_ryujinx_log_file = self.is_valid_log_name(attachment) - if message.channel.id in self.bot_log_allowed_channels.values(): + if ( + is_log_file + and is_ryujinx_log_file + and message.channel.id in self.bot_log_allowed_channels.values() + ): return await self.analyse_log_message( message, message.attachments.index(attachment) ) - elif is_log_file and not is_ryujinx_log_file: - return await message.channel.send( - content=message.author.mention, - embed=Embed( - description=f"Your file does not match the Ryujinx log format. Please check your file.", - colour=self.ryujinx_blue, - ), - ) elif ( is_log_file + and is_ryujinx_log_file and message.channel.id not in self.bot_log_allowed_channels.values() ): return await message.author.send(