From 9cd2d6550d7a7f04534a1462c05474118d079e4c Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Thu, 4 May 2023 00:40:41 +0200 Subject: [PATCH] Small logfilereader fixes and improvements (#49) * Fix cheat_information regex * Add warning about default user profiles to notes * Fix disable_ro_section issues * Apply black formatting --- robocop_ng/cogs/logfilereader.py | 14 +++++++++++--- robocop_ng/helpers/disabled_ids.py | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/robocop_ng/cogs/logfilereader.py b/robocop_ng/cogs/logfilereader.py index 31f40cc..eee94a0 100644 --- a/robocop_ng/cogs/logfilereader.py +++ b/robocop_ng/cogs/logfilereader.py @@ -647,10 +647,10 @@ class LogFileReader(Cog): return mods_status def cheat_information(log_file=log_file): - cheat_regex = re.compile(r"Installing cheat\s\'(.+?)\'") + cheat_regex = re.compile(r"Installing cheat\s\'?\'") matches = re.findall(cheat_regex, log_file) if matches: - cheats = [match[0] for match in matches] + cheats = [f"ℹ️ {match}" for match in matches] return list(set(cheats)) game_mods = mods_information() @@ -661,6 +661,14 @@ class LogFileReader(Cog): if game_cheats: self.embed["game_info"]["cheats"] = "\n".join(game_cheats) + if ( + re.search(r"UserId: 00000000000000010000000000000000", log_file) + is not None + ): + self.embed["game_info"]["notes"].append( + "⚠️ Default user profile in use, consider creating a custom one." + ) + controllers_regex = re.compile(r"Hid Configure: ([^\r\n]+)") controllers = re.findall(controllers_regex, log_file) if controllers: @@ -974,7 +982,7 @@ class LogFileReader(Cog): ] ) async def disable_ro_section( - self, ctx: Context, note: str, ro_section_snippet: str + self, ctx: Context, note: str, *, ro_section_snippet: str ): ro_section_snippet = ro_section_snippet.strip("`").splitlines() ro_section_snippet = [ diff --git a/robocop_ng/helpers/disabled_ids.py b/robocop_ng/helpers/disabled_ids.py index 47f8ad8..1392620 100644 --- a/robocop_ng/helpers/disabled_ids.py +++ b/robocop_ng/helpers/disabled_ids.py @@ -54,12 +54,15 @@ def is_build_id_disabled(bot, build_id: str) -> bool: return build_id in disabled_ids["build_id"].keys() -def is_ro_section_disabled(bot, ro_section: dict[str, str]) -> bool: +def is_ro_section_disabled(bot, ro_section: dict[str, Union[str, list[str]]]) -> bool: disabled_ids = get_disabled_ids(bot) matches = [] for note, entry in disabled_ids["ro_section"].items(): for key, content in entry.items(): - matches.append(ro_section[key].lower() == content.lower()) + if key == "module": + matches.append(ro_section[key].lower() == content.lower()) + else: + matches.append(ro_section[key] == content) if all(matches): return True else: @@ -111,13 +114,18 @@ def remove_disabled_build_id(bot, build_id: str) -> bool: return False -def add_disabled_ro_section(bot, note: str, ro_section: dict[str, str]) -> bool: +def add_disabled_ro_section( + bot, note: str, ro_section: dict[str, Union[str, list[str]]] +) -> bool: disabled_ids = get_disabled_ids(bot) note = note.lower() if note not in disabled_ids["ro_section"].keys(): disabled_ids["ro_section"][note] = {} for key, content in ro_section.items(): - disabled_ids["ro_section"][note][key] = content.lower() + if key == "module": + disabled_ids["ro_section"][note][key] = content.lower() + else: + disabled_ids["ro_section"][note][key] = content set_disabled_ids(bot, disabled_ids) return True return False