diff --git a/ui/views/blackjack.py b/ui/views/blackjack.py new file mode 100644 index 0000000..756a6ce --- /dev/null +++ b/ui/views/blackjack.py @@ -0,0 +1,59 @@ +import discord +from discord.ext import commands +from discord.ui import View, Button +from lib.const import CONST +from typing import List, Optional + + +class BlackJackButtons(View): + def __init__(self, ctx: commands.Context[commands.Bot]) -> None: + super().__init__(timeout=180) + self.ctx: commands.Context[commands.Bot] = ctx + self.clickedHit: bool = False + self.clickedStand: bool = False + self.clickedDoubleDown: bool = False + self.message: Optional[discord.Message] = None + + async def on_timeout(self) -> None: + self.children: List[discord.ui.Button] = [] + + for child in self.children: + if isinstance(child, Button): + child.disabled = True + + @discord.ui.button( + label=CONST.STRINGS["blackjack_hit"], + style=discord.ButtonStyle.gray, + emoji=CONST.BLACKJACK_HIT_EMOJI, + ) + async def hit_button_callback( + self, + interaction: discord.Interaction, + button: Button, + ) -> None: + self.clickedHit = True + await interaction.response.defer() + self.stop() + + @discord.ui.button( + label=CONST.STRINGS["blackjack_stand"], + style=discord.ButtonStyle.gray, + emoji=CONST.BLACKJACK_STAND_EMOJI, + ) + async def stand_button_callback( + self, + interaction: discord.Interaction, + button: Button, + ) -> None: + self.clickedStand = True + await interaction.response.defer() + self.stop() + + async def interaction_check(self, interaction: discord.Interaction) -> bool: + if interaction.user == self.ctx.author: + return True + await interaction.response.send_message( + CONST.STRINGS["error_cant_use_buttons"], + ephemeral=True, + ) + return False diff --git a/ui/views/introduction.py b/ui/views/introduction.py index 3fa27a0..22cb10d 100644 --- a/ui/views/introduction.py +++ b/ui/views/introduction.py @@ -1,13 +1,14 @@ from typing import Optional import discord +from discord.ext import commands from discord.ui import Button, View class IntroductionStartButtons(View): - def __init__(self, ctx) -> None: + def __init__(self, ctx: commands.Context[commands.Bot]) -> None: super().__init__(timeout=60) - self.ctx = ctx + self.ctx: commands.Context[commands.Bot] = ctx self.clicked_start: bool = False self.clicked_stop: bool = False self.message: Optional[discord.Message] = None @@ -41,9 +42,9 @@ class IntroductionStartButtons(View): class IntroductionFinishButtons(View): - def __init__(self, ctx) -> None: + def __init__(self, ctx: commands.Context[commands.Bot]) -> None: super().__init__(timeout=60) - self.ctx = ctx + self.ctx: commands.Context[commands.Bot] = ctx self.clicked_confirm: bool = False self.message: Optional[discord.Message] = None