From 881c4e3e570812e296b5a069bbfccce0d0f9f9b2 Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Fri, 19 Aug 2022 00:52:55 -0400 Subject: [PATCH] add safety check --- .../commands/periodic/transcription_check_ping.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bubbles/commands/periodic/transcription_check_ping.py b/bubbles/commands/periodic/transcription_check_ping.py index 20d69d2..7837a95 100644 --- a/bubbles/commands/periodic/transcription_check_ping.py +++ b/bubbles/commands/periodic/transcription_check_ping.py @@ -99,11 +99,9 @@ def _get_check_username(message: Dict) -> Optional[str]: :returns: The username, or None if it couldn't be found. """ text = _extract_check_text(message) - try: - username_match = USERNAME_REGEX.search(text) - return username_match.group("username") if username_match else None - except TypeError: - print(f"Could not parse username. Value of `text`: {text}") + + username_match = USERNAME_REGEX.search(text) + return username_match.group("username") if username_match else None def _get_check_status(message: Dict) -> Tuple[CheckStatus, Optional[str]]: @@ -158,6 +156,7 @@ def _get_check_time(message: Dict) -> datetime: def _get_check_data(message: Dict) -> CheckData: """Extract the data from a given check message.""" + user = _get_check_username(message) status, mod = _get_check_status(message) link = _get_check_link(message) @@ -184,6 +183,10 @@ def _extract_open_checks(messages: List[Dict]) -> List[CheckData]: if not _is_check_message(message): continue + # sanity check, make sure the message is valid + if not _extract_check_text(message): + continue + check = _get_check_data(message) # We don't need to handle resolved checks