Fixed single digit second submissions. Covered bases to ensure time format is consistant.

This commit is contained in:
alwayscompiling
2022-07-29 14:12:58 -04:00
parent 565babd1d3
commit 3eed30567d
+13 -7
View File
@@ -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)