From 25e23ffe60da20a83d18ae317f3817d42bfcb128 Mon Sep 17 00:00:00 2001 From: blank X Date: Sun, 20 Dec 2020 21:11:14 +0700 Subject: [PATCH] Parse markdown for .sh --- sukuinote/plugins/shell.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sukuinote/plugins/shell.py b/sukuinote/plugins/shell.py index 69baf69..2f43a39 100644 --- a/sukuinote/plugins/shell.py +++ b/sukuinote/plugins/shell.py @@ -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)