Skip to content

Commit 56f646c

Browse files
committed
Better support arbitrarily long outputs of 'eval' command in 'bot_management' extension
1 parent f4c835b commit 56f646c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ENV PYTHONUNBUFFERED=1 \
66
PIP_DISABLE_PIP_VERSION_CHECK=on \
77
PIP_DEFAULT_TIMEOUT=100 \
88
VENV_PATH="/opt/.venv"
9+
910
ENV PATH="$VENV_PATH/bin:$PATH"
1011

1112
FROM python-base AS builder-base

pcbot/exts/bot_management.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ async def eval(self, ctx: commands.Context[BotT], code: CodeBlock):
516516
try:
517517
script = compile(code.code, "<string>", "eval") # compile script
518518
script_start = time.perf_counter()
519-
eval_output = eval(script) # pylint: disable = eval-used
519+
eval_output = repr(eval(script)) # pylint: disable = eval-used
520520
total = time.perf_counter() - script_start
521521
except Exception as ex:
522522
raise commands.CommandInvokeError(
@@ -531,9 +531,13 @@ async def eval(self, ctx: commands.Context[BotT], code: CodeBlock):
531531
embed=discord.Embed(
532532
title=f"Return output (code executed in "
533533
f"{snakecore.utils.format_time_by_units(total)}):",
534-
description=snakecore.utils.code_block(repr(eval_output)),
534+
description=snakecore.utils.code_block(eval_output, max_characters=4096),
535535
color=int(self.theme_color),
536536
),
537+
file=discord.File(
538+
io.StringIO(repr(eval_output)), # type: ignore
539+
filename=f"eval_output_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.txt",
540+
) if len(eval_output) > 4096 else None,
537541
)
538542

539543
@is_bot_manager()

0 commit comments

Comments
 (0)