Skip to content

Commit

Permalink
Better support arbitrarily long outputs of 'eval' command in 'bot_man…
Browse files Browse the repository at this point in the history
…agement' extension
  • Loading branch information
Mega-JC committed Jul 27, 2024
1 parent f4c835b commit f9c6c0c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pcbot/exts/bot_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ async def eval(self, ctx: commands.Context[BotT], code: CodeBlock):
try:
script = compile(code.code, "<string>", "eval") # compile script
script_start = time.perf_counter()
eval_output = eval(script) # pylint: disable = eval-used
eval_output = repr(eval(script)) # pylint: disable = eval-used
total = time.perf_counter() - script_start
except Exception as ex:
raise commands.CommandInvokeError(
Expand All @@ -531,9 +531,13 @@ async def eval(self, ctx: commands.Context[BotT], code: CodeBlock):
embed=discord.Embed(
title=f"Return output (code executed in "
f"{snakecore.utils.format_time_by_units(total)}):",
description=snakecore.utils.code_block(repr(eval_output)),
description=snakecore.utils.code_block(eval_output, max_characters=4096),
color=int(self.theme_color),
),
file=discord.File(
io.StringIO(repr(eval_output)), # type: ignore
filename=f"eval_output_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.txt",
) if len(eval_output) > 4096 else None,
)

@is_bot_manager()
Expand Down

0 comments on commit f9c6c0c

Please sign in to comment.