1
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
Alex Kotov e1177d388d
Add Telegram callback 2023-01-08 17:57:21 +04:00
Alex Kotov f78baf0f68
Mount source code as volume 2023-01-08 17:57:21 +04:00
Alex Kotov 87308db512
Improve project structure 2023-01-08 17:57:21 +04:00
4 changed files with 18 additions and 10 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
__pycache__/
/.env

View File

@ -1,9 +1,9 @@
FROM ubuntu:22.10
RUN mkdir /app
RUN mkdir -p /app/mirrortea/
WORKDIR /app
RUN apt-get update --yes
RUN apt-get install --yes python3 python3-pip
COPY requirements.txt /app
COPY requirements.txt /app/
RUN pip3 install -r requirements.txt
COPY mirrortea /app
ENTRYPOINT ["/app/mirrortea"]
COPY mirrortea/* /app/mirrortea/
ENTRYPOINT ["/usr/bin/python3", "/app/mirrortea"]

View File

@ -4,3 +4,5 @@ services:
app:
build: .
env_file: '.env'
volumes:
- './mirrortea:/app/mirrortea/'

16
mirrortea → mirrortea/__main__.py Executable file → Normal file
View File

@ -1,5 +1,3 @@
#!/usr/bin/env python3
import asyncio
import os
import sys
@ -16,15 +14,18 @@ async def main():
try:
matrix_client = \
matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID)
matrix_client.add_event_callback(matrix_on_message,
matrix.RoomMessage)
await matrix_client.login(MATRIX_PASSWORD)
telegram_client = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
telegram_bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
telegram_dispatcher = telegram.Dispatcher(bot=telegram_bot)
telegram_dispatcher.register_message_handler(telegram_on_message)
await asyncio.gather(matrix_loop(matrix_client), telegram_loop())
await asyncio.gather(
matrix_loop(matrix_client),
telegram_loop(),
)
finally:
if matrix_client:
await matrix_client.close()
@ -38,5 +39,8 @@ async def telegram_loop():
async def matrix_on_message(room, event):
print(room, event, file=sys.stderr)
async def telegram_on_message(msg):
print(msg, file=sys.stderr)
if __name__ == '__main__':
asyncio.run(main())