2023-06-20 09:02:18 +00:00
|
|
|
import sys
|
2023-06-18 03:13:16 +00:00
|
|
|
from getpass import getuser
|
2022-08-02 04:57:08 +00:00
|
|
|
from os.path import exists, sep
|
2022-05-23 12:40:30 +00:00
|
|
|
from platform import node
|
|
|
|
|
2022-11-15 02:52:29 +00:00
|
|
|
from pyrogram.enums import ParseMode
|
|
|
|
|
2023-01-31 16:24:56 +00:00
|
|
|
from pagermaid.common.system import run_eval
|
2022-08-02 04:57:08 +00:00
|
|
|
from pagermaid.enums import Message
|
2023-06-18 03:13:16 +00:00
|
|
|
from pagermaid.listener import listener
|
2022-08-02 04:57:08 +00:00
|
|
|
from pagermaid.utils import attach_log, execute, lang, upload_attachment
|
2022-05-23 12:40:30 +00:00
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
command="sh",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("sh_des"),
|
|
|
|
parameters=lang("sh_parameters"),
|
|
|
|
)
|
2022-06-20 13:55:14 +00:00
|
|
|
async def sh(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Use the command-line from Telegram."""
|
2022-05-23 12:40:30 +00:00
|
|
|
user = getuser()
|
2022-06-08 03:18:21 +00:00
|
|
|
command = message.arguments
|
2022-05-23 12:40:30 +00:00
|
|
|
hostname = node()
|
|
|
|
|
|
|
|
if not command:
|
2023-03-12 03:56:01 +00:00
|
|
|
await message.edit(lang("arg_error"))
|
2022-05-23 12:40:30 +00:00
|
|
|
return
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
message = await message.edit(f"`{user}`@{hostname} ~" f"\n> `$` {command}")
|
2022-05-23 12:40:30 +00:00
|
|
|
|
|
|
|
result = await execute(command)
|
|
|
|
|
|
|
|
if result:
|
|
|
|
if len(result) > 4096:
|
2022-07-08 14:26:36 +00:00
|
|
|
await attach_log(result, message.chat.id, "output.log", message.id)
|
2022-05-23 12:40:30 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
await message.edit(
|
2023-03-12 03:56:01 +00:00
|
|
|
f"`{user}`@{hostname} ~" f"\n> `#` {command}" f"\n`{result}`"
|
2022-06-20 13:55:14 +00:00
|
|
|
)
|
2022-05-23 12:40:30 +00:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False, command="restart", need_admin=True, description=lang("restart_des")
|
|
|
|
)
|
2022-06-20 13:55:14 +00:00
|
|
|
async def restart(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""To re-execute PagerMaid."""
|
2022-05-23 12:40:30 +00:00
|
|
|
if not message.text[0].isalpha():
|
2023-03-12 03:56:01 +00:00
|
|
|
await message.edit(lang("restart_log"))
|
2023-06-20 09:02:18 +00:00
|
|
|
sys.exit(0)
|
2022-05-23 12:40:30 +00:00
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
command="eval",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("eval_des"),
|
|
|
|
parameters=lang("eval_parameters"),
|
|
|
|
)
|
2022-06-20 13:55:14 +00:00
|
|
|
async def sh_eval(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Run python commands from Telegram."""
|
2022-11-15 02:52:29 +00:00
|
|
|
dev_mode = exists(f"data{sep}dev")
|
2022-05-23 12:40:30 +00:00
|
|
|
try:
|
2023-06-20 09:02:18 +00:00
|
|
|
if not dev_mode:
|
|
|
|
raise AssertionError
|
2022-05-23 12:40:30 +00:00
|
|
|
cmd = message.text.split(" ", maxsplit=1)[1]
|
2022-11-15 02:52:29 +00:00
|
|
|
except (IndexError, AssertionError):
|
2023-03-12 03:56:01 +00:00
|
|
|
return await message.edit(lang("eval_need_dev"))
|
2023-01-31 16:24:56 +00:00
|
|
|
final_output = await run_eval(cmd, message)
|
2022-05-23 12:40:30 +00:00
|
|
|
if len(final_output) > 4096:
|
2022-11-15 02:52:29 +00:00
|
|
|
message = await message.edit(f"**>>>** `{cmd}`", parse_mode=ParseMode.MARKDOWN)
|
2023-01-31 16:24:56 +00:00
|
|
|
await attach_log(final_output, message.chat.id, "output.log", message.id)
|
2022-05-23 12:40:30 +00:00
|
|
|
else:
|
|
|
|
await message.edit(final_output)
|
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
command="send_log",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("send_log_des"),
|
|
|
|
)
|
2022-08-02 04:57:08 +00:00
|
|
|
async def send_log(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Send log to a chat."""
|
2023-12-16 16:22:26 +00:00
|
|
|
if not exists("data/pagermaid.log.txt"):
|
2022-08-02 04:57:08 +00:00
|
|
|
return await message.edit(lang("send_log_not_found"))
|
2023-03-12 03:56:01 +00:00
|
|
|
await upload_attachment(
|
2023-12-16 16:22:26 +00:00
|
|
|
"data/pagermaid.log.txt",
|
2023-03-12 03:56:01 +00:00
|
|
|
message.chat.id,
|
2024-02-04 07:33:01 +00:00
|
|
|
message.reply_to_message_id,
|
|
|
|
message_thread_id=message.message_thread_id,
|
2023-03-12 03:56:01 +00:00
|
|
|
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
|
|
|
|
caption=lang("send_log_caption"),
|
|
|
|
)
|
2022-08-02 04:57:08 +00:00
|
|
|
await message.safe_delete()
|