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
This commit is contained in:
parent
e937abb41c
commit
45538eec6f
1 changed files with 11 additions and 14 deletions
|
@ -25,8 +25,7 @@ class LogFileReader(Cog):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_log_name(attachment: Attachment) -> tuple[bool, bool]:
|
def is_valid_log_name(attachment: Attachment) -> tuple[bool, bool]:
|
||||||
filename = attachment.filename
|
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$")
|
||||||
ryujinx_log_file_regex = re.compile(r"^Ryujinx_.*\.log|message\.txt$")
|
|
||||||
log_file = re.compile(r"^.*\.log|.*\.txt$")
|
log_file = re.compile(r"^.*\.log|.*\.txt$")
|
||||||
is_ryujinx_log_file = re.match(ryujinx_log_file_regex, filename) is not None
|
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
|
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:]
|
self.uploaded_log_info = self.uploaded_log_info[-5:]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
return await reply_message.edit(content=None, embed=embed)
|
return await reply_message.edit(content=None, embed=embed)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError as error:
|
||||||
return await message.channel.send(
|
await reply_message.edit(
|
||||||
content=author_mention,
|
content=author_mention,
|
||||||
embed=Embed(
|
embed=Embed(
|
||||||
description="This log file appears to be invalid. Please re-check and re-upload your log file.",
|
description="This log file appears to be invalid. Please re-check and re-upload your log file.",
|
||||||
colour=self.ryujinx_blue,
|
colour=self.ryujinx_blue,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
logging.warning(error)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
await reply_message.edit(
|
await reply_message.edit(
|
||||||
content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception."
|
content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception."
|
||||||
)
|
)
|
||||||
print(logging.warning(error))
|
logging.warning(error)
|
||||||
else:
|
else:
|
||||||
duplicate_log_file = next(
|
duplicate_log_file = next(
|
||||||
(
|
(
|
||||||
|
@ -898,20 +898,17 @@ class LogFileReader(Cog):
|
||||||
for attachment in message.attachments:
|
for attachment in message.attachments:
|
||||||
is_log_file, is_ryujinx_log_file = self.is_valid_log_name(attachment)
|
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(
|
return await self.analyse_log_message(
|
||||||
message, message.attachments.index(attachment)
|
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 (
|
elif (
|
||||||
is_log_file
|
is_log_file
|
||||||
|
and is_ryujinx_log_file
|
||||||
and message.channel.id not in self.bot_log_allowed_channels.values()
|
and message.channel.id not in self.bot_log_allowed_channels.values()
|
||||||
):
|
):
|
||||||
return await message.author.send(
|
return await message.author.send(
|
||||||
|
|
Loading…
Reference in a new issue