mirror of https://github.com/coddrago/Heroku
test
parent
6a66451865
commit
fbdd60c5e7
|
@ -562,6 +562,7 @@ eval:
|
|||
_cls_doc: "Führt Code in verschiedenen Programmiersprachen aus"
|
||||
compiling: "<emoji document_id=5325787248363314644>🫥</emoji> <b>Code wird kompiliert...</b>"
|
||||
no_compiler: "<emoji document_id={}>💻</emoji> <b>Compiler {} ist auf dem System nicht installiert.</b>"
|
||||
print_outp: "<emoji document_id=5118861066981344121>✅</emoji> Ergebnis drucken\n<pre><code class=\"language-python\">{}</code></pre>"
|
||||
_cmd_doc_e: "Führt Python-Code aus"
|
||||
_cmd_doc_ebf: "Führt Brainf*ck-Code aus"
|
||||
_cmd_doc_ec: "Führt C-Code aus"
|
||||
|
|
|
@ -597,6 +597,7 @@ eval:
|
|||
err: "<emoji document_id={}>💻</emoji><b> Code:</b>\n<pre><code class=\"language-{}\">{}</code></pre>\n\n<emoji document_id=5210952531676504517>🚫</emoji> <b>Error:</b>\n<pre><code class=\"language-{}\">{}</code></pre>"
|
||||
compiling: "<emoji document_id=5325787248363314644>🫥</emoji> <b>Compiling code...</b>"
|
||||
no_compiler: "<emoji document_id={}>💻</emoji> <b>{} compiler is not installed on the system.</b>"
|
||||
print_outp: "<emoji document_id=5118861066981344121>✅</emoji> Print Result\n<pre><code class=\"language-python\">{}</code></pre>"
|
||||
_cmd_doc_e: "Evaluates python code"
|
||||
_cmd_doc_ebf: "Evaluates Brainf*ck code"
|
||||
_cmd_doc_ec: "Evaluates C code"
|
||||
|
|
|
@ -556,6 +556,7 @@ eval:
|
|||
_cls_doc: "Выполняет код на различных языках программирования"
|
||||
compiling: "<emoji document_id=5325787248363314644>🫥</emoji> <b>Компиляция кода...</b>"
|
||||
no_compiler: "<emoji document_id={}>💻</emoji> <b>Компилятор {} не установлен на системе.</b>"
|
||||
print_outp: "<emoji document_id=5118861066981344121>✅</emoji> Print Result\n<pre><code class=\"language-python\">{}</code></pre>"
|
||||
_cmd_doc_e: "Выполняет Python код"
|
||||
_cmd_doc_ebf: "Выполняет Brainf*ck код"
|
||||
_cmd_doc_ec: "Выполняет C код"
|
||||
|
|
|
@ -563,6 +563,7 @@ eval:
|
|||
_cls_doc: "Виконує код різними мовами програмування"
|
||||
compiling: "<emoji document_id=5325787248363314644>🫥</emoji> <b>Компіляція коду...</b>"
|
||||
no_compiler: "<emoji document_id={}>💻</emoji> <b>Компілятор {} не встановлено в системі.</b>"
|
||||
print_outp: "<emoji document_id=5118861066981344121>✅</emoji> Друкувати результат\n<pre><code class=\"language-python\">{}</code></pre>"
|
||||
_cmd_doc_e: "Виконує Python код"
|
||||
_cmd_doc_ebf: "Виконує Brainf*ck код"
|
||||
_cmd_doc_ec: "Виконує C код"
|
||||
|
|
|
@ -24,6 +24,7 @@ from herokutl.errors.rpcerrorlist import MessageIdInvalidError
|
|||
from herokutl.sessions import StringSession
|
||||
from herokutl.tl.types import Message
|
||||
from meval import meval
|
||||
from io import StringIO
|
||||
|
||||
from .. import loader, main, utils
|
||||
from ..log import HerokuException
|
||||
|
@ -156,11 +157,15 @@ class Evaluator(loader.Module):
|
|||
@loader.command(alias="eval")
|
||||
async def e(self, message: Message):
|
||||
try:
|
||||
result = await meval(
|
||||
utils.get_args_raw(message),
|
||||
globals(),
|
||||
**await self.getattrs(message),
|
||||
)
|
||||
output_print = StringIO()
|
||||
with contextliv.redirect_stdout(output_print)
|
||||
result = await meval(
|
||||
utils.get_args_raw(message),
|
||||
globals(),
|
||||
**await self.getattrs(message),
|
||||
)
|
||||
print_output = output_print.getvalue()
|
||||
|
||||
except Exception:
|
||||
item = HerokuException.from_exc_info(*sys.exc_info())
|
||||
|
||||
|
@ -197,7 +202,10 @@ class Evaluator(loader.Module):
|
|||
utils.escape_html(utils.get_args_raw(message)),
|
||||
"python",
|
||||
utils.escape_html(self.censor(str(result))),
|
||||
),
|
||||
) + (utils.escape_html(self.strings["print_outp"].format(
|
||||
"python",
|
||||
print_output,
|
||||
)) if print_output else ""),
|
||||
)
|
||||
|
||||
@loader.command()
|
||||
|
@ -474,6 +482,7 @@ class Evaluator(loader.Module):
|
|||
"chat": message.to_id,
|
||||
"herokutl": herokutl,
|
||||
"telethon": herokutl,
|
||||
"hikkatl": herokutl,
|
||||
"utils": utils,
|
||||
"main": main,
|
||||
"loader": loader,
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
# █▀▀ ▄▀█ █▀▄▀█ █▀█ █▀▄ █▀
|
||||
# █▀░ █▀█ █░▀░█ █▄█ █▄▀ ▄█
|
||||
|
||||
# https://t.me/famods
|
||||
|
||||
# 🔒 Licensed under the GNU AGPLv3
|
||||
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Name: Executor
|
||||
# Description: Выполнение python кода
|
||||
# meta developer: @FAmods
|
||||
# meta banner: https://github.com/FajoX1/FAmods/blob/main/assets/banners/executor.png?raw=true
|
||||
# -------------------------------------------------------------------------------—
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
import html
|
||||
import time
|
||||
import herokutl
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from meval import meval
|
||||
from io import StringIO
|
||||
|
||||
from .. import loader, utils
|
||||
from ..log import HerokuException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@loader.tds
|
||||
class Executor(loader.Module):
|
||||
"""Выполнение python кода"""
|
||||
|
||||
strings = {
|
||||
"name": "Executor"
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.config = loader.ModuleConfig(
|
||||
loader.ConfigValue(
|
||||
"hide_phone",
|
||||
True,
|
||||
lambda: self.strings["no_phone"],
|
||||
validator=loader.validators.Boolean()
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def client_ready(self, client, db):
|
||||
self.db = db
|
||||
self._client = client
|
||||
|
||||
async def cexecute(self, code, message, reply):
|
||||
client = self.client
|
||||
me = await client.get_me()
|
||||
reply = await message.get_reply_message()
|
||||
functions = {
|
||||
"message": message,
|
||||
"client": self._client,
|
||||
"reply": reply,
|
||||
"r": reply,
|
||||
"event": message,
|
||||
"chat": message.to_id,
|
||||
"me": me,
|
||||
"herokutl": herokutl,
|
||||
"telethon": herokutl,
|
||||
"utils": utils,
|
||||
"loader": loader,
|
||||
"f": herokutl.tl.functions,
|
||||
"c": self._client,
|
||||
"m": message,
|
||||
"lookup": self.lookup,
|
||||
"self": self,
|
||||
"db": self.db,
|
||||
}
|
||||
result = sys.stdout = StringIO()
|
||||
try:
|
||||
res = await meval(
|
||||
code,
|
||||
globals(),
|
||||
**functions,
|
||||
)
|
||||
except:
|
||||
return traceback.format_exc().strip(), None, True
|
||||
return result.getvalue().strip(), res, False
|
||||
|
||||
@loader.command()
|
||||
async def execcmd(self, message):
|
||||
"""Выполнить python код"""
|
||||
|
||||
code = utils.get_args_raw(message)
|
||||
if not code:
|
||||
return await utils.answer(message, self.strings["no_code"].format(self.get_prefix()))
|
||||
|
||||
await utils.answer(message, self.strings["executing"])
|
||||
|
||||
reply = await message.get_reply_message()
|
||||
|
||||
start_time = time.perf_counter()
|
||||
result, res, cerr = await self.cexecute(code, message, reply)
|
||||
stop_time = time.perf_counter()
|
||||
|
||||
me = await self.client.get_me()
|
||||
|
||||
result = str(result)
|
||||
res = str(res)
|
||||
|
||||
if self.config['hide_phone']:
|
||||
t_h = "never gonna give you up"
|
||||
|
||||
if result:
|
||||
result = result.replace("+"+me.phone, t_h).replace(me.phone, t_h)
|
||||
if res:
|
||||
res = res.replace("+"+me.phone, t_h).replace(me.phone, t_h)
|
||||
|
||||
if result:
|
||||
if not cerr:
|
||||
result = self.strings["result_no_error"].format(result=result)
|
||||
else:
|
||||
result = self.strings["result_error"].format(result=result)
|
||||
|
||||
if res or res == 0 or res == False and res is not None:
|
||||
result += self.strings["res_return"].format(res=res)
|
||||
|
||||
return await utils.answer(message, self.strings["result"].format(code=code, result=result, time=round(stop_time - start_time, 5)))
|
Loading…
Reference in New Issue