aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2024-05-23 17:00:29 +0100
committerGravatar GitHub <[email protected]>2024-05-23 17:00:29 +0100
commitf644d7894e48cc3ba8e17118767d0a0354d3552c (patch)
tree98a4a5cf1b02886783179282a041d74f504c7da4
parentSupport events that span from one year to another (#3065) (diff)
parentMerge branch 'main' into vivek/fix-eval-truncation (diff)
Merge pull request #3046 from python-discord/vivek/fix-eval-truncation
Don't upload to pastebin when no truncation
-rw-r--r--bot/exts/utils/snekbox/_cog.py11
-rw-r--r--tests/bot/exts/utils/snekbox/test_snekbox.py2
2 files changed, 8 insertions, 5 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index 36434d290..decc1780b 100644
--- a/bot/exts/utils/snekbox/_cog.py
+++ b/bot/exts/utils/snekbox/_cog.py
@@ -266,14 +266,17 @@ class Snekbox(Cog):
truncated = False
lines = output.splitlines()
- if len(lines) > 1:
- if line_nums:
- lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
- lines = lines[:max_lines+1] # Limiting to max+1 lines
+ if len(lines) > 1 and line_nums:
+ lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
output = "\n".join(lines)
if len(lines) > max_lines:
truncated = True
+ if len(lines) == max_lines + 1:
+ lines = lines[:max_lines - 1]
+ else:
+ lines = lines[:max_lines]
+ output = "\n".join(lines)
if len(output) >= max_chars:
output = f"{output[:max_chars]}\n... (truncated - too long, too many lines)"
else:
diff --git a/tests/bot/exts/utils/snekbox/test_snekbox.py b/tests/bot/exts/utils/snekbox/test_snekbox.py
index 08925afaa..3595d9a67 100644
--- a/tests/bot/exts/utils/snekbox/test_snekbox.py
+++ b/tests/bot/exts/utils/snekbox/test_snekbox.py
@@ -199,7 +199,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
too_many_lines = (
"001 | v\n002 | e\n003 | r\n004 | y\n005 | l\n006 | o\n"
- "007 | n\n008 | g\n009 | b\n010 | e\n011 | a\n... (truncated - too many lines)"
+ "007 | n\n008 | g\n009 | b\n010 | e\n... (truncated - too many lines)"
)
too_long_too_many_lines = (
"\n".join(