Skip to content

Commit 8418211

Browse files
committed
Fixed pagination
1 parent 0536b78 commit 8418211

File tree

1 file changed

+8
-51
lines changed

1 file changed

+8
-51
lines changed

lib/pages/__init__.py

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,18 @@
22
from datetime import datetime
33

44
import discord
5-
from discord import Message
65

76
from lib.bot import Bot
87

98

109
class Pagination(discord.ui.View):
11-
"""
12-
Embed Paginator.
13-
Parameters:
14-
----------
15-
timeout: int
16-
How long the Paginator should timeout in, after the last interaction. (In seconds) (Overrides default of 60)
17-
PreviousButton: discord.ui.Button
18-
Overrides default previous button.
19-
NextButton: discord.ui.Button
20-
Overrides default next button.
21-
PageCounterStyle: discord.ButtonStyle
22-
Overrides default page counter style.
23-
InitialPage: int
24-
Page to start the pagination on.
25-
AllowExtInput: bool
26-
Overrides ability for 3rd party to interract with button.
27-
"""
28-
2910
ctx: discord.Interaction
3011

3112
def __init__(self, *,
3213
bot: Bot,
3314
timeout: int = 60,
34-
PreviousButton: discord.ui.Button = discord.ui.Button(emoji=discord.PartialEmoji(name="\U000025c0")),
35-
NextButton: discord.ui.Button = discord.ui.Button(emoji=discord.PartialEmoji(name="\U000025b6")),
36-
LastButton: discord.ui.Button = discord.ui.Button(emoji=discord.PartialEmoji(name="\U000023ed")),
37-
FirstButton: discord.ui.Button = discord.ui.Button(emoji=discord.PartialEmoji(name="\U000023ee")),
38-
PageCounterStyle: discord.ButtonStyle = discord.ButtonStyle.grey,
39-
InitialPage: int = 0,
4015
ephemeral: bool = False) -> None:
4116
self.bot = bot
42-
self.PageCounterStyle = PageCounterStyle
43-
self.InitialPage = InitialPage
4417
self.ephemeral = ephemeral
4518

4619
self.pages = None
@@ -62,18 +35,15 @@ async def start(self, ctx: discord.Interaction, pages: list[discord.Embed]):
6235
self.pages = pages
6336
self.total_page_count = len(pages)
6437
self.ctx: discord.Interaction = ctx
65-
self.current_page = self.InitialPage
38+
self.current_page = 0
6639
if self.total_page_count == 1:
6740
self.next.disabled = True
6841
self.previous.disabled = True
6942

70-
# self.PreviousButton.callback = self.previous_button_callback
71-
# self.NextButton.callback = self.next_button_callback
72-
73-
self.counter.label=f'{1}/{self.total_page_count}'
43+
self.counter.label = f'{1}/{self.total_page_count}'
7444

75-
self.message: Message = await self.bot.send(ctx, embed=self.pages[self.InitialPage], view=self,
76-
ephemeral=self.ephemeral)
45+
await self.bot.send(ctx, embed=self.pages[0], view=self,
46+
ephemeral=self.ephemeral)
7747

7848
def handle_buttons(self):
7949
self.first.disabled = self.current_page <= 1
@@ -129,20 +99,7 @@ async def last(self, interaction: discord.Interaction, button: discord.Button):
12999
self.counter.label = f"{self.current_page + 1}/{self.total_page_count}"
130100
await interaction.response.edit_message(embed=self.pages[self.current_page], view=self)
131101

132-
# async def next_button_callback(self, interaction: discord.Interaction):
133-
# if interaction.user != self.ctx.author and self.AllowExtInput:
134-
# embed = discord.Embed(description="You cannot control this pagination because you did not execute it.",
135-
# color=discord.Colour.red())
136-
# return await self.bot.send(self.ctx, embed=embed, ephemeral=True)
137-
# print('next')
138-
# await self.next()
139-
# await interaction.response.defer()
140-
#
141-
# async def previous_button_callback(self, interaction: discord.Interaction):
142-
# if interaction.user != self.ctx.author and self.AllowExtInput:
143-
# embed = discord.Embed(description="You cannot control this pagination because you did not execute it.",
144-
# color=discord.Colour.red())
145-
# return await self.bot.send(self.ctx, embed=embed, ephemeral=True)
146-
# print('previous')
147-
# await self.previous()
148-
# await interaction.response.defer()
102+
async def on_timeout(self) -> None:
103+
self.clear_items()
104+
self.add_item(self.counter)
105+
await self.ctx.edit_original_response(embed=self.pages[self.current_page], view=self)

0 commit comments

Comments
 (0)