Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Feb 20, 2024
1 parent 24ead2c commit 95d2386
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bot/cogs/karma.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,9 @@ def __init__(self, ctx: commands.Context, kasino: Record):


async def on_submit(self, interaction: discord.Interaction) -> None:
kasino_id = self.kasino['id']
amount = self.bet_amount_input.value
option = self.bet_option_select.value
if amount != 'all':
try:
amount = int(amount)
Expand All @@ -1007,7 +1009,8 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
if self.kasino['locked']:
return await interaction.response.send_message('The kasino is locked! No more bets are taken in. Time to wait and see...', ephemeral=True)

bettor_karma = await self._get_user_karma(interaction.user.id, interaction.guild.id)
user_karma_query = 'SELECT amount FROM karma WHERE discord_user_id = $1 AND discord_server_id = $2'
bettor_karma = await self.ctx.bot.db.fetchval(user_karma_query, interaction.user.id, interaction.guild.id)
if bettor_karma is None:
return await interaction.response.send_message('You don\'t have any karma!', ephemeral=True)

Expand All @@ -1018,18 +1021,19 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
total_bet = amount
output = 'added'

output_embed = discord.Embed(color=discord.Colour.from_rgb(209, 25, 25))
stmt_bet = 'SELECT * FROM kasino_bet WHERE kasino_id = $1 AND discord_user_id = $2;'
user_bet = await self.bot.db.fetchrow(stmt_bet, kasino_id, ctx.author.id)
user_bet = await self.bot.db.fetchrow(stmt_bet, kasino_id, interaction.user.id)
if user_bet is not None:
if user_bet['option'] != option:
output_embed.title = f'You can\'t change your choice on the bet with id {kasino_id}. No chickening out!'
return await ctx.author.send(embed=output_embed)
return await interaction.response.send_message(embed=output_embed, ephemeral=True)
total_bet = user_bet['amount'] + amount
output = 'increased'
stmt_bet = '''INSERT INTO kasino_bet (kasino_id, discord_user_id, amount, option) VALUES ($1, $2, $3, $4)
ON CONFLICT (kasino_id, discord_user_id) DO UPDATE SET amount = kasino_bet.amount + $3;
UPDATE user_karma SET karma = user_karma.karma - $3 WHERE discord_user_id = $2 AND discord_server_id = $5;'''
await self.bot.db.execute(stmt_bet, kasino_id, ctx.author.id, amount, option, ctx.guild.id)
await self.bot.db.execute(stmt_bet, kasino_id, interaction.user.id, amount, option, interaction.guild.id)

output_embed.title = f'**Successfully {output} bet on option {option}, on kasino with ID {kasino_id} for {amount} karma! Total bet is now: {total_bet} Karma**'
output_embed.color = discord.Colour.from_rgb(52, 79, 235)
Expand Down

0 comments on commit 95d2386

Please sign in to comment.