2024-05-13 19:26:13 -04:00
|
|
|
# _____ _
|
|
|
|
# / ____| (_)
|
|
|
|
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
|
|
|
|
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
|
|
|
|
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
|
|
|
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
|
|
|
|
|
|
|
import inspect
|
2024-05-13 21:12:51 -04:00
|
|
|
import operator
|
2024-05-13 19:26:13 -04:00
|
|
|
|
2024-05-13 21:09:02 -04:00
|
|
|
from discord import Embed
|
2024-05-13 19:26:13 -04:00
|
|
|
from redbot.core import commands
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
from redbot.core.utils import chat_formatting as cf
|
2024-05-13 21:09:02 -04:00
|
|
|
from redbot.core.utils.views import SimpleMenu
|
2024-05-13 19:26:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
class SeaUtils(commands.Cog):
|
|
|
|
"""A collection of random utilities."""
|
|
|
|
|
|
|
|
__author__ = ["SeaswimmerTheFsh"]
|
|
|
|
__version__ = "1.0.0"
|
|
|
|
|
|
|
|
def __init__(self, bot: Red):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
def format_help_for_context(self, ctx: commands.Context) -> str:
|
|
|
|
pre_processed = super().format_help_for_context(ctx) or ""
|
|
|
|
n = "\n" if "\n\n" not in pre_processed else ""
|
|
|
|
text = [
|
|
|
|
f"{pre_processed}{n}",
|
|
|
|
f"Cog Version: **{self.__version__}**",
|
|
|
|
f"Author: {cf.humanize_list(self.__author__)}"
|
|
|
|
]
|
|
|
|
return "\n".join(text)
|
|
|
|
|
2024-05-13 20:22:13 -04:00
|
|
|
@commands.command(aliases=["source", "src", "code", "showsource"])
|
2024-05-13 19:26:13 -04:00
|
|
|
@commands.is_owner()
|
|
|
|
async def showcode(self, ctx: commands.Context, *, command: str):
|
|
|
|
"""Show the code for a particular command."""
|
|
|
|
try:
|
2024-05-13 21:11:15 -04:00
|
|
|
temp_content = cf.pagify(
|
2024-05-13 21:09:02 -04:00
|
|
|
text=inspect.getsource(self.bot.get_command(command).callback),
|
|
|
|
escape_mass_mentions=True,
|
|
|
|
page_length = 1977
|
2024-05-13 21:11:15 -04:00
|
|
|
)
|
|
|
|
content = []
|
2024-05-13 21:12:51 -04:00
|
|
|
max_i = operator.length_hint(temp_content)
|
2024-05-13 21:09:02 -04:00
|
|
|
i = 1
|
|
|
|
for page in temp_content:
|
2024-05-13 21:11:15 -04:00
|
|
|
content.append(f"**Page {i}/{max_i}**\n{cf.box(page, lang='py')}")
|
2024-05-13 21:09:02 -04:00
|
|
|
i += 1
|
|
|
|
await SimpleMenu(content, disable_after_timeout=True, timeout=180).start(ctx)
|
2024-05-13 20:17:00 -04:00
|
|
|
except (OSError, AttributeError):
|
2024-05-13 21:09:02 -04:00
|
|
|
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))
|