Parse markdown for .sh

This commit is contained in:
blank X 2020-12-20 21:11:14 +07:00
parent 0f33b4b114
commit 25e23ffe60
1 changed files with 7 additions and 3 deletions

View File

@ -5,12 +5,16 @@ from io import BytesIO
from pyrogram import Client, filters
from .. import config, help_dict, log_errors, public_log_errors
@Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.regex('^(?:' + '|'.join(map(re.escape, config['config']['prefixes'])) + r')(?:(?:ba)?sh|shell|term(?:inal)?)\s+(.+)(?:\n([\s\S]+))?$'))
SHELL_REGEX = '^(?:' + '|'.join(map(re.escape, config['config']['prefixes'])) + r')(?:(?:ba)?sh|shell|term(?:inal)?)\s+(.+)(?:\n([\s\S]+))?$'
@Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.regex(SHELL_REGEX))
@log_errors
@public_log_errors
async def shell(client, message):
command = message.matches[0].group(1)
stdin = message.matches[0].group(2)
match = re.match(SHELL_REGEX, message.text.markdown)
if not match:
return
command = match.group(1)
stdin = match.group(2)
reply = await message.reply_text('Executing...')
process = await asyncio.create_subprocess_shell(command, stdin=asyncio.subprocess.PIPE if stdin else None, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
stdout, stderr = await process.communicate(stdin.encode() if stdin else None)