Path: blob/master/bot/modules/shell.py
1619 views
from io import BytesIO12from .. import LOGGER3from ..helper.ext_utils.bot_utils import cmd_exec, new_task4from ..helper.telegram_helper.message_utils import send_message, send_file567@new_task8async def run_shell(_, message):9cmd = message.text.split(maxsplit=1)10if len(cmd) == 1:11await send_message(message, "No command to execute was given.")12return13cmd = cmd[1]14stdout, stderr, _ = await cmd_exec(cmd, shell=True)15reply = ""16if len(stdout) != 0:17reply += f"*Stdout*\n<code>{stdout}</code>\n"18LOGGER.info(f"Shell - {cmd} - {stdout}")19if len(stderr) != 0:20reply += f"*Stderr*\n<code>{stderr}</code>"21LOGGER.error(f"Shell - {cmd} - {stderr}")22if len(reply) > 3000:23with BytesIO(str.encode(reply)) as out_file:24out_file.name = "shell_output.txt"25await send_file(message, out_file)26elif len(reply) != 0:27await send_message(message, reply)28else:29await send_message(message, "No Reply")303132