From fbdd60c5e7644c62047b639048b2544c934ab17f Mon Sep 17 00:00:00 2001 From: Who? <155328415+coddrago@users.noreply.github.com> Date: Sun, 3 Aug 2025 07:11:49 +0000 Subject: [PATCH] test --- heroku/langpacks/de.yml | 1 + heroku/langpacks/en.yml | 1 + heroku/langpacks/ru.yml | 1 + heroku/langpacks/ua.yml | 1 + heroku/modules/eval.py | 21 ++++-- heroku/modules/executor.py | 127 ------------------------------------- 6 files changed, 19 insertions(+), 133 deletions(-) delete mode 100644 heroku/modules/executor.py diff --git a/heroku/langpacks/de.yml b/heroku/langpacks/de.yml index 2777fce..718cb48 100644 --- a/heroku/langpacks/de.yml +++ b/heroku/langpacks/de.yml @@ -562,6 +562,7 @@ eval: _cls_doc: "Führt Code in verschiedenen Programmiersprachen aus" compiling: "🫥 Code wird kompiliert..." no_compiler: "💻 Compiler {} ist auf dem System nicht installiert." + print_outp: " Ergebnis drucken\n
{}
" _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" diff --git a/heroku/langpacks/en.yml b/heroku/langpacks/en.yml index 02af1a6..d5eeb56 100644 --- a/heroku/langpacks/en.yml +++ b/heroku/langpacks/en.yml @@ -597,6 +597,7 @@ eval: err: "💻 Code:\n
{}
\n\n🚫 Error:\n
{}
" compiling: "🫥 Compiling code..." no_compiler: "💻 {} compiler is not installed on the system." + print_outp: " Print Result\n
{}
" _cmd_doc_e: "Evaluates python code" _cmd_doc_ebf: "Evaluates Brainf*ck code" _cmd_doc_ec: "Evaluates C code" diff --git a/heroku/langpacks/ru.yml b/heroku/langpacks/ru.yml index 52d41c9..bb5e53c 100644 --- a/heroku/langpacks/ru.yml +++ b/heroku/langpacks/ru.yml @@ -556,6 +556,7 @@ eval: _cls_doc: "Выполняет код на различных языках программирования" compiling: "🫥 Компиляция кода..." no_compiler: "💻 Компилятор {} не установлен на системе." + print_outp: " Print Result\n
{}
" _cmd_doc_e: "Выполняет Python код" _cmd_doc_ebf: "Выполняет Brainf*ck код" _cmd_doc_ec: "Выполняет C код" diff --git a/heroku/langpacks/ua.yml b/heroku/langpacks/ua.yml index 1a08c52..3502cfc 100644 --- a/heroku/langpacks/ua.yml +++ b/heroku/langpacks/ua.yml @@ -563,6 +563,7 @@ eval: _cls_doc: "Виконує код різними мовами програмування" compiling: "🫥 Компіляція коду..." no_compiler: "💻 Компілятор {} не встановлено в системі." + print_outp: " Друкувати результат\n
{}
" _cmd_doc_e: "Виконує Python код" _cmd_doc_ebf: "Виконує Brainf*ck код" _cmd_doc_ec: "Виконує C код" diff --git a/heroku/modules/eval.py b/heroku/modules/eval.py index f68a5f1..00ee4b5 100644 --- a/heroku/modules/eval.py +++ b/heroku/modules/eval.py @@ -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, diff --git a/heroku/modules/executor.py b/heroku/modules/executor.py deleted file mode 100644 index ca9aa85..0000000 --- a/heroku/modules/executor.py +++ /dev/null @@ -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))) \ No newline at end of file