1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

refactor: Update coinflip command to handle invalid predictions

This commit is contained in:
wlinator 2024-09-22 16:22:45 +02:00
parent 5c9f229019
commit 360454c152
2 changed files with 32 additions and 29 deletions

View file

@ -79,18 +79,18 @@
"case_type_field_value": "`{0}`",
"case_type_field_value_with_duration": "`{0} ({1})`",
"coinflip_correct_prediction_author": "Correct Prediction!",
"coinflip_correct_prediction_description": "The coin landed on **{0}**. You predicted correctly!",
"coinflip_flipping_animation_1": "\ud83e\ude79 Flipping...",
"coinflip_flipping_animation_2": "\ud83e\ude79 Flipping..",
"coinflip_flipping_animation_3": "\ud83e\ude79 Flipping.",
"coinflip_flipping_author": "Flipping a Coin",
"coinflip_flipping_description": "The coin is in the air...",
"coinflip_correct_prediction_description": "the coin landed on **{0}**. You predicted correctly!",
"coinflip_flipping_animation_1": "\ud83e\ude99 Flipping...",
"coinflip_flipping_animation_2": "\ud83e\ude99 Flipping..",
"coinflip_flipping_animation_3": "\ud83e\ude99 Flipping.",
"coinflip_flipping_author": "flipping a Coin",
"coinflip_flipping_description": "the coin is in the air...",
"coinflip_invalid_prediction_author": "Invalid Prediction",
"coinflip_invalid_prediction_description": "Please enter a valid prediction ('heads'/'h' or 'tails'/'t').",
"coinflip_invalid_prediction_description": "please enter a valid prediction ('heads'/'h' or 'tails'/'t').",
"coinflip_result_author": "Coin Flip Result",
"coinflip_result_description": "The coin landed on **{0}**.",
"coinflip_result_description": "the coin landed on **{0}**.",
"coinflip_wrong_prediction_author": "Wrong Prediction",
"coinflip_wrong_prediction_description": "The coin landed on **{0}**. Your prediction was incorrect.",
"coinflip_wrong_prediction_description": "the coin landed on **{0}**. Your prediction was incorrect.",
"config_author": "Server Configuration",
"config_birthday_channel_set": "birthday announcements will be sent in {0}.",
"config_birthday_module_already_disabled": "the birthday module was already disabled.",

View file

@ -36,6 +36,18 @@ class Coinflip(commands.Cog):
"""
result = random.choice(["heads", "tails"])
if prediction:
prediction = prediction.lower()
if prediction not in ["heads", "h", "tails", "t"]:
embed = Builder.create_embed(
Builder.ERROR,
user_name=ctx.author.name,
author_text=CONST.STRINGS["coinflip_invalid_prediction_author"],
description=CONST.STRINGS["coinflip_invalid_prediction_description"],
)
await ctx.send(embed=embed)
return
flip_embed = Builder.create_embed(
Builder.INFO,
user_name=ctx.author.name,
@ -61,8 +73,6 @@ class Coinflip(commands.Cog):
await asyncio.sleep(0.5)
if prediction:
prediction = prediction.lower()
if prediction in ["heads", "h", "tails", "t"]:
predicted_correctly = (prediction.startswith("h") and result == "heads") or (
prediction.startswith("t") and result == "tails"
)
@ -80,13 +90,6 @@ class Coinflip(commands.Cog):
author_text=CONST.STRINGS["coinflip_wrong_prediction_author"],
description=CONST.STRINGS["coinflip_wrong_prediction_description"].format(result),
)
else:
embed = Builder.create_embed(
Builder.ERROR,
user_name=ctx.author.name,
author_text=CONST.STRINGS["coinflip_invalid_prediction_author"],
description=CONST.STRINGS["coinflip_invalid_prediction_description"],
)
else:
embed = Builder.create_embed(
Builder.INFO,