Пример #1
0
 async def pagetest_prefix(self, ctx: commands.Context):
     """Demonstrates using the paginator with a prefix-based command."""
     paginator = pages.Paginator(pages=self.get_pages(), use_default_buttons=False)
     paginator.add_button(
         pages.PaginatorButton("prev", label="<", style=discord.ButtonStyle.green)
     )
     paginator.add_button(
         pages.PaginatorButton(
             "page_indicator", style=discord.ButtonStyle.gray, disabled=True
         )
     )
     paginator.add_button(
         pages.PaginatorButton("next", style=discord.ButtonStyle.green)
     )
     await paginator.send(ctx)
Пример #2
0
 async def pagetest_groups(self, ctx: discord.ApplicationContext):
     """Demonstrates using page groups to switch between different sets of pages."""
     page_buttons = [
         pages.PaginatorButton(
             "first", label="<<-", style=discord.ButtonStyle.green
         ),
         pages.PaginatorButton("prev", label="<-", style=discord.ButtonStyle.green),
         pages.PaginatorButton(
             "page_indicator", style=discord.ButtonStyle.gray, disabled=True
         ),
         pages.PaginatorButton("next", label="->", style=discord.ButtonStyle.green),
         pages.PaginatorButton("last", label="->>", style=discord.ButtonStyle.green),
     ]
     view = discord.ui.View()
     view.add_item(discord.ui.Button(label="Test Button, Does Nothing", row=2))
     view.add_item(
         discord.ui.Select(
             placeholder="Test Select Menu, Does Nothing",
             options=[
                 discord.SelectOption(
                     label="Example Option",
                     value="Example Value",
                     description="This menu does nothing!",
                 )
             ],
         )
     )
     page_groups = [
         pages.PageGroup(
             pages=self.get_pages(),
             label="Main Page Group",
             description="Main Pages for Main Things",
         ),
         pages.PageGroup(
             pages=[
                 "Second Set of Pages, Page 1",
                 "Second Set of Pages, Page 2",
                 "Look, it's group 2, page 3!",
             ],
             label="Second Page Group",
             description="Secondary Pages for Secondary Things",
             custom_buttons=page_buttons,
             use_default_buttons=False,
             custom_view=view,
         ),
     ]
     paginator = pages.Paginator(pages=page_groups, show_menu=True)
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #3
0
 async def pagetest_custom_view(self, ctx: discord.ApplicationContext):
     """Demonstrates passing a custom view to the paginator."""
     view = discord.ui.View()
     view.add_item(discord.ui.Button(label="Test Button, Does Nothing", row=1))
     view.add_item(
         discord.ui.Select(
             placeholder="Test Select Menu, Does Nothing",
             options=[
                 discord.SelectOption(
                     label="Example Option",
                     value="Example Value",
                     description="This menu does nothing!",
                 )
             ],
         )
     )
     paginator = pages.Paginator(pages=self.get_pages(), custom_view=view)
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #4
0
 async def pagetest_init(self, ctx: discord.ApplicationContext):
     """Demonstrates how to pass a list of custom buttons when creating the Paginator instance."""
     pagelist = [
         pages.PaginatorButton(
             "first", label="<<-", style=discord.ButtonStyle.green
         ),
         pages.PaginatorButton("prev", label="<-", style=discord.ButtonStyle.green),
         pages.PaginatorButton(
             "page_indicator", style=discord.ButtonStyle.gray, disabled=True
         ),
         pages.PaginatorButton("next", label="->", style=discord.ButtonStyle.green),
         pages.PaginatorButton("last", label="->>", style=discord.ButtonStyle.green),
     ]
     paginator = pages.Paginator(
         pages=self.get_pages(),
         show_disabled=True,
         show_indicator=True,
         use_default_buttons=False,
         custom_buttons=pagelist,
         loop_pages=True,
     )
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #5
0
 async def pagetest_custom_buttons(self, ctx: discord.ApplicationContext):
     """Demonstrates adding buttons to the paginator when the default buttons are not used."""
     paginator = pages.Paginator(
         pages=self.get_pages(),
         use_default_buttons=False,
         loop_pages=False,
         show_disabled=False,
     )
     paginator.add_button(
         pages.PaginatorButton(
             "prev", label="<", style=discord.ButtonStyle.green, loop_label="lst"
         )
     )
     paginator.add_button(
         pages.PaginatorButton(
             "page_indicator", style=discord.ButtonStyle.gray, disabled=True
         )
     )
     paginator.add_button(
         pages.PaginatorButton(
             "next", style=discord.ButtonStyle.green, loop_label="fst"
         )
     )
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #6
0
 async def pagetest_remove(self, ctx: discord.ApplicationContext):
     """Demonstrates using the default buttons, but removing some of them."""
     paginator = pages.Paginator(pages=self.get_pages())
     paginator.remove_button("first")
     paginator.remove_button("last")
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #7
0
 async def pagetest_timeout(self, ctx: discord.ApplicationContext):
     """Demonstrates having the buttons be disabled when the paginator view times out."""
     paginator = pages.Paginator(
         pages=self.get_pages(), disable_on_timeout=True, timeout=30
     )
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #8
0
 async def pagetest_strings(self, ctx: discord.ApplicationContext):
     """Demonstrates passing a list of strings as pages."""
     paginator = pages.Paginator(
         pages=["Page 1", "Page 2", "Page 3"], loop_pages=True
     )
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #9
0
 async def pagetest_loop(self, ctx: discord.ApplicationContext):
     """Demonstrates using the loop_pages option."""
     paginator = pages.Paginator(pages=self.get_pages(), loop_pages=True)
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #10
0
 async def pagetest_hidden(self, ctx: discord.ApplicationContext):
     """Demonstrates using the paginator with disabled buttons hidden."""
     paginator = pages.Paginator(pages=self.get_pages(), show_disabled=False)
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #11
0
 async def pagetest_default(self, ctx: discord.ApplicationContext):
     """Demonstrates using the paginator with the default options."""
     paginator = pages.Paginator(pages=self.get_pages())
     await paginator.respond(ctx.interaction, ephemeral=False)
