2
2
from datetime import datetime
3
3
4
4
import discord
5
- from discord import Message
6
5
7
6
from lib .bot import Bot
8
7
9
8
10
9
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
-
29
10
ctx : discord .Interaction
30
11
31
12
def __init__ (self , * ,
32
13
bot : Bot ,
33
14
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 ,
40
15
ephemeral : bool = False ) -> None :
41
16
self .bot = bot
42
- self .PageCounterStyle = PageCounterStyle
43
- self .InitialPage = InitialPage
44
17
self .ephemeral = ephemeral
45
18
46
19
self .pages = None
@@ -62,18 +35,15 @@ async def start(self, ctx: discord.Interaction, pages: list[discord.Embed]):
62
35
self .pages = pages
63
36
self .total_page_count = len (pages )
64
37
self .ctx : discord .Interaction = ctx
65
- self .current_page = self . InitialPage
38
+ self .current_page = 0
66
39
if self .total_page_count == 1 :
67
40
self .next .disabled = True
68
41
self .previous .disabled = True
69
42
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 } '
74
44
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 )
77
47
78
48
def handle_buttons (self ):
79
49
self .first .disabled = self .current_page <= 1
@@ -129,20 +99,7 @@ async def last(self, interaction: discord.Interaction, button: discord.Button):
129
99
self .counter .label = f"{ self .current_page + 1 } /{ self .total_page_count } "
130
100
await interaction .response .edit_message (embed = self .pages [self .current_page ], view = self )
131
101
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