Initial commit

This commit is contained in:
2022-05-19 12:18:00 +03:00
commit bba190a782
11 changed files with 391 additions and 0 deletions

2
bot/.dockerignore Normal file
View File

@ -0,0 +1,2 @@
env
Dockerfile

10
bot/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3-buster
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./main.py"]

38
bot/main.py Normal file
View File

@ -0,0 +1,38 @@
from urllib import response
from aiogram import types, Bot, Dispatcher
import requests
from dotenv import load_dotenv
import os
load_dotenv()
TOKEN = os.getenv("TOKEN")
HOST = os.getenv("HOST", "http://127.0.0.1:8080")
if not TOKEN:
print("Token not specified")
exit(1)
bot: Bot = Bot(TOKEN)
dp: Dispatcher = Dispatcher()
@dp.message(commands=['run'])
async def message_handler(message: types.Message):
if not message.reply_to_message: return
msg = message.reply_to_message
if not msg.entities: return
print(msg.text)
for entity in msg.entities:
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")
def main():
dp.run_polling(bot)
if __name__ == "__main__":
main()

21
bot/requirements.txt Normal file
View File

@ -0,0 +1,21 @@
aiofiles==0.8.0
aiogram==3.0.0b3
aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.2
attrs==21.4.0
Babel==2.9.1
certifi==2022.5.18
charset-normalizer==2.0.12
frozenlist==1.3.0
idna==3.3
magic-filter==1.0.7
multidict==6.0.2
pydantic==1.9.0
Pygments==2.12.0
python-dotenv==0.20.0
pytz==2022.1
requests==2.27.1
typing_extensions==4.2.0
urllib3==1.26.9
yarl==1.7.2