Rename Akeno/plugins/eval to Akeno/plugins/eval.py
Browse files- Akeno/plugins/{eval โ eval.py} +58 -54
Akeno/plugins/{eval โ eval.py}
RENAMED
@@ -1,48 +1,72 @@
|
|
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 |
-
|
12 |
-
|
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
|
|
|
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
|
|
|
|
|
|
|
26 |
from pyrogram.raw.types import InputGroupCall, InputPeerChannel, InputPeerChat
|
|
|
27 |
|
28 |
-
from Akeno.utils.tools import *
|
29 |
from Akeno.utils.handler import *
|
30 |
-
from Akeno import *
|
31 |
from config import CMD_HANDLER
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
@Akeno(
|
34 |
~filters.scheduled
|
35 |
& filters.command(["eval", "ev"], CMD_HANDLER)
|
36 |
& filters.me
|
37 |
& ~filters.forwarded
|
38 |
)
|
39 |
-
async def
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
46 |
old_stderr = sys.stderr
|
47 |
old_stdout = sys.stdout
|
48 |
redirected_output = sys.stdout = io.StringIO()
|
@@ -50,16 +74,16 @@ async def evaluation_cmd_t(client: Client, message: Message):
|
|
50 |
stdout, stderr, exc = None, None, None
|
51 |
|
52 |
try:
|
53 |
-
await aexec(
|
54 |
except Exception:
|
55 |
exc = traceback.format_exc()
|
56 |
|
|
|
57 |
stdout = redirected_output.getvalue()
|
58 |
stderr = redirected_error.getvalue()
|
59 |
sys.stdout = old_stdout
|
60 |
sys.stderr = old_stderr
|
61 |
|
62 |
-
evaluation = ""
|
63 |
if exc:
|
64 |
evaluation = exc
|
65 |
elif stderr:
|
@@ -69,33 +93,13 @@ async def evaluation_cmd_t(client: Client, message: Message):
|
|
69 |
else:
|
70 |
evaluation = "Success"
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
await
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
await status_message.delete()
|
83 |
-
else:
|
84 |
-
await status_message.edit_text(final_output)
|
85 |
-
|
86 |
-
async def aexec(code, client, message):
|
87 |
-
exec(
|
88 |
-
"async def __aexec(client, message): "
|
89 |
-
+ "".join(f"\n {l_}" for l_ in code.split("\n"))
|
90 |
-
)
|
91 |
-
return await locals()["__aexec"](client, message)
|
92 |
-
|
93 |
-
async def shell_exec(code, treat=True):
|
94 |
-
process = await asyncio.create_subprocess_shell(
|
95 |
-
code, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT
|
96 |
-
)
|
97 |
-
|
98 |
-
stdout = (await process.communicate())[0]
|
99 |
-
if treat:
|
100 |
-
stdout = stdout.decode().strip()
|
101 |
-
return stdout, process
|
|
|
1 |
import asyncio
|
|
|
2 |
import io
|
3 |
import os
|
|
|
4 |
import re
|
|
|
5 |
import subprocess
|
6 |
+
import sys
|
7 |
+
import traceback
|
8 |
+
from asyncio import sleep
|
9 |
+
from contextlib import suppress
|
10 |
+
from io import BytesIO, StringIO
|
11 |
from random import randint
|
12 |
from typing import Optional
|
13 |
+
import bs4
|
14 |
+
import requests
|
|
|
|
|
|
|
|
|
15 |
from pyrogram import Client
|
16 |
+
from pyrogram.errors import MessageTooLong
|
17 |
+
from pyrogram.types import Message
|
18 |
|
19 |
+
from pyrogram import Client
|
20 |
+
from pyrogram import Client as app
|
21 |
+
from pyrogram import Client as ren
|
22 |
+
from pyrogram import *
|
23 |
from pyrogram.raw import *
|
|
|
|
|
24 |
from pyrogram.raw.functions.channels import GetFullChannel
|
25 |
from pyrogram.raw.functions.messages import GetFullChat
|
26 |
+
from pyrogram.raw.functions.phone import CreateGroupCall
|
27 |
+
from pyrogram.raw.functions.phone import CreateGroupCall as call
|
28 |
+
from pyrogram.raw.functions.phone import DiscardGroupCall
|
29 |
+
from pyrogram.raw.types import *
|
30 |
from pyrogram.raw.types import InputGroupCall, InputPeerChannel, InputPeerChat
|
31 |
+
from pyrogram.types import *
|
32 |
|
|
|
33 |
from Akeno.utils.handler import *
|
34 |
+
from Akeno.utils.tools import *
|
35 |
from config import CMD_HANDLER
|
36 |
|
37 |
+
async def input_user(message: Message) -> str:
|
38 |
+
"""Get the input from the user"""
|
39 |
+
if len(message.command) < 2:
|
40 |
+
output = ""
|
41 |
+
else:
|
42 |
+
try:
|
43 |
+
output = message.text.split(" ", 1)[1].strip() or ""
|
44 |
+
except IndexError:
|
45 |
+
output = ""
|
46 |
+
return output
|
47 |
+
|
48 |
+
async def aexec(code, client, message):
|
49 |
+
exec(
|
50 |
+
"async def __aexec(client, message): "
|
51 |
+
+ "".join(f"\n {l_}" for l_ in code.split("\n"))
|
52 |
+
)
|
53 |
+
return await locals()["__aexec"](client, message)
|
54 |
+
|
55 |
@Akeno(
|
56 |
~filters.scheduled
|
57 |
& filters.command(["eval", "ev"], CMD_HANDLER)
|
58 |
& filters.me
|
59 |
& ~filters.forwarded
|
60 |
)
|
61 |
+
async def runeval(client: Client, message: Message):
|
62 |
+
if len(message.command) < 2:
|
63 |
+
return await message.reply_text("No python code provided!")
|
64 |
+
|
65 |
+
reply_to = message.reply_to_message or message
|
66 |
+
|
67 |
+
code = await input_user(message)
|
68 |
+
pro = await message.reply_texf("`running...`")
|
69 |
+
|
70 |
old_stderr = sys.stderr
|
71 |
old_stdout = sys.stdout
|
72 |
redirected_output = sys.stdout = io.StringIO()
|
|
|
74 |
stdout, stderr, exc = None, None, None
|
75 |
|
76 |
try:
|
77 |
+
await aexec(code, client, message)
|
78 |
except Exception:
|
79 |
exc = traceback.format_exc()
|
80 |
|
81 |
+
evaluation = ""
|
82 |
stdout = redirected_output.getvalue()
|
83 |
stderr = redirected_error.getvalue()
|
84 |
sys.stdout = old_stdout
|
85 |
sys.stderr = old_stderr
|
86 |
|
|
|
87 |
if exc:
|
88 |
evaluation = exc
|
89 |
elif stderr:
|
|
|
93 |
else:
|
94 |
evaluation = "Success"
|
95 |
|
96 |
+
heading = f"**๐ค๐๐บ๐
:**\n```python\n{code}```\n\n"
|
97 |
+
output = f"**๐ฎ๐๐๐๐๐:**\n`{evaluation.strip()}`"
|
98 |
+
final_output = heading + output
|
99 |
+
try:
|
100 |
+
await reply_to.reply_text(final_output, disable_web_page_preview=True)
|
101 |
+
except MessageTooLong:
|
102 |
+
with io.BytesIO(str.encode(output)) as out_file:
|
103 |
+
out_file.name = "eval.txt"
|
104 |
+
await reply_to.reply_document(out_file, caption=heading)
|
105 |
+
await pro.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|