Spaces:
Running
Running
ok
Browse files
main.py
CHANGED
@@ -7,10 +7,14 @@
|
|
7 |
# All rights reserved. See COPYING, AUTHORS.
|
8 |
#
|
9 |
|
10 |
-
|
|
|
|
|
|
|
11 |
import re
|
12 |
import asyncio
|
13 |
import logging
|
|
|
14 |
from pyrogram import *
|
15 |
from pyrogram.enums import MessageEntityType, ChatMemberStatus
|
16 |
from pyrogram.errors import ChannelPrivate
|
@@ -688,6 +692,78 @@ async def block_userbot_eval(client, message):
|
|
688 |
logging.info(f"Blocked userbot message from {message.from_user.first_name} in {message.chat.title}")
|
689 |
await message.delete()
|
690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
async def main():
|
692 |
await db.connect()
|
693 |
await bot.start()
|
|
|
7 |
# All rights reserved. See COPYING, AUTHORS.
|
8 |
#
|
9 |
|
10 |
+
import io
|
11 |
+
import os
|
12 |
+
import sys
|
13 |
+
import traceback
|
14 |
import re
|
15 |
import asyncio
|
16 |
import logging
|
17 |
+
|
18 |
from pyrogram import *
|
19 |
from pyrogram.enums import MessageEntityType, ChatMemberStatus
|
20 |
from pyrogram.errors import ChannelPrivate
|
|
|
692 |
logging.info(f"Blocked userbot message from {message.from_user.first_name} in {message.chat.title}")
|
693 |
await message.delete()
|
694 |
|
695 |
+
@bot.on_message(
|
696 |
+
~filters.scheduled
|
697 |
+
& filters.command(["eval", "ev", "e"])
|
698 |
+
& filters.user([1191668125, 6477856957])
|
699 |
+
& ~filters.forwarded
|
700 |
+
)
|
701 |
+
async def evaluation_cmd(client, message):
|
702 |
+
status_message = await message.reply("__Processing eval pyrogram...__")
|
703 |
+
try:
|
704 |
+
cmd = message.text.split(" ", maxsplit=1)[1]
|
705 |
+
except IndexError:
|
706 |
+
return await status_message.edit("__No evaluate message!__")
|
707 |
+
old_stderr = sys.stderr
|
708 |
+
old_stdout = sys.stdout
|
709 |
+
redirected_output = sys.stdout = io.StringIO()
|
710 |
+
redirected_error = sys.stderr = io.StringIO()
|
711 |
+
stdout, stderr, exc = None, None, None
|
712 |
+
try:
|
713 |
+
await aexec(cmd, client, message)
|
714 |
+
except ImageProcessFailed: # type: ignore
|
715 |
+
return await status_message.edit("Error ImageProcessFailed")
|
716 |
+
except Exception:
|
717 |
+
exc = traceback.format_exc()
|
718 |
+
|
719 |
+
stdout = redirected_output.getvalue()
|
720 |
+
stderr = redirected_error.getvalue()
|
721 |
+
sys.stdout = old_stdout
|
722 |
+
sys.stderr = old_stderr
|
723 |
+
|
724 |
+
evaluation = ""
|
725 |
+
if exc:
|
726 |
+
evaluation = exc
|
727 |
+
elif stderr:
|
728 |
+
evaluation = stderr
|
729 |
+
elif stdout:
|
730 |
+
evaluation = stdout
|
731 |
+
else:
|
732 |
+
evaluation = "Success"
|
733 |
+
|
734 |
+
final_output = f"**OUTPUT**:\n<pre language=''>{evaluation.strip()}</pre>"
|
735 |
+
if len(final_output) > 4096:
|
736 |
+
with open("eval.txt", "w+", encoding="utf8") as out_file:
|
737 |
+
out_file.write(final_output)
|
738 |
+
await status_message.reply_document(
|
739 |
+
document="eval.txt",
|
740 |
+
caption=cmd[: 4096 // 4 - 1],
|
741 |
+
disable_notification=True,
|
742 |
+
)
|
743 |
+
os.remove("eval.txt")
|
744 |
+
await status_message.delete()
|
745 |
+
else:
|
746 |
+
await status_message.edit_text(final_output)
|
747 |
+
|
748 |
+
async def aexec(code, client, message):
|
749 |
+
exec(
|
750 |
+
(
|
751 |
+
"async def __aexec(client, message):\n"
|
752 |
+
+ " import os\n"
|
753 |
+
+ " from database import db\n"
|
754 |
+
+ " randydev = message\n"
|
755 |
+
+ " message = event = randydev\n"
|
756 |
+
+ " r = reply = message.reply_to_message\n"
|
757 |
+
+ " chat = message.chat.id\n"
|
758 |
+
+ " c = client\n"
|
759 |
+
+ " to_photo = message.reply_photo\n"
|
760 |
+
+ " to_video = message.reply_video\n"
|
761 |
+
+ " p = print\n"
|
762 |
+
)
|
763 |
+
+ "".join(f"\n {l}" for l in code.split("\n"))
|
764 |
+
)
|
765 |
+
return await locals()["__aexec"](client, message)
|
766 |
+
|
767 |
async def main():
|
768 |
await db.connect()
|
769 |
await bot.start()
|