From 3eed30567d7afed2d88b5851bf5e326c0230fddf Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Fri, 29 Jul 2022 14:12:58 -0400 Subject: [PATCH] Fixed single digit second submissions. Covered bases to ensure time format is consistant. --- cogs/message_listener/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cogs/message_listener/__init__.py b/cogs/message_listener/__init__.py index dc2fd2a..d519eb2 100644 --- a/cogs/message_listener/__init__.py +++ b/cogs/message_listener/__init__.py @@ -43,15 +43,14 @@ class SubmissionListener(commands.Cog, name="Message Listener"): ) time_regex = re.search( - "^([0-9]{1,2}:)?[0-9]{2}(\.[0-9])?$", # pylint: disable=anomalous-backslash-in-string - message.content, + "^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content ) int_regex = re.search("^[0-9]+$", message.content) if time_regex is None and is_time_record: embed = submission_message.embeds[0] embed.add_field( name="Error", - value="Time record must follow format MM:SS.ms or SS.ms or SS.", + value="Time record must follow format MM:SS.ms, SS.ms, or SS.", ) elif int_regex is None and not is_time_record: embed = submission_message.embeds[0] @@ -60,11 +59,18 @@ class SubmissionListener(commands.Cog, name="Message Listener"): score = message.content if is_time_record: # standardize time score format. - # strip leading 0s and colon - # then add colon if its not there - score = score.lstrip("0:") - if score.find(":") == -1: + if re.search("^[1-9]?[0-9]:[0-9]{2}(\\.[0-9])?$", score): + # score is already fine. + pass + elif re.search("^[0-9]{2}(\\.[0-9])?$", score): + # need to add leading colon and 0 score = "0:" + score + elif re.search("^[0-9](\\.[0-9])?$", score): + # need to add 0 in seconds and leading colon and 0 + score = "0:0" + score + elif re.search("^[0]?[0-9]:[0-9]{2}(\\.[0-9])?$", score): + # if there is a minute 10ths place 0, remove + score = score.lstrip("0") submission_objects[message.author.id]["score"] = score embed = get_submission_embed(message.author.id)