Пример #12
0
 async def pagetest_target(self, ctx: commands.Context):
     """Demonstrates sending the paginator to a different target than where it was invoked (prefix-command version)."""
     paginator = pages.Paginator(pages=self.get_pages())
     await paginator.send(ctx, target=ctx.author, target_message="Paginator sent!")
Пример #13
0
 async def pagetest_target(self, ctx: discord.ApplicationContext):
     """Demonstrates sending the paginator to a different target than where it was invoked."""
     paginator = pages.Paginator(pages=self.get_pages())
     await paginator.respond(ctx.interaction, target=ctx.interaction.user)
Пример #14
0
 async def pagetest_update(self, ctx: discord.ApplicationContext):
     """Demonstrates updating an existing paginator instance with different options."""
     paginator = pages.Paginator(pages=self.get_pages(), show_disabled=False)
     await paginator.respond(ctx.interaction)
     await asyncio.sleep(3)
     await paginator.update(show_disabled=True, show_indicator=False)
Пример #15
0
    async def server_list(self, ctx):
        """ 봇이 들어가있는 모든 서버 리스트를 출력합니다. """
        page = 10
        # 페이지 지정값이 없고, 총 서버수가 10 이하일 경우
        if len(self.bot.guilds) <= page:
            embed = discord.Embed(
                title=get_lan(ctx.author.id,
                              "owners_server_list_title").format(
                                  BOT_NAME=self.bot.user.name),
                description=get_lan(ctx.author.id,
                                    "owners_server_list_description").format(
                                        server_count=len(self.bot.guilds),
                                        members_count=len(self.bot.users)),
                color=color_code)
            srvr = str()
            for i in self.bot.guilds:
                srvr = srvr + get_lan(
                    ctx.author.id, "owners_server_list_info").format(
                        server_name=i, server_members_count=i.member_count)
            embed.add_field(name="​", value=srvr, inline=False)
            embed.set_footer(text=BOT_NAME_TAG_VER)
            return await ctx.respond(embed=embed)

        # 서버수가 10개 이상일 경우

        # 총 페이지수 계산
        botguild = self.bot.guilds
        allpage = math.ceil(len(botguild) / page)

        pages_list = []
        for i in range(1, allpage + 1):
            srvr = ""
            numb = (page * i)
            numa = numb - page
            for a in range(numa, numb):
                try:
                    srvr = srvr + get_lan(
                        ctx.author.id, "owners_server_list_info").format(
                            server_name=botguild[a],
                            server_members_count=botguild[a].member_count)
                except IndexError:
                    break

            pages_list.append([
                discord.Embed(title=get_lan(ctx.author.id,
                                            "owners_server_list_title").format(
                                                BOT_NAME=self.bot.user.name),
                              description=get_lan(
                                  ctx.author.id,
                                  "owners_server_list_description2").format(
                                      server_count=len(self.bot.guilds),
                                      members_count=len(self.bot.users),
                                      servers=srvr),
                              color=color_code).
                set_footer(
                    text=
                    f"{get_lan(ctx.author.id, 'owners_page')} {str(i)}/{str(allpage)}\n{BOT_NAME_TAG_VER}"
                )
            ])
        paginator = pages.Paginator(pages=pages_list)
        await paginator.respond(ctx.interaction, ephemeral=False)
