From f9c6c0cd17f00436505e534cfd2429ffaf4e5dd6 Mon Sep 17 00:00:00 2001 From: Mega-JC <65417594+Mega-JC@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:38:52 +0200 Subject: [PATCH] Better support arbitrarily long outputs of 'eval' command in 'bot_management' extension --- pcbot/exts/bot_management.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pcbot/exts/bot_management.py b/pcbot/exts/bot_management.py index a851415..5412579 100644 --- a/pcbot/exts/bot_management.py +++ b/pcbot/exts/bot_management.py @@ -516,7 +516,7 @@ async def eval(self, ctx: commands.Context[BotT], code: CodeBlock): try: script = compile(code.code, "", "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( @@ -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()