mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 18:03:12 +00:00
Add blackjack view and refactor other views
This commit is contained in:
parent
84ae737a33
commit
5149fa172c
2 changed files with 64 additions and 4 deletions
59
ui/views/blackjack.py
Normal file
59
ui/views/blackjack.py
Normal file
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue