If output from .exec or .term is too long, send as a file instead
Signed-off-by: Justin Crawford <Justin@stacksmash.net>
This commit is contained in:
parent
af06deebc1
commit
55d41e65cc
|
@ -5,7 +5,7 @@ import sys
|
|||
import html
|
||||
import inspect
|
||||
import asyncio
|
||||
from io import StringIO
|
||||
from io import StringIO, BytesIO
|
||||
from pyrogram import Client, filters
|
||||
from .. import config, help_dict, log_errors, slave, apps, session, public_log_errors
|
||||
|
||||
|
@ -57,15 +57,26 @@ async def pyexec(client, message):
|
|||
wrapped_stdout.seek(0)
|
||||
output = ''
|
||||
wrapped_stderr_text = wrapped_stderr.read().strip()
|
||||
wrapped_stdout_text = wrapped_stdout.read().strip()
|
||||
if wrapped_stderr_text:
|
||||
output += f'<code>{html.escape(wrapped_stderr_text)}</code>\n'
|
||||
wrapped_stdout_text = wrapped_stdout.read().strip()
|
||||
if wrapped_stdout_text:
|
||||
output += f'<code>{html.escape(wrapped_stdout_text)}</code>\n'
|
||||
for i in returned:
|
||||
output += f'<code>{html.escape(str(i).strip())}</code>\n'
|
||||
if not output.strip():
|
||||
output = 'Executed'
|
||||
|
||||
# send as a file if it's longer than 4096 bytes
|
||||
if len(output) > 4096:
|
||||
out = wrapped_stderr_text + "\n" + wrapped_stdout_text + "\n"
|
||||
for i in returned:
|
||||
out += str(i).strip() + "\n"
|
||||
f = BytesIO(out.strip().encode('utf-8'))
|
||||
f.name = "output.txt"
|
||||
await reply.delete()
|
||||
await message.reply_document(f)
|
||||
else:
|
||||
await reply.edit_text(output)
|
||||
|
||||
help_dict['exec'] = ('Exec', '{prefix}exec <i><python code></i> - Executes python code')
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
import html
|
||||
import asyncio
|
||||
from io import BytesIO
|
||||
from pyrogram import Client, filters
|
||||
from .. import config, help_dict, log_errors, public_log_errors
|
||||
|
||||
|
@ -21,6 +22,15 @@ async def shell(client, message):
|
|||
text += f'<code>{html.escape(stderr)}</code>\n'
|
||||
if stdout:
|
||||
text += f'<code>{html.escape(stdout)}</code>'
|
||||
|
||||
# send as a file if it's longer than 4096 bytes
|
||||
if len(text) > 4096:
|
||||
out = stderr.strip() + "\n" + stdout.strip()
|
||||
f = BytesIO(out.strip().encode('utf-8'))
|
||||
f.name = "output.txt"
|
||||
await reply.delete()
|
||||
await message.reply_document(f)
|
||||
else:
|
||||
await reply.edit_text(text)
|
||||
|
||||
help_dict['shell'] = ('Shell',
|
||||
|
|
Loading…
Reference in New Issue