aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Ionite <[email protected]>2023-02-24 15:04:58 -0500
committerGravatar Ionite <[email protected]>2023-02-24 15:04:58 -0500
commit3d19133d70334eb9a46b4788f95e3c5ac44cc41d (patch)
tree13090f3fa3c2016279745c9422e35b4a90b5adc7
parentUse PurePosixPath so tests work on windows (diff)
Fix and simplify logic for optional line numbering
-rw-r--r--bot/exts/utils/snekbox/_cog.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index f4032e4a1..a549ec70a 100644
--- a/bot/exts/utils/snekbox/_cog.py
+++ b/bot/exts/utils/snekbox/_cog.py
@@ -262,15 +262,15 @@ class Snekbox(Cog):
return "Code block escape attempt detected; will not output result", paste_link
truncated = False
- lines = output.count("\n")
+ lines = output.splitlines()
- if lines > 0:
+ if lines:
if line_nums:
- output = [f"{i:03d} | {line}" for i, line in enumerate(output.split('\n'), 1)]
- output = output[:max_lines+1] # Limiting to max+1 lines
- output = "\n".join(output)
+ lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
+ lines = lines[:max_lines+1] # Limiting to max+1 lines
+ output = "\n".join(lines)
- if lines > max_lines:
+ if len(lines) > max_lines:
truncated = True
if len(output) >= max_chars:
output = f"{output[:max_chars]}\n... (truncated - too long, too many lines)"