[Downloader] Embed version of findcog (#3965)

This commit is contained in:
Vexed 2020-06-18 21:37:46 +01:00 committed by GitHub
parent 4e890814ff
commit 1cf8308d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1351,49 +1351,6 @@ class Downloader(commands.Cog):
await ctx.invoke(ctx.bot.get_cog("Core").reload, *updated_cognames) await ctx.invoke(ctx.bot.get_cog("Core").reload, *updated_cognames)
def format_findcog_info(
self, command_name: str, cog_installable: Union[Installable, object] = None
) -> str:
"""Format a cog's info for output to discord.
Parameters
----------
command_name : str
Name of the command which belongs to the cog.
cog_installable : `Installable` or `object`
Can be an `Installable` instance or a Cog instance.
Returns
-------
str
A formatted message for the user.
"""
if isinstance(cog_installable, Installable):
is_installable = True
made_by = ", ".join(cog_installable.author) or _("Missing from info.json")
repo_url = (
_("Missing from installed repos")
if cog_installable.repo is None
else cog_installable.repo.clean_url
)
cog_name = cog_installable.name
else:
is_installable = False
made_by = "26 & co."
repo_url = "https://github.com/Cog-Creators/Red-DiscordBot"
cog_name = cog_installable.__class__.__name__
msg = _(
"Command: {command}\nCog name: {cog}\nMade by: {author}\nRepo: {repo_url}\n"
).format(command=command_name, author=made_by, repo_url=repo_url, cog=cog_name)
if is_installable 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
)
return msg
def cog_name_from_instance(self, instance: object) -> str: def cog_name_from_instance(self, instance: object) -> str:
"""Determines the cog name that Downloader knows from the cog instance. """Determines the cog name that Downloader knows from the cog instance.
@ -1431,13 +1388,45 @@ class Downloader(commands.Cog):
cog_name = self.cog_name_from_instance(cog) cog_name = self.cog_name_from_instance(cog)
installed, cog_installable = await self.is_installed(cog_name) installed, cog_installable = await self.is_installed(cog_name)
if installed: if installed:
msg = self.format_findcog_info(command_name, cog_installable) is_installable = True
made_by = humanize_list(cog_installable.author) or _("Missing from info.json")
repo_url = (
_("Missing from installed repos")
if cog_installable.repo is None
else cog_installable.repo.clean_url
)
cog_name = cog_installable.name
else: else:
# Assume it's in a base cog # Assume it's in a base cog
msg = self.format_findcog_info(command_name, cog) is_installable = False
made_by = "26 & co."
repo_url = "https://github.com/Cog-Creators/Red-DiscordBot"
cog_name = cog.__class__.__name__
else: else:
msg = _("This command is not provided by a cog.") msg = _("This command is not provided by a cog.")
await ctx.send(msg)
return
if await ctx.embed_requested():
embed = discord.Embed(color=(await ctx.embed_colour()))
embed.add_field(name=_("Command:"), value=command_name, inline=False)
embed.add_field(name=_("Cog Name:"), value=cog_name, inline=False)
embed.add_field(name=_("Made by:"), value=made_by, inline=False)
embed.add_field(name=_("Repo URL:"), value=repo_url, inline=False)
if is_installable 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
)
await ctx.send(embed=embed)
else:
msg = _(
"Command: {command}\nCog name: {cog}\nMade by: {author}\nRepo URL: {repo_url}\n"
).format(command=command_name, author=made_by, repo_url=repo_url, cog=cog_name)
if is_installable 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
)
await ctx.send(box(msg)) await ctx.send(box(msg))
@staticmethod @staticmethod