-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
87 lines (78 loc) · 3.23 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import discord
import typing
from discord.ext import commands
class Paginator(discord.ui.View):
def __init__(self, paginator, context: commands.Context, **kwargs):
super().__init__(timeout=30)
self.paginator: discord.ext.commands.Paginator = paginator
self.context: commands.Context = context
self.author: typing.Union[discord.User, discord.Member] = context.author
self.pages: int = len(paginator.pages)
self.page: int = 1
_embed = discord.Embed(colour=discord.Color.red())
self.embed: discord.Embed = kwargs.pop("embed", _embed)
self._original_embed_title = self.embed.title
self.embed.title = f"{self._original_embed_title} [{self.page}/{self.pages}]"
async def update_message(self, interaction):
self.page_number.label = self.page
self.embed.title = f"{self._original_embed_title} [{self.page}/{self.pages}]"
self.embed.description = self.paginator.pages[self.page - 1]
await interaction.message.edit(embed=self.embed, view=self)
# Buttons
@discord.ui.button(label="First Page", style=discord.ButtonStyle.secondary)
async def first_page(
self, button: discord.ui.Button, interaction: discord.Interaction
):
if interaction.user.id != self.author.id:
return await interaction.response.send_message(
"This is not for you", ephemeral=True
)
if self.page == 1:
return
self.page = 1
await self.update_message(interaction)
@discord.ui.button(style=discord.ButtonStyle.secondary, emoji="◀️")
async def previous_page(
self, button: discord.ui.Button, interaction: discord.Interaction
):
if interaction.user.id != self.author.id:
return await interaction.response.send_message(
"This is not for you", ephemeral=True
)
page = self.page
if page == 1:
self.page = self.pages
else:
self.page -= 1
await self.update_message(interaction)
@discord.ui.button(label=1, style=discord.ButtonStyle.primary)
async def page_number(
self, button: discord.ui.Button, interaction: discord.Interaction
):
return
@discord.ui.button(style=discord.ButtonStyle.secondary, emoji="▶️")
async def next_page(
self, button: discord.ui.Button, interaction: discord.Interaction
):
if interaction.user.id != self.author.id:
return await interaction.response.send_message(
"This is not for you", ephemeral=True
)
page = self.page
if page == self.pages:
self.page = 1
else:
self.page += 1
await self.update_message(interaction)
@discord.ui.button(label="Last Page", style=discord.ButtonStyle.secondary)
async def last_page(
self, button: discord.ui.Button, interaction: discord.Interaction
):
if interaction.user.id != self.author.id:
return await interaction.response.send_message(
"This is not for you", ephemeral=True
)
if self.page == self.pages:
return
self.page = self.pages
await self.update_message(interaction)