ShinshiDevs / aurum-hikari

A flexible framework for handling commands and components.
https://shinshidevs.github.io/aurum-hikari/
MIT License
5 stars 1 forks source link

Message Components #17

Open stefanlight8 opened 2 months ago

stefanlight8 commented 2 months ago

https://discord.com/developers/docs/interactions/message-components#message-components

stefanlight8 commented 1 month ago

And so, let's think about it. Initially, the general concept should be that components always have a parent (command or view) and should be initialized through interaction.

Little concept with command

from aurum.context import InteractionContext
from aurum.commands import SlashCommand
from aurum.components import Button, decorators  
# or from aurum.components.decorators import button

class ButtonCommand(SlashCommand):
    def __init__(self) -> None:
        super().__init__("button", description="Get button")

     @decorators.button(label="Magic", emoji="🪄")  # or @button(label=...
     async def magic_button(self, context: InteractionContext, button: Button) -> None:
          await context.create_response("Woah, you clicked that button!", ephemeral=True)

      async def callback(self, context: InteractionContext) -> None:
          await context.create_response(components=[context.init_component(self.magic_button)])  # doubtful, but OK

Furthermore, the concept for objects is likely to be similar to that of commands, with a get_builder function. I think it would be possible to return these to commands by implementing a proxy (CommandBuilder), thus avoiding unnecessary complexity in the code.

It's difficult.

stefanlight8 commented 1 month ago

we can command components initialize through metaclass automatically and just creating response with component=self.magic_button I think, but that will be little difficult and add some complexity :b but with the view – all the same way, because it's can't be an independent object without interaction.

stefanlight8 commented 1 month ago

beh

from aurum.context import InteractionContext
from aurum.commands import SlashCommand
from aurum.components import View, Button, decorators  

class ButtonView(View):
    @decorators.button(label="Magic", emoji="🪄")
    async def magic_button(self, context: InteractionContext, button: Button) -> None:
         await context.create_response("Woah, you clicked that button!", ephemeral=True)

class ButtonCommand(SlashCommand):
    def __init__(self) -> None:
        super().__init__("button", description="Get button")

      async def callback(self, context: InteractionContext) -> None:
          await context.create_response(components=context.init_view(ButtonView()))