GoldyBot.utility.views.forms

 1import GoldyBot
 2from typing import Callable, List
 3
 4MODULE_NAME = __name__.upper()
 5
 6def normal_form(title:str, items:List[GoldyBot.nextcord.ui.Item], callback:Callable, author:GoldyBot.Member, timeout=None, 
 7        warning=False, warning_msg="🛑 Are you sure!") -> GoldyBot.nextcord.ui.Modal:
 8    """
 9    Goldy Bot's normal form modal. (Only the command author can interact with interactions from this form!)
10    """
11
12    class NormalForm(GoldyBot.nextcord.ui.Modal):
13        def __init__(self):
14            super().__init__(title, timeout=timeout, auto_defer=True)
15
16            for item in items:
17                self.add_item(item)
18
19        async def callback(self, interaction: GoldyBot.nextcord.Interaction):
20            view = await GoldyBot.utility.views.confirm.yes_or_no(interaction)
21            
22            if warning:
23                message = await interaction.send(warning_msg, view=view)
24                await view.wait()
25                await message.delete()
26            else:
27                view.value = True
28
29            if view.value == True:
30                if not callback == None:
31                    await callback((lambda x: [item_.value for item_ in x])(items), interaction) # Execute callback
32
33                    GoldyBot.logging.log(f"[{MODULE_NAME}] Normal form modal for '{author.name}' executed it's function '{callback.__name__}'!")
34                
35                return True
36    
37    return NormalForm()
def normal_form( title: str, items: List[nextcord.ui.item.Item], callback: Callable, author: GoldyBot.objects.member.Member, timeout=None, warning=False, warning_msg='🛑 Are you sure!') -> nextcord.ui.modal.Modal:
 7def normal_form(title:str, items:List[GoldyBot.nextcord.ui.Item], callback:Callable, author:GoldyBot.Member, timeout=None, 
 8        warning=False, warning_msg="🛑 Are you sure!") -> GoldyBot.nextcord.ui.Modal:
 9    """
10    Goldy Bot's normal form modal. (Only the command author can interact with interactions from this form!)
11    """
12
13    class NormalForm(GoldyBot.nextcord.ui.Modal):
14        def __init__(self):
15            super().__init__(title, timeout=timeout, auto_defer=True)
16
17            for item in items:
18                self.add_item(item)
19
20        async def callback(self, interaction: GoldyBot.nextcord.Interaction):
21            view = await GoldyBot.utility.views.confirm.yes_or_no(interaction)
22            
23            if warning:
24                message = await interaction.send(warning_msg, view=view)
25                await view.wait()
26                await message.delete()
27            else:
28                view.value = True
29
30            if view.value == True:
31                if not callback == None:
32                    await callback((lambda x: [item_.value for item_ in x])(items), interaction) # Execute callback
33
34                    GoldyBot.logging.log(f"[{MODULE_NAME}] Normal form modal for '{author.name}' executed it's function '{callback.__name__}'!")
35                
36                return True
37    
38    return NormalForm()

Goldy Bot's normal form modal. (Only the command author can interact with interactions from this form!)