66import discord
77
88from eggsplode .strings import format_message , tooltip
9+ from eggsplode .ui .base import BaseView
910
1011if TYPE_CHECKING :
1112 from eggsplode .core import Game
1213
1314
14- class SelectionView (discord . ui . DesignerView ):
15+ class SelectionView (BaseView ):
1516 def __init__ (self , timeout : int = 20 ):
1617 super ().__init__ (timeout = timeout , disable_on_timeout = True )
1718 self .confirm_button = discord .ui .Button (
@@ -20,22 +21,20 @@ def __init__(self, timeout: int = 20):
2021 self .confirm_button .callback = self .confirm
2122
2223 async def on_timeout (self ):
23- try :
24- await super ().on_timeout ()
25- finally :
24+ if not self .is_ignoring_interactions :
2625 await self .finish ()
2726
28- async def finish (self , interaction : discord . Interaction | None = None ):
29- pass
27+ async def finish (self ):
28+ self . ignore_interactions ()
3029
3130 async def confirm (self , interaction : discord .Interaction ):
3231 self .disable_all_items ()
3332 await interaction .edit (view = self )
34- self .stop ()
35- await self .finish (interaction )
33+ if not self .is_ignoring_interactions :
34+ await self .finish ()
3635
3736
38- class ChoosePlayerView (discord . ui . DesignerView ):
37+ class ChoosePlayerView (BaseView ):
3938 def __init__ (
4039 self ,
4140 game : "Game" ,
@@ -50,12 +49,11 @@ def __init__(
5049 self .callback_action = callback_action
5150 self .user_select = None
5251 self .action_row = None
53- self .game .events .game_end += self .stop
52+ self .game .events .game_end += self .ignore_interactions
5453
5554 async def on_timeout (self ):
56- try :
57- await super ().on_timeout ()
58- finally :
55+ if not self .is_ignoring_interactions :
56+ self .ignore_interactions ()
5957 await self .callback_action (self .eligible_players [0 ])
6058
6159 async def skip_if_single_option (self ) -> bool :
@@ -86,7 +84,7 @@ async def create_user_selection(self):
8684 async def selection_callback (self , interaction : discord .Interaction ):
8785 if not (interaction and self .user_select ):
8886 return
89- self .stop ()
87+ self .ignore_interactions ()
9088 self .disable_all_items ()
9189 await interaction .edit (view = self , delete_after = 0 )
9290 if not isinstance (self .user_select .values [0 ], str ):
@@ -110,21 +108,13 @@ def __init__(
110108 self .card_position = 0
111109 self .move_prompt_display = discord .ui .TextDisplay (self .move_prompt )
112110 self .add_item (self .move_prompt_display )
113- self .top_button = discord .ui .Button (
114- label = "Top" , style = discord .ButtonStyle .blurple , emoji = "⏫"
115- )
111+ self .top_button = discord .ui .Button (label = "Top" , emoji = "⏫" )
116112 self .top_button .callback = self .top
117- self .move_up_button = discord .ui .Button (
118- label = "Move up" , style = discord .ButtonStyle .blurple , emoji = "⬆️"
119- )
113+ self .move_up_button = discord .ui .Button (label = "Move up" , emoji = "🔼" )
120114 self .move_up_button .callback = self .move_up
121- self .move_down_button = discord .ui .Button (
122- label = "Move down" , style = discord .ButtonStyle .blurple , emoji = "⬇️"
123- )
115+ self .move_down_button = discord .ui .Button (label = "Move down" , emoji = "🔽" )
124116 self .move_down_button .callback = self .move_down
125- self .bottom_button = discord .ui .Button (
126- label = "Bottom" , style = discord .ButtonStyle .blurple , emoji = "⏬"
127- )
117+ self .bottom_button = discord .ui .Button (label = "Bottom" , emoji = "⏬" )
128118 self .bottom_button .callback = self .bottom
129119 self .move_action_row = discord .ui .ActionRow (
130120 self .top_button ,
@@ -134,15 +124,16 @@ def __init__(
134124 self .confirm_button ,
135125 )
136126 self .add_item (self .move_action_row )
137- self .game .events .game_end += self .stop
127+ self .game .events .game_end += self .ignore_interactions
138128
139129 async def skip_if_deck_empty (self ) -> bool :
140130 if len (self .game .deck ) == 0 :
141131 await self .finish ()
142132 return True
143133 return False
144134
145- async def finish (self , interaction = None ):
135+ async def finish (self ):
136+ await super ().finish ()
146137 self .game .deck .insert (self .card_position , self .card )
147138 await self .callback_action ()
148139
0 commit comments