Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
- redbot/core/_settings_caches.py
- redbot/core/_sharedlibdeprecation.py
- redbot/core/utils/_internal_utils.py
- redbot/ext_cogs/__init__.py
# Tests
- redbot/pytest/__init__.py
- redbot/pytest/cog_manager.py
Expand Down
9 changes: 0 additions & 9 deletions redbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,3 @@ def _early_init():
module="discord",
message="'audioop' is deprecated and slated for removal",
)
# DEP-WARN - will need a fix before Python 3.12 support
#
# DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead
_warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
module="importlib",
message=r"the load_module\(\) method is deprecated and slated for removal",
)
69 changes: 26 additions & 43 deletions redbot/cogs/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,25 +1096,6 @@ async def _ask_for_cog_reload(

await ctx.invoke(ctx.bot.get_cog("Core").reload, *updated_cognames)

def cog_name_from_instance(self, instance: object) -> str:
"""Determines the cog name that Downloader knows from the cog instance.

Probably.

Parameters
----------
instance : object
The cog instance.

Returns
-------
str
The name of the cog according to Downloader..

"""
splitted = instance.__module__.split(".")
return splitted[0]

@commands.command()
async def findcog(self, ctx: commands.Context, command_name: str) -> None:
"""Find which cog a command comes from.
Expand All @@ -1136,8 +1117,21 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None:

# Check if in installed cogs
cog = command.cog
if cog:
cog_pkg_name = self.cog_name_from_instance(cog)
if not cog:
await ctx.send(_("This command is not provided by a cog."))
return

try:
top_level_package, subpackage, cog_pkg_name, *__ = cog.__module__.split(".", 3)
if top_level_package != "redbot":
raise ValueError
except ValueError:
await ctx.send(_("The cog package for the given command could not be determined."))
return

cog_name = cog.__class__.__name__
repo_branch = None
if subpackage == "ext_cogs":
installed, cog_installable = await _downloader.is_installed(cog_pkg_name)
if installed:
made_by = (
Expand All @@ -1155,25 +1149,18 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None:
if cog_installable.repo is None
else cog_installable.repo.name
)
repo_branch = cog_installable.repo and cog_installable.repo.branch
cog_pkg_name = cog_installable.name
elif cog.__module__.startswith("redbot."): # core commands or core cog
made_by = "Cog Creators"
repo_url = "https://github.com/Cog-Creators/Red-DiscordBot"
module_fragments = cog.__module__.split(".")
if module_fragments[1] == "core":
cog_pkg_name = "N/A - Built-in commands"
else:
cog_pkg_name = module_fragments[2]
repo_name = "Red-DiscordBot"
else: # assume not installed via downloader
made_by = _("Unknown")
repo_url = _("None - this cog wasn't installed via downloader")
repo_name = _("Unknown")
cog_name = cog.__class__.__name__
else:
msg = _("This command is not provided by a cog.")
await ctx.send(msg)
return
else: # core commands or core cog
made_by = "Cog Creators"
repo_url = "https://github.com/Cog-Creators/Red-DiscordBot"
if subpackage == "core":
cog_pkg_name = "N/A - Built-in commands"
repo_name = "Red-DiscordBot"

if await ctx.embed_requested():
embed = discord.Embed(color=(await ctx.embed_colour()))
Expand All @@ -1183,10 +1170,8 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None:
embed.add_field(name=_("Made by:"), value=made_by, inline=False)
embed.add_field(name=_("Repo name:"), value=repo_name, inline=False)
embed.add_field(name=_("Repo URL:"), value=repo_url, inline=False)
if installed and cog_installable.repo is not None and cog_installable.repo.branch:
embed.add_field(
name=_("Repo branch:"), value=cog_installable.repo.branch, inline=False
)
if repo_branch:
embed.add_field(name=_("Repo branch:"), value=repo_branch, inline=False)
await ctx.send(embed=embed)

else:
Expand All @@ -1205,10 +1190,8 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None:
repo_url=repo_url,
repo_name=repo_name,
)
if installed and cog_installable.repo is not None and cog_installable.repo.branch:
msg += _("Repo branch: {branch_name}\n").format(
branch_name=cog_installable.repo.branch
)
if repo_branch:
msg += _("Repo branch: {branch_name}\n").format(branch_name=repo_branch)
await ctx.send(box(msg))

@staticmethod
Expand Down
Loading
Loading