Пример #16
0
    async def list(self, ctx, *, arg: str = None):
        """ Load playlists or play the music from that playlist! """
        anilistpath = "musicbot/anilist"

        # Files list
        files = []
        for file in os.listdir(anilistpath):
            if file.endswith(".txt"):
                files.append(file.replace(".txt", ""))
        # Sort
        files = sorted(files)
        # 재생목록 총 개수
        if arg == "-a":
            embed=discord.Embed(title=get_lan(ctx.author.id, "music_len_list"), description=get_lan(ctx.author.id, "music_len_list").format(files_len=len(files)), color=color_code)
            embed.set_footer(text=BOT_NAME_TAG_VER)
            return await ctx.respond(embed=embed)

        embed=discord.Embed(title=get_lan(ctx.author.id, "music_list_finding"), color=color_code)
        embed.set_footer(text=BOT_NAME_TAG_VER)
        playmsg = await ctx.respond(embed=embed)

        if arg is not None:
            # List play
            try:
                f = open(f"{anilistpath}/{arg}.txt", 'r')
                list_str = f.read()
                f.close()

            except Exception:
                embed=discord.Embed(title=get_lan(ctx.author.id, "music_list_can_not_find"), description=arg, color=color_code)
                embed.set_footer(text=BOT_NAME_TAG_VER)
                return await playmsg.edit_original_message(embed=embed)

            player = self.bot.lavalink.player_manager.get(ctx.guild.id)
            music_list = list_str.split('\n')
            music_list_process = []
            for music in music_list:
                if music != "":
                    music_list_process.append(music)
            music_list = music_list_process

            # Play music list
            info, playmusic, passmusic = await play_list(player, ctx, music_list, playmsg)

            embed=discord.Embed(title=get_lan(ctx.author.id, "music_play_music"), description='', color=color_code)
            embed.add_field(name=get_lan(ctx.author.id, "music_played_music"), value = playmusic, inline=False)
            embed.add_field(name=get_lan(ctx.author.id, "music_can_not_find_music"), value = passmusic, inline=False)
            embed.set_thumbnail(url="http://img.youtube.com/vi/%s/0.jpg" %(info['identifier']))
            embed.set_footer(text=BOT_NAME_TAG_VER)
            await playmsg.edit_original_message(embed=embed)
            if not player.is_playing:
                await player.play()

        # 리스트 목록
        else:
            # 페이지당 띄울 리스트 개수
            page = 15
            # 총 리스트 수가 page개 이하일 경우
            if len(files) <= page:
                embed=discord.Embed(title=get_lan(ctx.author.id, "music_playlist_list"), description="\n".join(file), color=color_code)
                embed.set_footer(text=BOT_NAME_TAG_VER)
                return await playmsg.edit_original_message(embed=embed)

            # 총 페이지수 계산
            allpage = math.ceil(len(files) / page)

            pages_list = []

            for i in range(1, allpage+1):
                filelist = ""
                numb = (page * i)
                numa = numb - page
                for a in range(numa, numb):
                    try:
                        filelist = filelist + f"{files[a]}\n"
                    except IndexError:
                        break
                pages_list.append(
                    [
                        discord.Embed(title=get_lan(ctx.author.id, "music_playlist_list"), description=filelist, color=color_code).set_footer(text=f"{get_lan(ctx.author.id, 'music_page')} {str(i)}/{str(allpage)}\n{BOT_NAME_TAG_VER}")
                    ]
                )
            paginator = pages.Paginator(pages=pages_list)
            await paginator.respond(ctx.interaction, ephemeral=False)