|
|
@@ -175,34 +175,66 @@ async def shellrunner(_, message: Message):
|
|
|
text = message.text.split(None, 1)[1]
|
|
|
if "\n" in text:
|
|
|
code = text.split("\n")
|
|
|
- shell = " ".join(code)
|
|
|
+ output = ""
|
|
|
+ for x in code:
|
|
|
+ shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", x)
|
|
|
+ try:
|
|
|
+ process = subprocess.Popen(
|
|
|
+ shell,
|
|
|
+ stdout=subprocess.PIPE,
|
|
|
+ stderr=subprocess.PIPE,
|
|
|
+ )
|
|
|
+ except Exception as err:
|
|
|
+ print(err)
|
|
|
+ await eor(
|
|
|
+ message,
|
|
|
+ text=f"**INPUT:**\n```{escape(text)}```\n\n**ERROR:**\n```{escape(err)}```",
|
|
|
+ )
|
|
|
+ output += f"**{code}**\n"
|
|
|
+ output += process.stdout.read()[:-1].decode("utf-8")
|
|
|
+ output += "\n"
|
|
|
else:
|
|
|
- shell = text
|
|
|
- process = await asyncio.create_subprocess_shell(
|
|
|
- shell,
|
|
|
- stdout=asyncio.subprocess.PIPE,
|
|
|
- stderr=asyncio.subprocess.PIPE,
|
|
|
- )
|
|
|
- out, errorz = await process.communicate()
|
|
|
- if errorz:
|
|
|
- error=f"**INPUT:**\n```{escape(text)}```\n\n**ERROR:**\n```{errorz.decode('utf-8')}```")
|
|
|
- return await eor(message, text=error)
|
|
|
- output += out.decode("utf-8")
|
|
|
- output += "\n"
|
|
|
+ shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", text)
|
|
|
+ for a, _ in enumerate(shell):
|
|
|
+ shell[a] = shell[a].replace('"', "")
|
|
|
+ try:
|
|
|
+ process = subprocess.Popen(
|
|
|
+ shell,
|
|
|
+ stdout=subprocess.PIPE,
|
|
|
+ stderr=subprocess.PIPE,
|
|
|
+ )
|
|
|
+ except Exception as err:
|
|
|
+ print(err)
|
|
|
+ exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
|
+ errors = traceback.format_exception(
|
|
|
+ etype=exc_type,
|
|
|
+ value=exc_obj,
|
|
|
+ tb=exc_tb,
|
|
|
+ )
|
|
|
+ return await eor(
|
|
|
+ message,
|
|
|
+ text=f"**INPUT:**\n```{escape(text)}```\n\n**ERROR:**\n```{''.join(errors)}```",
|
|
|
+ )
|
|
|
+ output = process.stdout.read()[:-1].decode("utf-8")
|
|
|
if str(output) == "\n":
|
|
|
output = None
|
|
|
if output:
|
|
|
if len(output) > 4096:
|
|
|
with open("output.txt", "w+") as file:
|
|
|
file.write(output)
|
|
|
- await message.reply_document("output.txt",caption=f"{escape(text)}")
|
|
|
+ await app2.send_document(
|
|
|
+ message.chat.id,
|
|
|
+ "output.txt",
|
|
|
+ reply_to_message_id=message.message_id,
|
|
|
+ caption=escape(text),
|
|
|
+ )
|
|
|
return os.remove("output.txt")
|
|
|
await eor(
|
|
|
- message,
|
|
|
- text=f"**INPUT:**\n```{escape(text)}```\n\n**OUTPUT:**\n```{(output)}```",
|
|
|
+ message,
|
|
|
+ text=f"**INPUT:**\n```{escape(text)}```\n\n**OUTPUT:**\n```{escape(output)}```",
|
|
|
)
|
|
|
else:
|
|
|
- return await eor(
|
|
|
- message,
|
|
|
- text=f"**INPUT:**\n```{escape(text)}```\n\n**OUTPUT: **\n`No output`",
|
|
|
+ await eor(
|
|
|
+ message,
|
|
|
+ text=f"**INPUT:**\n```{escape(text)}```\n\n**OUTPUT: **\n`No output`",
|
|
|
)
|