From 95d23864d128459c3ec4edbc78e320f4fc8c1d4b Mon Sep 17 00:00:00 2001 From: jackra1n <45038833+jackra1n@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:37:20 +0100 Subject: [PATCH] wip --- bot/cogs/karma.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/cogs/karma.py b/bot/cogs/karma.py index 5f29bc6..270700b 100644 --- a/bot/cogs/karma.py +++ b/bot/cogs/karma.py @@ -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) @@ -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) @@ -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)