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 56f646c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
VENV_PATH="/opt/.venv"

ENV PATH="$VENV_PATH/bin:$PATH"

FROM python-base AS builder-base
Expand Down
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 56f646c

Please sign in to comment.