mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
enhance(downloader): pagify any output that might be too long (#3388)
This commit is contained in:
parent
a203fe34cf
commit
67fbcb1b4a
@ -418,6 +418,11 @@ class Downloader(commands.Cog):
|
|||||||
elif target.is_file():
|
elif target.is_file():
|
||||||
os.remove(str(target))
|
os.remove(str(target))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def send_pagified(target: discord.abc.Messageable, content: str) -> None:
|
||||||
|
for page in pagify(content):
|
||||||
|
await target.send(page)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def pipinstall(self, ctx: commands.Context, *deps: str) -> None:
|
async def pipinstall(self, ctx: commands.Context, *deps: str) -> None:
|
||||||
@ -550,7 +555,7 @@ class Downloader(commands.Cog):
|
|||||||
if failed:
|
if failed:
|
||||||
message += "\n" + self.format_failed_repos(failed)
|
message += "\n" + self.format_failed_repos(failed)
|
||||||
|
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@ -596,12 +601,13 @@ class Downloader(commands.Cog):
|
|||||||
tuple(map(inline, libnames))
|
tuple(map(inline, libnames))
|
||||||
)
|
)
|
||||||
if message:
|
if message:
|
||||||
await ctx.send(
|
await self.send_pagified(
|
||||||
|
ctx,
|
||||||
_(
|
_(
|
||||||
"Cog requirements and shared libraries for all installed cogs"
|
"Cog requirements and shared libraries for all installed cogs"
|
||||||
" have been reinstalled but there were some errors:\n"
|
" have been reinstalled but there were some errors:\n"
|
||||||
)
|
)
|
||||||
+ message
|
+ message,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
@ -643,8 +649,7 @@ class Downloader(commands.Cog):
|
|||||||
f"**{candidate.object_type} {candidate.rev}**"
|
f"**{candidate.object_type} {candidate.rev}**"
|
||||||
f" - {candidate.description}\n"
|
f" - {candidate.description}\n"
|
||||||
)
|
)
|
||||||
for page in pagify(msg):
|
await self.send_pagified(ctx, msg)
|
||||||
await ctx.send(msg)
|
|
||||||
return
|
return
|
||||||
except errors.UnknownRevision:
|
except errors.UnknownRevision:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
@ -658,14 +663,14 @@ class Downloader(commands.Cog):
|
|||||||
async with repo.checkout(commit, exit_to_rev=repo.branch):
|
async with repo.checkout(commit, exit_to_rev=repo.branch):
|
||||||
cogs, message = await self._filter_incorrect_cogs_by_names(repo, cog_names)
|
cogs, message = await self._filter_incorrect_cogs_by_names(repo, cog_names)
|
||||||
if not cogs:
|
if not cogs:
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
return
|
return
|
||||||
failed_reqs = await self._install_requirements(cogs)
|
failed_reqs = await self._install_requirements(cogs)
|
||||||
if failed_reqs:
|
if failed_reqs:
|
||||||
message += _("\nFailed to install requirements: ") + humanize_list(
|
message += _("\nFailed to install requirements: ") + humanize_list(
|
||||||
tuple(map(inline, failed_reqs))
|
tuple(map(inline, failed_reqs))
|
||||||
)
|
)
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
return
|
return
|
||||||
|
|
||||||
installed_cogs, failed_cogs = await self._install_cogs(cogs)
|
installed_cogs, failed_cogs = await self._install_cogs(cogs)
|
||||||
@ -711,7 +716,7 @@ class Downloader(commands.Cog):
|
|||||||
+ message
|
+ message
|
||||||
)
|
)
|
||||||
# "---" added to separate cog install messages from Downloader's message
|
# "---" added to separate cog install messages from Downloader's message
|
||||||
await ctx.send(f"{message}{deprecation_notice}\n---")
|
await self.send_pagified(ctx, f"{message}{deprecation_notice}\n---")
|
||||||
for cog in installed_cogs:
|
for cog in installed_cogs:
|
||||||
if cog.install_msg:
|
if cog.install_msg:
|
||||||
await ctx.send(cog.install_msg.replace("[p]", ctx.prefix))
|
await ctx.send(cog.install_msg.replace("[p]", ctx.prefix))
|
||||||
@ -759,7 +764,7 @@ class Downloader(commands.Cog):
|
|||||||
" If so, ensure the cogs have been unloaded with `{prefix}unload {cogs}`."
|
" If so, ensure the cogs have been unloaded with `{prefix}unload {cogs}`."
|
||||||
).format(prefix=ctx.prefix, cogs=" ".join(failed_cogs))
|
).format(prefix=ctx.prefix, cogs=" ".join(failed_cogs))
|
||||||
)
|
)
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
@cog.command(name="pin", usage="<cogs>")
|
@cog.command(name="pin", usage="<cogs>")
|
||||||
async def _cog_pin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
async def _cog_pin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
||||||
@ -782,7 +787,7 @@ class Downloader(commands.Cog):
|
|||||||
message += _("Pinned cogs: ") + humanize_list(cognames)
|
message += _("Pinned cogs: ") + humanize_list(cognames)
|
||||||
if already_pinned:
|
if already_pinned:
|
||||||
message += _("\nThese cogs were already pinned: ") + humanize_list(already_pinned)
|
message += _("\nThese cogs were already pinned: ") + humanize_list(already_pinned)
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
@cog.command(name="unpin", usage="<cogs>")
|
@cog.command(name="unpin", usage="<cogs>")
|
||||||
async def _cog_unpin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
async def _cog_unpin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
||||||
@ -805,7 +810,7 @@ class Downloader(commands.Cog):
|
|||||||
message += _("Unpinned cogs: ") + humanize_list(cognames)
|
message += _("Unpinned cogs: ") + humanize_list(cognames)
|
||||||
if not_pinned:
|
if not_pinned:
|
||||||
message += _("\nThese cogs weren't pinned: ") + humanize_list(not_pinned)
|
message += _("\nThese cogs weren't pinned: ") + humanize_list(not_pinned)
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
@cog.command(name="checkforupdates")
|
@cog.command(name="checkforupdates")
|
||||||
async def _cog_checkforupdates(self, ctx: commands.Context) -> None:
|
async def _cog_checkforupdates(self, ctx: commands.Context) -> None:
|
||||||
@ -837,7 +842,7 @@ class Downloader(commands.Cog):
|
|||||||
if failed:
|
if failed:
|
||||||
message += "\n" + self.format_failed_repos(failed)
|
message += "\n" + self.format_failed_repos(failed)
|
||||||
|
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
@cog.command(name="update")
|
@cog.command(name="update")
|
||||||
async def _cog_update(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
async def _cog_update(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
|
||||||
@ -873,7 +878,6 @@ class Downloader(commands.Cog):
|
|||||||
rev: Optional[str] = None,
|
rev: Optional[str] = None,
|
||||||
cogs: Optional[List[InstalledModule]] = None,
|
cogs: Optional[List[InstalledModule]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
message = ""
|
|
||||||
failed_repos = set()
|
failed_repos = set()
|
||||||
updates_available = set()
|
updates_available = set()
|
||||||
|
|
||||||
@ -886,7 +890,7 @@ class Downloader(commands.Cog):
|
|||||||
await repo.update()
|
await repo.update()
|
||||||
except errors.UpdateError:
|
except errors.UpdateError:
|
||||||
message = self.format_failed_repos([repo.name])
|
message = self.format_failed_repos([repo.name])
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -900,11 +904,10 @@ class Downloader(commands.Cog):
|
|||||||
f"**{candidate.object_type} {candidate.rev}**"
|
f"**{candidate.object_type} {candidate.rev}**"
|
||||||
f" - {candidate.description}\n"
|
f" - {candidate.description}\n"
|
||||||
)
|
)
|
||||||
for page in pagify(msg):
|
await self.send_pagified(ctx, msg)
|
||||||
await ctx.send(msg)
|
|
||||||
return
|
return
|
||||||
except errors.UnknownRevision:
|
except errors.UnknownRevision:
|
||||||
message += _(
|
message = _(
|
||||||
"Error: there is no revision `{rev}` in repo `{repo.name}`"
|
"Error: there is no revision `{rev}` in repo `{repo.name}`"
|
||||||
).format(rev=rev, repo=repo)
|
).format(rev=rev, repo=repo)
|
||||||
await ctx.send(message)
|
await ctx.send(message)
|
||||||
@ -921,6 +924,8 @@ class Downloader(commands.Cog):
|
|||||||
|
|
||||||
pinned_cogs = {cog for cog in cogs_to_check if cog.pinned}
|
pinned_cogs = {cog for cog in cogs_to_check if cog.pinned}
|
||||||
cogs_to_check -= pinned_cogs
|
cogs_to_check -= pinned_cogs
|
||||||
|
|
||||||
|
message = ""
|
||||||
if not cogs_to_check:
|
if not cogs_to_check:
|
||||||
cogs_to_update = libs_to_update = ()
|
cogs_to_update = libs_to_update = ()
|
||||||
message += _("There were no cogs to check.")
|
message += _("There were no cogs to check.")
|
||||||
@ -976,7 +981,7 @@ class Downloader(commands.Cog):
|
|||||||
if repos_with_libs:
|
if repos_with_libs:
|
||||||
message += DEPRECATION_NOTICE.format(repo_list=humanize_list(list(repos_with_libs)))
|
message += DEPRECATION_NOTICE.format(repo_list=humanize_list(list(repos_with_libs)))
|
||||||
|
|
||||||
await ctx.send(message)
|
await self.send_pagified(ctx, message)
|
||||||
|
|
||||||
if updates_available and updated_cognames:
|
if updates_available and updated_cognames:
|
||||||
await self._ask_for_cog_reload(ctx, updated_cognames)
|
await self._ask_for_cog_reload(ctx, updated_cognames)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user