Eval output allows too many lines
The Problem
The MAX_OUTPUT_BLOCK_LINES variable is set to a value of 10, which means under the current logic evals which output more than 10 lines, will be uploaded to the haste site (paste.pydis.com) and a message will be added to the eval output stating it was truncated.
However, since we currently update the lines variable to be lines[:max_lines+1], outputs of 11 lines (such as for x in range(11): print(x)) will be uploaded to the pastebin and still display all 11 lines (despite the limit being 10). This also means that the paste content is the same as what's sent to Discord as the eval content.
The code should be changed to instead change lines to lines[:max_lines]. This will also break the logic underneath (you've shortened so will never be more than max_lines) so the if statements will have to be swapped around.
Current Code
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
output = "\n".join(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)"
else:
output = f"{output}\n... (truncated - too many lines)"
Proposed Solution (approx.)
if len(lines) > max_lines:
truncated = True
lines = lines[:max_lines]
if len(lines) > 1:
if line_nums:
lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
output = "\n".join(lines)
if truncated:
if len(output) > max_chars:
output = f"{output[:max_chars]}\n... (truncated - too long, too many lines)"
else:
output = f"{output}\n... (truncated - too many lines)"
Notice that the proposed solution sets lines to lines[:max_lines] instead of lines[:max_lines + 1]. In reality the if truncated part can just be slotted into the pre-existing if truncated block