Correct score submission value. Parse times correctly.

This commit is contained in:
alwayscompiling
2022-12-01 23:30:21 -05:00
parent 44cb9025b0
commit 2e3f298036
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ class VerificationView(nextcord.ui.View):
elif field["name"] == "CategoryId":
category_id = int(field["value"])
elif field["name"] == "Score":
score = float(field["value"])
score = field["value"]
elif field["name"] == "User Name":
user = field["value"]
+12 -2
View File
@@ -315,7 +315,7 @@ async def send_highscore_message(channel: nextcord.TextChannel, group: CategoryG
async def submit_score(
interaction: nextcord.Interaction, group_id: int, category_id: int, username: str, score: float
interaction: nextcord.Interaction, group_id: int, category_id: int, username: str, score: str
) -> None:
"""
Adds passed score to group. Then updates group message by calling send_highscore_message.
@@ -326,9 +326,19 @@ async def submit_score(
group (CategoryGroup): group to submit score to.
category_id (Category): Category to submit score to.
username (str): The user who submitted the score.
score (float): Score to submit.
score (str): Score to submit. Need to convert to correct type.
"""
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == category_id)
is_time_record = session.scalar(stmt)
if is_time_record:
minutes = float(score.split(":", maxsplit=1)[0])
seconds = float(score.split(":", maxsplit=1)[1])
score = (minutes * 60) + seconds
else:
score = float(score)
score_obj = Score(UserName=username, Score=score, CategoryId=category_id)
session.add(score_obj)
session.commit()