misc(seautils): optimized showcode

This commit is contained in:
Seaswimmer 2024-05-13 21:11:15 -04:00
parent bb1aca83dd
commit 84d2728d3a
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -38,19 +38,16 @@ class SeaUtils(commands.Cog):
async def showcode(self, ctx: commands.Context, *, command: str):
"""Show the code for a particular command."""
try:
temp_content = []
content = []
for page in cf.pagify(
temp_content = cf.pagify(
text=inspect.getsource(self.bot.get_command(command).callback),
escape_mass_mentions=True,
page_length = 1977
):
temp_content.append(cf.box(page, lang='py'))
)
content = []
max_i = len(temp_content)
i = 1
for page in temp_content:
content.append(f"**Page {i}/{max_i}**\n{page}")
content.append(f"**Page {i}/{max_i}**\n{cf.box(page, lang='py')}")
i += 1
await SimpleMenu(content, disable_after_timeout=True, timeout=180).start(ctx)
except (OSError, AttributeError):