Allow user to update score.

This commit is contained in:
alwayscompiling
2022-12-03 20:49:17 -05:00
parent e3a937649f
commit 081e406d51
+9 -4
View File
@@ -275,7 +275,6 @@ def format_highscore_message(group: CategoryGroup) -> str:
if not ret_string.endswith("\n\n"): if not ret_string.endswith("\n\n"):
ret_string += "\n" ret_string += "\n"
print(ret_string)
return ret_string + "```" return ret_string + "```"
@@ -345,8 +344,14 @@ async def submit_score(
else: else:
score = float(score) score = float(score)
score_obj = Score(UserName=username, Score=score, CategoryId=category_id) stmt = select(Score).where(Score.UserName == username).where(Score.CategoryId == category_id)
session.add(score_obj) existing_score = session.scalar(stmt)
if existing_score:
existing_score.Score = score
else:
score_obj = Score(UserName=username, Score=score, CategoryId=category_id)
session.add(score_obj)
session.commit() session.commit()
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id) stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id)
@@ -356,7 +361,7 @@ async def submit_score(
channel = interaction.guild.get_channel(group.ChannelId) channel = interaction.guild.get_channel(group.ChannelId)
error_response = "Registered Highscores channel does not exist or was never registered." error_response = "Registered Highscores channel does not exist or was never registered."
error_response += 'Register with "?register" command.' error_response += 'Register with "/register" command.'
assert channel is not None, await interaction.send(error_response, ephemeral=True) assert channel is not None, await interaction.send(error_response, ephemeral=True)
await send_highscore_message(channel, group) await send_highscore_message(channel, group)