Exemplo n.º 1
0
        async def update_data(menu):
            if menu.button_pressed(reload):
                response = await make_request()

                p = Page(title='Awesome Data',
                         description='We can reload this data.')
                p.add_field(name='Random Updating Integer',
                            value=response.get('random_data'))
                await menu.output.edit(embed=p.as_safe_embed())

            elif menu.button_pressed(close):
                await menu.close()
Exemplo n.º 2
0
    def create_menu(self, ctx: commands.Context, name: str):
        guild_id = ctx.guild.id
        guildcollections = [
            extract_name(x) for x in database.db.list_collection_names()
            if extract_id(x) == str(guild_id)
        ]
        if name not in guildcollections:
            return None
        else:
            menu = PaginatedMenu(ctx)
            all_pages = {}

            collection_name = f"{guild_id}_{name}"
            entries_by_day = self.get_entries_by_day(collection_name)

            for i in range(7):
                day_entries = entries_by_day[i]
                x = "\n".join([
                    f"{num + 1}) " + (" ".join(
                        list(
                            map(
                                str,
                                list([
                                    entry[key]
                                    for key in entry if key != "link"
                                ])[2:])))).replace("\n", " ")
                    for num, entry in enumerate(day_entries)
                ])
                if x == "" or None or type(x) != str:
                    break
                page_i = Page(title=f"Page {i + 1}",
                              description=f"Slots for {TimeTable.days[i]}")
                page_i.add_field(name=TimeTable.days[i], value=x)

                all_pages[i] = page_i.as_safe_embed()

            menu.add_pages(list(all_pages.values()))
            menu.hide_cancel_button()
            menu.show_skip_buttons()
            menu.set_timeout(120)
            menu.allow_multisession()

            return menu