From 6762ec09bc0e08286b0269300a7698349519ffdd Mon Sep 17 00:00:00 2001 From: nefrace Date: Thu, 19 May 2022 15:09:57 +0300 Subject: [PATCH] Fixes --- bot/main.py | 31 +++++++++++++++++++++++++------ docker-compose.yml | 5 +++-- server/main.go | 2 +- server/template | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bot/main.py b/bot/main.py index 37935c9..760a9a2 100644 --- a/bot/main.py +++ b/bot/main.py @@ -1,5 +1,7 @@ from urllib import response from aiogram import types, Bot, Dispatcher +from aiogram.utils.text_decorations import markdown_decoration + import requests from dotenv import load_dotenv import os @@ -15,24 +17,41 @@ bot: Bot = Bot(TOKEN) dp: Dispatcher = Dispatcher() + +def escape_md(text): + return markdown_decoration.quote(text) + + @dp.message(commands=['run']) async def message_handler(message: types.Message): - if not message.reply_to_message: return + if not message.reply_to_message: + return msg = message.reply_to_message - if not msg.entities: return + if not msg.entities: + return print(msg.text) for entity in msg.entities: - if entity.type != "pre" and entity.type != "code": continue + if entity.type != "pre" and entity.type != "code": + continue code = entity.extract(msg.text) resp = requests.post(HOST+"/run", data={'code': code}) json = resp.json() if resp.status_code != 200: - return await msg.answer("Произошла ошибка:\n" + json["stderr"]) - await msg.reply(f"Резульат\n```gd\n{json['result']}\n```", parse_mode="MarkdownV2") + if json['stderr'].strip() == "": + return await msg.reply("Таймаут скрипта") + return await msg.reply("Произошла ошибка:\n" + json["stderr"]) + result = json['result'][:4095] + answer = f"{result}" + repr(result) + if result.strip() == "": + answer = "Скрипт выполнен, вывод пуст." + await msg.reply(answer) + def main(): dp.run_polling(bot) + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/docker-compose.yml b/docker-compose.yml index 12f5d3a..0e1e1a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: volumes: - ./data/scripts:/app/scripts - ./data/logs:/app/logs - bot: + bot: build: ./bot - \ No newline at end of file + env_file: + - ./bot/.env diff --git a/server/main.go b/server/main.go index 5b522e9..361a74a 100644 --- a/server/main.go +++ b/server/main.go @@ -80,7 +80,7 @@ func main() { err_sep = append(err_sep, "") } if ctx.Err() == context.DeadlineExceeded { - c.JSON(http.StatusRequestTimeout, gin.H{"status": "script timeout", "stdout": out_sep[1], "stderr": err_sep[1]}) + c.JSON(http.StatusRequestTimeout, gin.H{"status": "timeout", "stdout": out_sep[1], "stderr": err_sep[1]}) return } if err != nil { diff --git a/server/template b/server/template index 94936e6..9849650 100644 --- a/server/template +++ b/server/template @@ -7,6 +7,8 @@ func _init(): var Directory = null var ConfigFile = null var File = null + var HTTPClient = null + var GDScript = null print("=== {{ .Id }} ===") printerr("=== {{ .Id }} === ")