Parse markdown for .sh
This commit is contained in:
parent
0f33b4b114
commit
25e23ffe60
|
@ -5,12 +5,16 @@ from io import BytesIO
|
||||||
from pyrogram import Client, filters
|
from pyrogram import Client, filters
|
||||||
from .. import config, help_dict, log_errors, public_log_errors
|
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
|
@log_errors
|
||||||
@public_log_errors
|
@public_log_errors
|
||||||
async def shell(client, message):
|
async def shell(client, message):
|
||||||
command = message.matches[0].group(1)
|
match = re.match(SHELL_REGEX, message.text.markdown)
|
||||||
stdin = message.matches[0].group(2)
|
if not match:
|
||||||
|
return
|
||||||
|
command = match.group(1)
|
||||||
|
stdin = match.group(2)
|
||||||
reply = await message.reply_text('Executing...')
|
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)
|
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)
|
stdout, stderr = await process.communicate(stdin.encode() if stdin else None)
|
||||||
|
|
Loading…
Reference in New Issue