th0m45s5helby

Untitled

Dec 4th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. async def exec_message_f(client, message):
  2.     if message.from_user.id in AUTH_CHANNEL:
  3.         DELAY_BETWEEN_EDITS = 0.3
  4.         PROCESS_RUN_TIME = 100
  5.         cmd = message.text.split(" ", maxsplit=1)[1]
  6.  
  7.         reply_to_id = message.message_id
  8.         if message.reply_to_message:
  9.             reply_to_id = message.reply_to_message.message_id
  10.  
  11.         start_time = time.time() + PROCESS_RUN_TIME
  12.         process = await asyncio.create_subprocess_shell(
  13.             cmd,
  14.             stdout=asyncio.subprocess.PIPE,
  15.             stderr=asyncio.subprocess.PIPE
  16.         )
  17.         stdout, stderr = await process.communicate()
  18.         e = stderr.decode()
  19.         if not e:
  20.             e = "No Error"
  21.         o = stdout.decode()
  22.         if not o:
  23.             o = "No Output"
  24.         else:
  25.             _o = o.split("\n")
  26.             o = "`\n".join(_o)
  27.         OUTPUT = f"**QUERY:**\n__Command:__\n`{cmd}` \n__PID:__\n`{process.pid}`\n\n**stderr:** \n`{e}`\n**Output:**\n{o}"
  28.  
  29.         if len(OUTPUT) > MAX_MESSAGE_LENGTH:
  30.             with open("exec.text", "w+", encoding="utf8") as out_file:
  31.                 out_file.write(str(OUTPUT))
  32.             await client.send_document(
  33.                 chat_id=message.chat.id,
  34.                 document="exec.text",
  35.                 caption=cmd,
  36.                 disable_notification=True,
  37.                 reply_to_message_id=reply_to_id
  38.             )
  39.             os.remove("exec.text")
  40.             await message.delete()
  41.         else:
  42.             await message.reply_text(OUTPUT)
Advertisement
Add Comment
Please, Sign In to add comment