Update paginator.py
This commit is contained in:
parent
7228ef64a5
commit
c74fd90a9c
@ -9,16 +9,17 @@ class FirstPageComps(View):
|
|||||||
async def interaction_check(self, interaction: Interaction):
|
async def interaction_check(self, interaction: Interaction):
|
||||||
return interaction.user.id == self.author_id
|
return interaction.user.id == self.author_id
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, disabled=True, label='Left')
|
@discord.ui.button(style=ButtonStyle.primary, disabled=True, label="Left")
|
||||||
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "left"
|
self.value = "left"
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, label='Right')
|
@discord.ui.button(style=ButtonStyle.primary, label="Right")
|
||||||
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "right"
|
self.value = "right"
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
# The middle pages have both left and right buttons available
|
# The middle pages have both left and right buttons available
|
||||||
class MiddlePageComps(View):
|
class MiddlePageComps(View):
|
||||||
def __init__(self, author_id: int):
|
def __init__(self, author_id: int):
|
||||||
@ -29,16 +30,17 @@ class MiddlePageComps(View):
|
|||||||
async def interaction_check(self, interaction: Interaction):
|
async def interaction_check(self, interaction: Interaction):
|
||||||
return interaction.user.id == self.author_id
|
return interaction.user.id == self.author_id
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, label='Left')
|
@discord.ui.button(style=ButtonStyle.primary, label="Left")
|
||||||
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "left"
|
self.value = "left"
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, label='Right')
|
@discord.ui.button(style=ButtonStyle.primary, label="Right")
|
||||||
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "right"
|
self.value = "right"
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
# The last page has the right button disabled, because there's no right page to go to anymore...
|
# The last page has the right button disabled, because there's no right page to go to anymore...
|
||||||
class LastPageComps(View):
|
class LastPageComps(View):
|
||||||
def __init__(self, author_id: int):
|
def __init__(self, author_id: int):
|
||||||
@ -49,12 +51,12 @@ class LastPageComps(View):
|
|||||||
async def interaction_check(self, interaction: Interaction):
|
async def interaction_check(self, interaction: Interaction):
|
||||||
return interaction.user.id == self.author_id
|
return interaction.user.id == self.author_id
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, label='Left')
|
@discord.ui.button(style=ButtonStyle.primary, label="Left")
|
||||||
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
async def left(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "left"
|
self.value = "left"
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
@discord.ui.button(style=ButtonStyle.primary, label='Right', disabled=True)
|
@discord.ui.button(style=ButtonStyle.primary, label="Right", disabled=True)
|
||||||
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
async def right(self, button: discord.ui.Button, interaction: Interaction):
|
||||||
self.value = "right"
|
self.value = "right"
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -73,7 +75,7 @@ async def paginate(ctx, pages: list, title: str = None):
|
|||||||
|
|
||||||
embed = first_page
|
embed = first_page
|
||||||
if title:
|
if title:
|
||||||
embed.title = f'{title} | Page {index+1}/{total_pages}'
|
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
||||||
|
|
||||||
view = FirstPageComps(ctx.author.id)
|
view = FirstPageComps(ctx.author.id)
|
||||||
# Here we send the message with the view of the first page and the FirstPageComps buttons
|
# Here we send the message with the view of the first page and the FirstPageComps buttons
|
||||||
@ -89,17 +91,25 @@ async def paginate(ctx, pages: list, title: str = None):
|
|||||||
if view.value == "right":
|
if view.value == "right":
|
||||||
index += 1
|
index += 1
|
||||||
current_page = pages[index]
|
current_page = pages[index]
|
||||||
view = MiddlePageComps(ctx.author.id) if current_page != last_page else LastPageComps(ctx.author.id)
|
view = (
|
||||||
|
MiddlePageComps(ctx.author.id)
|
||||||
|
if current_page != last_page
|
||||||
|
else LastPageComps(ctx.author.id)
|
||||||
|
)
|
||||||
embed = current_page
|
embed = current_page
|
||||||
if title:
|
if title:
|
||||||
embed.title = f'{title} | Page {index+1}/{total_pages}'
|
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
||||||
|
|
||||||
elif view.value == "left":
|
elif view.value == "left":
|
||||||
index -= 1
|
index -= 1
|
||||||
current_page = pages[index]
|
current_page = pages[index]
|
||||||
view = MiddlePageComps(ctx.author.id) if current_page != first_page else FirstPageComps(ctx.author.id)
|
view = (
|
||||||
|
MiddlePageComps(ctx.author.id)
|
||||||
|
if current_page != first_page
|
||||||
|
else FirstPageComps(ctx.author.id)
|
||||||
|
)
|
||||||
embed = current_page
|
embed = current_page
|
||||||
if title:
|
if title:
|
||||||
embed.title = f'{title} | Page {index+1}/{total_pages}'
|
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
||||||
|
|
||||||
await msg.edit(embed=embed, view=view)
|
await msg.edit(embed=embed, view=view)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user