feat(seautils): added some more functionality to showcode

This commit is contained in:
Seaswimmer 2024-05-13 21:09:02 -04:00
parent 59848fe857
commit bb1aca83dd
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -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))