Skip to content

Commit b8df285

Browse files
committed
improve multi-page pagination dropdown and titles
1 parent 5a32966 commit b8df285

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

cogs/modmail.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,8 +1637,6 @@ async def contact(
16371637
async def blocked(self, ctx):
16381638
"""Retrieve a list of blocked users."""
16391639

1640-
embeds = [discord.Embed(title="Blocked Users", color=self.bot.main_color, description="")]
1641-
16421640
roles = []
16431641
users = []
16441642
now = ctx.message.created_at
@@ -1700,43 +1698,54 @@ async def blocked(self, ctx):
17001698
if role:
17011699
roles.append((role.mention, reason))
17021700

1701+
user_embeds = [discord.Embed(title="Blocked Users", color=self.bot.main_color, description="")]
1702+
17031703
if users:
1704-
embed = embeds[0]
1704+
embed = user_embeds[0]
17051705

17061706
for mention, reason in users:
17071707
line = mention + f" - {reason or 'No Reason Provided'}\n"
17081708
if len(embed.description) + len(line) > 2048:
17091709
embed = discord.Embed(
1710-
title="Blocked Users (Continued)",
1710+
title="Blocked Users",
17111711
color=self.bot.main_color,
17121712
description=line,
17131713
)
1714-
embeds.append(embed)
1714+
user_embeds.append(embed)
17151715
else:
17161716
embed.description += line
17171717
else:
1718-
embeds[0].description = "Currently there are no blocked users."
1718+
user_embeds[0].description = "Currently there are no blocked users."
1719+
1720+
if len(user_embeds) > 1:
1721+
for n, em in enumerate(user_embeds):
1722+
em.title = f'{em.title} [{n + 1}]'
17191723

1720-
embeds.append(discord.Embed(title="Blocked Roles", color=self.bot.main_color, description=""))
1724+
role_embeds = [discord.Embed(title="Blocked Roles", color=self.bot.main_color, description="")]
17211725

17221726
if roles:
1723-
embed = embeds[-1]
1727+
embed = role_embeds[-1]
17241728

17251729
for mention, reason in roles:
17261730
line = mention + f" - {reason or 'No Reason Provided'}\n"
17271731
if len(embed.description) + len(line) > 2048:
1732+
role_embeds[-1].set_author()
17281733
embed = discord.Embed(
1729-
title="Blocked Roles (Continued)",
1734+
title="Blocked Roles",
17301735
color=self.bot.main_color,
17311736
description=line,
17321737
)
1733-
embeds.append(embed)
1738+
role_embeds.append(embed)
17341739
else:
17351740
embed.description += line
17361741
else:
1737-
embeds[-1].description = "Currently there are no blocked roles."
1742+
role_embeds[-1].description = "Currently there are no blocked roles."
17381743

1739-
session = EmbedPaginatorSession(ctx, *embeds)
1744+
if len(role_embeds) > 1:
1745+
for n, em in enumerate(role_embeds):
1746+
em.title = f'{em.title} [{n + 1}]'
1747+
1748+
session = EmbedPaginatorSession(ctx, *user_embeds, *role_embeds)
17401749

17411750
await session.run()
17421751

cogs/utility.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ async def format_cog_help(self, cog, *, no_cog=False):
8989

9090
embed.add_field(name="Commands", value=format_ or "No commands.")
9191

92-
continued = " (Continued)" if embeds else ""
9392
name = cog.qualified_name + " - Help" if not no_cog else "Miscellaneous Commands"
94-
embed.set_author(name=name + continued, icon_url=bot.user.display_avatar.url)
93+
embed.set_author(name=name, icon_url=bot.user.display_avatar.url)
9594

9695
embed.set_footer(
9796
text=f'Type "{prefix}{self.command_attrs["name"]} command" '
9897
"for more info on a specific command."
9998
)
10099
embeds.append(embed)
100+
101+
if len(embeds) > 1:
102+
for n, em in enumerate(embeds):
103+
em.set_author(name=f'{em.author.name} [{n + 1}]', icon_url=em.author.icon_url)
104+
101105
return embeds
102106

103107
def process_help_msg(self, help_: str):

core/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ def format_description(i, names):
397397
def trigger_typing(func):
398398
@functools.wraps(func)
399399
async def wrapper(self, ctx: commands.Context, *args, **kwargs):
400-
async with ctx.typing():
401-
return await func(self, ctx, *args, **kwargs)
400+
await ctx.typing()
401+
return await func(self, ctx, *args, **kwargs)
402402

403403
return wrapper
404404

0 commit comments

Comments
 (0)