GoldyBot.utility.views.dropdown
1import GoldyBot 2from typing import Callable, List 3 4MODULE_NAME = "DROPDOWN" 5 6async def dropdown(ctx:GoldyBot.InteractionToCtx, options:List[GoldyBot.nextcord.SelectOption], min_max_value:tuple=(1, 1) , placeholder_msg="🎯 Pick an Option", warning=True, warning_msg="🛑 Are you sure!", callback:Callable=None): 7 """ 8 Goldy Bot's dropdown view. (Only the command author can interact with this!) 9 """ 10 11 class Dropdown(GoldyBot.nextcord.ui.Select): 12 def __init__(self, author:GoldyBot.Member, options:List[GoldyBot.nextcord.SelectOption], placeholder_msg:str, warning:bool, warning_msg:str, callback:Callable): 13 self.author = author 14 self.warning = warning 15 self.warning_msg = warning_msg 16 self.callback_ = callback 17 18 self.options_values = {} 19 20 # Embeds 21 self.your_not_author_embed = GoldyBot.Embed( 22 title="❌ Author Only!", 23 description="***❌{}, this view can only be interacted by the command author.***", 24 colour=GoldyBot.Colours.RED 25 ) 26 27 super().__init__( 28 placeholder=placeholder_msg, 29 min_values=min_max_value[0], 30 max_values=min_max_value[1], 31 options=options, 32 ) 33 34 async def callback(self, interaction: GoldyBot.nextcord.Interaction): 35 if self.author.member.id == interaction.user.id: # Is this the author. 36 view = await GoldyBot.utility.views.confirm.yes_or_no(interaction) 37 38 if self.warning: 39 message = await interaction.send(self.warning_msg, view=view) 40 await view.wait() 41 await message.delete() 42 else: 43 view.value = True 44 45 if view.value == True: 46 if not self.callback_ == None: 47 await self.callback_(self.values) # Execute callback 48 49 await interaction.delete_original_message() 50 51 GoldyBot.logging.log(f"[{MODULE_NAME}] Dropdown view for '{self.author.name}' executed it's function '{self.callback_.__name__}'!") 52 53 else: 54 # View not for you message. 55 embed_thumbnail = GoldyBot.File(GoldyBot.paths.ASSETS + "/angry_mirai_kuriyama.gif") 56 57 your_not_author_embed = self.your_not_author_embed.copy() 58 your_not_author_embed.description = self.your_not_author_embed.description.format(interaction.user.mention) 59 your_not_author_embed.set_thumbnail("attachment://image.gif") 60 61 message = await interaction.send(embed=your_not_author_embed, file=GoldyBot.nextcord.File(embed_thumbnail.file_path, filename="image.gif")) 62 await message.delete(delay=6) 63 64 #raise GoldyBot.errors.YourNotAuthor(f"[{MODULE_NAME}] '{interaction.user.name}' tried interacting with a command author only view.") 65 66 class DropdownView(GoldyBot.nextcord.ui.View): 67 def __init__(self, author:GoldyBot.Member, options:List[GoldyBot.nextcord.SelectOption], placeholder_msg:str, warning:bool, warning_msg:str, callback:Callable): 68 super().__init__() 69 70 self.add_item(Dropdown(author, options, placeholder_msg, warning, warning_msg, callback)) 71 72 return DropdownView(GoldyBot.Member(ctx), options, placeholder_msg, warning, warning_msg, callback)
async def
dropdown( ctx: GoldyBot.objects.slash.InteractionToCtx, options: List[nextcord.components.SelectOption], min_max_value: tuple = (1, 1), placeholder_msg='🎯 Pick an Option', warning=True, warning_msg='🛑 Are you sure!', callback: Callable = None):
7async def dropdown(ctx:GoldyBot.InteractionToCtx, options:List[GoldyBot.nextcord.SelectOption], min_max_value:tuple=(1, 1) , placeholder_msg="🎯 Pick an Option", warning=True, warning_msg="🛑 Are you sure!", callback:Callable=None): 8 """ 9 Goldy Bot's dropdown view. (Only the command author can interact with this!) 10 """ 11 12 class Dropdown(GoldyBot.nextcord.ui.Select): 13 def __init__(self, author:GoldyBot.Member, options:List[GoldyBot.nextcord.SelectOption], placeholder_msg:str, warning:bool, warning_msg:str, callback:Callable): 14 self.author = author 15 self.warning = warning 16 self.warning_msg = warning_msg 17 self.callback_ = callback 18 19 self.options_values = {} 20 21 # Embeds 22 self.your_not_author_embed = GoldyBot.Embed( 23 title="❌ Author Only!", 24 description="***❌{}, this view can only be interacted by the command author.***", 25 colour=GoldyBot.Colours.RED 26 ) 27 28 super().__init__( 29 placeholder=placeholder_msg, 30 min_values=min_max_value[0], 31 max_values=min_max_value[1], 32 options=options, 33 ) 34 35 async def callback(self, interaction: GoldyBot.nextcord.Interaction): 36 if self.author.member.id == interaction.user.id: # Is this the author. 37 view = await GoldyBot.utility.views.confirm.yes_or_no(interaction) 38 39 if self.warning: 40 message = await interaction.send(self.warning_msg, view=view) 41 await view.wait() 42 await message.delete() 43 else: 44 view.value = True 45 46 if view.value == True: 47 if not self.callback_ == None: 48 await self.callback_(self.values) # Execute callback 49 50 await interaction.delete_original_message() 51 52 GoldyBot.logging.log(f"[{MODULE_NAME}] Dropdown view for '{self.author.name}' executed it's function '{self.callback_.__name__}'!") 53 54 else: 55 # View not for you message. 56 embed_thumbnail = GoldyBot.File(GoldyBot.paths.ASSETS + "/angry_mirai_kuriyama.gif") 57 58 your_not_author_embed = self.your_not_author_embed.copy() 59 your_not_author_embed.description = self.your_not_author_embed.description.format(interaction.user.mention) 60 your_not_author_embed.set_thumbnail("attachment://image.gif") 61 62 message = await interaction.send(embed=your_not_author_embed, file=GoldyBot.nextcord.File(embed_thumbnail.file_path, filename="image.gif")) 63 await message.delete(delay=6) 64 65 #raise GoldyBot.errors.YourNotAuthor(f"[{MODULE_NAME}] '{interaction.user.name}' tried interacting with a command author only view.") 66 67 class DropdownView(GoldyBot.nextcord.ui.View): 68 def __init__(self, author:GoldyBot.Member, options:List[GoldyBot.nextcord.SelectOption], placeholder_msg:str, warning:bool, warning_msg:str, callback:Callable): 69 super().__init__() 70 71 self.add_item(Dropdown(author, options, placeholder_msg, warning, warning_msg, callback)) 72 73 return DropdownView(GoldyBot.Member(ctx), options, placeholder_msg, warning, warning_msg, callback)
Goldy Bot's dropdown view. (Only the command author can interact with this!)