Skip to content

Update general_coinflip.py #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: Development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/zorak/cogs/general/general_coinflip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,35 @@ async def get_bets(self, ctx: discord.AutocompleteContext):
@option("bet", description="Bet amount", autocomplete=get_bets)
async def coinflip(self, ctx: discord.ApplicationContext, side: str, bet_amount: int):
"""Flips a coin, adds or removes points from the user based on their bet."""

# Get Off Topic channel for response
channel = next((c for c in ctx.guild.channels if c.name == "📁-off-topic"), None)
ping = ctx.author.mention

wallet = self.bot.db_client.get_user_points(int(ctx.user.id))

if wallet is None:
# User is not yet added to the DB
self.bot.db_client.add_user_to_table(ctx.author)
await ctx.respond(
"You have no points yet.\n"
await channel.send(
f"{ping}\nYou have no points yet.\n"
"You can get points by chatting in the server,"
" or by doing things that make mods happy.")
return

if bet_amount < 0:
await ctx.respond("You betting negative points? You are a madman!")
await channel.send(f"{ping}\nYou betting negative points? You are a madman!")
return

if bet_amount == 0:
await ctx.respond("You betting zero points? You are a coward!")
await channel.send(f"{ping}\nYou betting zero points? You are a coward!")
return

if wallet < bet_amount:
# User is trying to be a sly little fox
await ctx.respond(f"You cant bet **{bet_amount:,}** points"
f", because you only have **{wallet:,}**")
await channel.send(
f"{ping}\nYou can't bet **{bet_amount:,}** points"
f", because you only have **{wallet:,}**")
return

if wallet >= bet_amount:
Expand All @@ -64,22 +70,19 @@ async def coinflip(self, ctx: discord.ApplicationContext, side: str, bet_amount:
name = ctx.author.name if ctx.author.nick is None else ctx.author.nick

if coin == side:
await ctx.respond(
f"{name} flipped a coin and chose **{side}**\n"
f"The coin landed on **{coin}**!\n"
f"You won **{bet_amount:,} points**!\n"
f"You now have **{(wallet + bet_amount):,} points!**")
self.bot.db_client.add_points_to_user(ctx.author.id, bet_amount)
return

status = "won"
bet_result = bet_amount
else:
await ctx.respond(
f"{name} flipped a coin and chose **{side}**\n"
f"The coin landed on **{coin}**!\n"
f"You lost **{bet_amount:,} points**!\n"
f"You now have **{(wallet - bet_amount):,} points**!")
self.bot.db_client.add_points_to_user(ctx.author.id, -bet_amount)
return
status = "lost"
bet_result = -bet_amount

await channel.send(
f"{ping} flipped a coin and chose **{side}**\n"
f"The coin landed on **{coin}**!\n"
f"You {status} **{bet_amount:,} points**!\n"
f"You now have **{(wallet + bet_result):,} points!**")
self.bot.db_client.add_points_to_user(ctx.author.id, bet_result)
return


def setup(bot):
Expand Down