File size: 2,686 Bytes
abc89fd 5a014fc abc89fd 1d2866f abc89fd 5a014fc abc89fd 3e77365 abc89fd 1d2866f abc89fd 3e77365 abc89fd 1d2866f abc89fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
"""
Devtools plugin for userbot-only development and admin commands.
Provides /sh, /xsh for shell commands and /eval, /e for Python code evaluation.
Also triggers if the message starts with 'sh', 'xsh', 'e', or 'eval' (with or without a slash or exclamation mark, and with any capitalization).
Restricted to OWNER_ID only. Usable in any chat where the userbot is present.
"""
import asyncio
import re
from pyrogram import filters
from pyrogram.types import Message
from DragMusic import userbot
from config import OWNER_ID
# Regex filters for command matching (case-insensitive)
sh_filter = filters.user(OWNER_ID) & filters.regex(r"^[!/]*x?sh( |$)", re.IGNORECASE)
eval_filter = filters.user(OWNER_ID) & filters.regex(r"^[!/]*(e|eval)( |$)", re.IGNORECASE)
@userbot.one.on_message(sh_filter)
async def shell_command_handler(client, message: Message):
print("sh/xsh command received from OWNER_ID") # Debug print
parts = message.text.split(None, 1)
if len(parts) < 2:
await message.reply_text("Usage: sh <command>")
return
cmd = parts[1]
try:
process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await process.communicate()
output = (stdout + stderr).decode().strip()
if not output:
output = "No output."
# Telegram message limit
if len(output) > 4096:
for i in range(0, len(output), 4096):
await message.reply_text(f"<code>{output[i:i+4096]}</code>")
else:
await message.reply_text(f"<code>{output}</code>")
except Exception as e:
await message.reply_text(f"Error: <code>{e}</code>")
@userbot.one.on_message(eval_filter)
async def eval_handler(client, message: Message):
print("eval command received from OWNER_ID") # Debug print
parts = message.text.split(None, 1)
if len(parts) < 2:
await message.reply_text("Usage: eval <python code>")
return
code = parts[1]
try:
env = {
"client": client,
"message": message,
"userbot": userbot,
"asyncio": asyncio,
}
exec(
f"async def __aexec(client, message):\n"
+ "\n".join(f" {l}" for l in code.split("\n")),
env,
)
result = await env["__aexec"](client, message)
if result is not None:
await message.reply_text(f"<code>{result}</code>")
except Exception as e:
await message.reply_text(f"Error: <code>{e}</code>")
# Add more dev/admin commands below as needed |