Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paginator interaction_check + remove inventory max_concurrency #284

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bot/cogs/commands/econ.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ async def inventory_boiler(self, ctx: Ctx, user: discord.User = None):
return True, user

@commands.group(name="inventory", aliases=["inv", "items"], case_insensitive=True)
@commands.max_concurrency(3, per=commands.BucketType.user, wait=False)
@commands.guild_only()
@commands.cooldown(2, 2, commands.BucketType.user)
async def inventory(self, ctx: Ctx):
Expand Down
20 changes: 15 additions & 5 deletions bot/cogs/core/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@


class PaginatorView(discord.ui.View):
def __init__(self, get_page, page_count, timeout):
def __init__(
self,
*,
author_id: int,
get_page: PAGE_EMBED_CALLABLE,
page_count: int,
timeout: float = 60.0,
):
super().__init__(timeout=timeout)

self._author_id = author_id
self._page = 0
self._page_count = page_count
self._get_page = get_page

@discord.ui.button(emoji="⏪", style=discord.ButtonStyle.gray)
async def interaction_check(self, interaction: discord.Interaction) -> bool:
return interaction.user.id == self._author_id

@discord.ui.button(emoji="⏪", style=discord.ButtonStyle.gray, disabled=True)
async def btn_first(self, interaction: discord.Interaction, button: discord.ui.Button):
self._page = 0
await self.update_message(interaction)

@discord.ui.button(emoji="⬅️", style=discord.ButtonStyle.gray)
@discord.ui.button(emoji="⬅️", style=discord.ButtonStyle.gray, disabled=True)
async def btn_back(self, interaction: discord.Interaction, button: discord.ui.Button):
self._page -= 1
await self.update_message(interaction)
Expand Down Expand Up @@ -89,12 +100,11 @@ async def paginate_embed(
return await ctx.reply(embed=embed, mention_author=False)

view = PaginatorView(
author_id=ctx.author.id,
get_page=lambda page: self._get_page(get_page, page),
page_count=page_count,
timeout=timeout,
)
view.children[0].disabled = True
view.children[1].disabled = True

message = await ctx.reply(embed=embed, mention_author=False, view=view)
view.message = message
Expand Down
Loading