From 40254a08c594243655b1ae969de7103f64279d07 Mon Sep 17 00:00:00 2001 From: AlbertUnruh <73029826+AlbertUnruh@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:24:35 +0100 Subject: [PATCH] fix: body-length can't be exceeded anymore (#744) * fix: body-length can't be exceeded anymore * fix length comparison for `result` --- naff/ext/debug_extension/debug_exec.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/naff/ext/debug_extension/debug_exec.py b/naff/ext/debug_extension/debug_exec.py index 3a328d116..e78784f46 100644 --- a/naff/ext/debug_extension/debug_exec.py +++ b/naff/ext/debug_extension/debug_exec.py @@ -81,8 +81,9 @@ async def debug_exec(self, ctx: InteractionContext) -> Optional[Message]: return await self.handle_exec_result(m_ctx, ret, stdout.getvalue(), body) async def handle_exec_result(self, ctx: ModalContext, result: Any, value: Any, body: str) -> Optional[Message]: - if len(body) <= 2000: - await ctx.send(f"```py\n{body}```") + # body can be of length 2000 and exceed the limit after formatting + if len(cmd_body := f"```py\n{body}```") <= 2000: + await ctx.send(cmd_body) else: paginator = Paginator.create_from_string(self.bot, body, prefix="```py", suffix="```", page_size=4000) @@ -123,8 +124,8 @@ async def handle_exec_result(self, ctx: ModalContext, result: Any, value: Any, b # prevent token leak result = result.replace(self.bot.http.token, "[REDACTED TOKEN]") - if len(result) <= 2000: - return await ctx.send(f"```py\n{result}```") + if len(cmd_result := f"```py\n{result}```") <= 2000: + return await ctx.send(cmd_result) else: paginator = Paginator.create_from_string(self.bot, result, prefix="```py", suffix="```", page_size=4000)