From bb1aca83dd58f240864d8ebfc5c481ba5fb8b531 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 13 May 2024 21:09:02 -0400 Subject: [PATCH] feat(seautils): added some more functionality to showcode --- seautils/seautils.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/seautils/seautils.py b/seautils/seautils.py index c59d089..374d28e 100644 --- a/seautils/seautils.py +++ b/seautils/seautils.py @@ -7,9 +7,11 @@ import inspect +from discord import Embed from redbot.core import commands from redbot.core.bot import Red from redbot.core.utils import chat_formatting as cf +from redbot.core.utils.views import SimpleMenu class SeaUtils(commands.Cog): @@ -36,7 +38,21 @@ class SeaUtils(commands.Cog): async def showcode(self, ctx: commands.Context, *, command: str): """Show the code for a particular command.""" try: - content = cf.pagify(inspect.getsource(self.bot.get_command(command).callback)) - await ctx.send_interactive(content, box_lang='py') + temp_content = [] + content = [] + for page in 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')) + + max_i = len(temp_content) + i = 1 + for page in temp_content: + content.append(f"**Page {i}/{max_i}**\n{page}") + i += 1 + await SimpleMenu(content, disable_after_timeout=True, timeout=180).start(ctx) except (OSError, AttributeError): - await ctx.send("Command not found.") + embed = Embed(title="Command not found!", color=await ctx.embed_color()) + await ctx.send(embed=embed, reference=ctx.message.to_reference(fail_if_not_exists=False))