Fixes
This commit is contained in:
parent
bba190a782
commit
6762ec09bc
29
bot/main.py
29
bot/main.py
|
@ -1,5 +1,7 @@
|
||||||
from urllib import response
|
from urllib import response
|
||||||
from aiogram import types, Bot, Dispatcher
|
from aiogram import types, Bot, Dispatcher
|
||||||
|
from aiogram.utils.text_decorations import markdown_decoration
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
@ -15,24 +17,41 @@ bot: Bot = Bot(TOKEN)
|
||||||
|
|
||||||
dp: Dispatcher = Dispatcher()
|
dp: Dispatcher = Dispatcher()
|
||||||
|
|
||||||
|
|
||||||
|
def escape_md(text):
|
||||||
|
return markdown_decoration.quote(text)
|
||||||
|
|
||||||
|
|
||||||
@dp.message(commands=['run'])
|
@dp.message(commands=['run'])
|
||||||
async def message_handler(message: types.Message):
|
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
|
msg = message.reply_to_message
|
||||||
if not msg.entities: return
|
if not msg.entities:
|
||||||
|
return
|
||||||
print(msg.text)
|
print(msg.text)
|
||||||
|
|
||||||
for entity in msg.entities:
|
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)
|
code = entity.extract(msg.text)
|
||||||
resp = requests.post(HOST+"/run", data={'code': code})
|
resp = requests.post(HOST+"/run", data={'code': code})
|
||||||
json = resp.json()
|
json = resp.json()
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
return await msg.answer("Произошла ошибка:\n" + json["stderr"])
|
if json['stderr'].strip() == "":
|
||||||
await msg.reply(f"Резульат\n```gd\n{json['result']}\n```", parse_mode="MarkdownV2")
|
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():
|
def main():
|
||||||
dp.run_polling(bot)
|
dp.run_polling(bot)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -8,4 +8,5 @@ services:
|
||||||
- ./data/logs:/app/logs
|
- ./data/logs:/app/logs
|
||||||
bot:
|
bot:
|
||||||
build: ./bot
|
build: ./bot
|
||||||
|
env_file:
|
||||||
|
- ./bot/.env
|
||||||
|
|
|
@ -80,7 +80,7 @@ func main() {
|
||||||
err_sep = append(err_sep, "")
|
err_sep = append(err_sep, "")
|
||||||
}
|
}
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
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
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,8 @@ func _init():
|
||||||
var Directory = null
|
var Directory = null
|
||||||
var ConfigFile = null
|
var ConfigFile = null
|
||||||
var File = null
|
var File = null
|
||||||
|
var HTTPClient = null
|
||||||
|
var GDScript = null
|
||||||
print("=== {{ .Id }} ===")
|
print("=== {{ .Id }} ===")
|
||||||
printerr("=== {{ .Id }} === ")
|
printerr("=== {{ .Id }} === ")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue