|
@@ -1,3 +1,4 @@
|
|
|
+from io import BytesIO
|
|
|
from sys import executable
|
|
|
from struct import pack
|
|
|
from asyncio import create_subprocess_shell
|
|
@@ -13,6 +14,7 @@ from aiofiles.os import (
|
|
|
)
|
|
|
from aiohttp import ClientSession
|
|
|
from emoji import is_emoji
|
|
|
+from cairosvg import svg2png
|
|
|
|
|
|
from actions import (
|
|
|
find_action,
|
|
@@ -407,6 +409,68 @@ async def vpn_handler(bot, event, command):
|
|
|
|
|
|
await event.reply('Готово!!~~ Файл конфигурации WireGuard отправлен в Ваши личные сообщения!')
|
|
|
|
|
|
+async def sylvy_handler(bot, event, command):
|
|
|
+ if command.argc < 1:
|
|
|
+ await event.reply('Пожалуйста, не оставляйте ввод пустым!')
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+ async with ClientSession() as session:
|
|
|
+ try:
|
|
|
+ async with session.post(
|
|
|
+ f'https://sylvy-engine.txlyre.website/api/computeSingle',
|
|
|
+ json={'program': command.args_string, 'stringify': True}
|
|
|
+ ) as resp:
|
|
|
+ data = await resp.json()
|
|
|
+
|
|
|
+ if data['status'] != 'ok':
|
|
|
+ await event.reply(f'Ошибка API Sylvy: {data['data']['message']}')
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+ result = data['data']['result']
|
|
|
+ except:
|
|
|
+ await event.reply('Произошла ошибка при попытке обращения к API Sylvy… :(')
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+ if result.status != 'SUCCESS':
|
|
|
+ await event.reply(f'Ошибка исполнения:\n```{result.stdout}```')
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+ text = ''
|
|
|
+
|
|
|
+ if result.stdout:
|
|
|
+ text += result.stdout
|
|
|
+ text += '\n'
|
|
|
+
|
|
|
+ text += result.output
|
|
|
+
|
|
|
+ if result.plots:
|
|
|
+ plots = []
|
|
|
+
|
|
|
+ for plot in result.plots:
|
|
|
+ buffer = BytesIO()
|
|
|
+
|
|
|
+ svg2png(
|
|
|
+ bytestring=plot,
|
|
|
+ write_to=buffer
|
|
|
+ )
|
|
|
+
|
|
|
+ plots.append(buffer)
|
|
|
+
|
|
|
+ await bot.send_file(
|
|
|
+ message.peer_id,
|
|
|
+ file=plots,
|
|
|
+ reply_to=message,
|
|
|
+ caption=text
|
|
|
+ )
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+ await event.reply(f'```{text}```')
|
|
|
+
|
|
|
COMMANDS = {
|
|
|
'newadmin': Handler(newadmin_handler, is_restricted=True),
|
|
|
'deladmin': Handler(deladmin_handler, is_restricted=True),
|
|
@@ -422,5 +486,7 @@ COMMANDS = {
|
|
|
|
|
|
'bday': Handler(bday_handler),
|
|
|
|
|
|
- 'vpn': Handler(vpn_handler)
|
|
|
+ 'vpn': Handler(vpn_handler),
|
|
|
+
|
|
|
+ 'sylvy': Handler(sylvy_handler),
|
|
|
}
|