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
This commit is contained in:
TSRBerry 2023-05-04 00:40:41 +02:00 committed by GitHub
parent 1eacb849f5
commit 9cd2d6550d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -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 = [

View file

@ -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():
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():
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