#Can someone explain why does it work like that?

1 messages · Page 1 of 1 (latest)

quick anchor
#

class MainMenu(lightbulb.components.Menu):
    def __init__(self, empire_id: int, capital_planet_name: str, miru_client: miru.Client) -> None:
            self.main_text_select = self.add_text_select(options=select_options, on_select=self.callback, custom_id="main_text_select", placeholder="Wybierz kategorię")

            self.empire_id = empire_id
            self.capital_planet_name = capital_planet_name
            self.miru_client = miru_client
    
    
    async def callback(self, ctx: lightbulb.components.MenuContext) -> None:
        if ctx.selected_values_for(self.main_text_select)[0] == 'planets':
            menu = ChoosePlanetMenu(self.empire_id)
            menu.pagineted_text_select = menu.add(PaginatedTextSelect(menu=menu, item_options=await menu.create_options(), per_page=12, placeholder="Wybierz swoją planetę", custom_id="choose_planet_paginated_text_select"))
            await respond_with_menu(ctx, menu, menu.components)
            if menu.planet_name:
                menu = PlanetMenu(menu.planet_name)
                await respond_with_menu(ctx, menu=menu, components=await menu.components)
                ctx.stop_interacting()
        if ctx.selected_values_for(self.main_text_select)[0] == 'army':
             pass

#
import hikari
import lightbulb

from memory import memory_manager, EmpireState

class ChoosePlanetMenu(lightbulb.components.Menu):
    def __init__(self, empire_id: int, page: int = 0) -> None:
        self.page = page
        self.pagineted_text_select = None

        self.empire_id = empire_id
    
    # Automatycznie wyszkuane przez pagineted text select
    async def on_pagineted_select(self, ctx: lightbulb.components.MenuContext) -> None:
        # pobierz wybrane wartości
        choice = ctx.selected_values_for(self.pagineted_text_select)[0]
        self.planet_name = choice
        ctx.stop_interacting()


    async def create_options(self) -> list[lightbulb.components.TextSelectOption]:
        empire = await memory_manager.get(EmpireState, self.empire_id)
        options = []

        for planet in empire.planets:
            option = lightbulb.components.TextSelectOption(
                label=planet.name,
                value=planet.name,
                description=None,
                emoji=(hikari.CustomEmoji(id=planet.emoji_id, name=planet.name, is_animated=False) if planet.emoji_id else "🌌"),
            )
            options.append(option)
        return options

    components = hikari.impl.ContainerComponentBuilder(
            components=[
                hikari.impl.TextDisplayComponentBuilder(content="Never trust a time traveler with a toaster."),
            ]
        ),
#
import asyncio
import hikari
import lightbulb

from views.utils import respond_with_menu
from .buildings import BuildingsMenu
from memory import memory_manager, PlanetState
# from ..buttons.back_to_empire_screen import BackToEmpireScreenButton

select_options = [
    lightbulb.components.TextSelectOption(label='Budynki', emoji='🏗️', value='buildings')
]

class PlanetMenu(lightbulb.components.Menu):
    def __init__(self, planet_name: str) -> None:
        #   self.back_button = self.add(BackToEmpireScreenButton())
            self.planet_text_select = self.add_text_select(options=select_options, on_select=self.callback, custom_id="planet_text_select", placeholder="Wybierz sekcję")

            self.planet_name = planet_name
    
    async def callback(self, ctx: lightbulb.components.MenuContext) -> None:
        if ctx.selected_values_for(self.planet_text_select)[0] == 'buildings':
            menu = await BuildingsMenu.create(self.planet_name)
            await respond_with_menu(ctx, menu, components=await menu.components)
            ctx.stop_interacting()
    
    @property
    async def components(self):
        planet = await memory_manager.get(PlanetState, self.planet_name)
        text_component = hikari.impl.ContainerComponentBuilder(
            components=[
                hikari.impl.TextDisplayComponentBuilder(content=f"# {self.planet_name}"),
                hikari.impl.SectionComponentBuilder(
                    accessory=hikari.impl.ThumbnailComponentBuilder(
                        media=f"assets/planets/{planet.name}.png",
                    ),
                    components=[
                        hikari.impl.TextDisplayComponentBuilder(content=f"### Populacja\n{planet.population}\n### Max Manpower\n{planet.max_manpower}\n### Manpower\n{planet.manpower}"),
                    ]
                ),
            ]
        ),
        return text_component

#

I mean this moment when it says that something went wrong

wet mason
#

you are editing the message instead of respoding toit with a message edit

#

i have no clue what respond_with_menu is

quick anchor
#

oh I forgot about it sorry

#
async def respond_with_menu(ctx: lightbulb.components.MenuContext, menu, components):
            await ctx.respond(components=[*components, *menu], edit=True, flags=hikari.MessageFlag.EPHEMERAL)
            try:
                # Extend the timeout of this menu to account for the sub-menu
                ctx.extend_timeout(120)
                await menu.attach(ctx.client, timeout=120)
            except asyncio.TimeoutError:
                await ctx.respond(component=hikari.impl.TextDisplayComponentBuilder(content="Timed out"), edit=True)
wet mason
#

ok, then it looks like it might have been a discord bug where it didnt treat the update properly

#

not sure

#

because the components did update