diff --git a/mirrortea/__main__.py b/mirrortea/__main__.py index 44bd80d..c37c69d 100644 --- a/mirrortea/__main__.py +++ b/mirrortea/__main__.py @@ -1,7 +1,6 @@ import asyncio -from messengers import Matrix as MatrixLoop -from abstract_source_platform.telegram import Telegram +from messengers import Matrix as MatrixLoop, Telegram as TelegramLoop from config_dataclass import Config @@ -18,14 +17,14 @@ class Application: def __init__(self, config): self.config = config self.matrix_loop = MatrixLoop(self) - self.telegram = Telegram(self) + self.telegram_loop = TelegramLoop(self) async def run(self): try: await self.matrix_loop.prepare() await asyncio.gather( self.matrix_loop.run(), - self.telegram.run(), + self.telegram_loop.run(), ) finally: if self.matrix_loop: diff --git a/mirrortea/abstract_source_platform/__init__.py b/mirrortea/abstract_source_platform/__init__.py deleted file mode 100644 index 815fa79..0000000 --- a/mirrortea/abstract_source_platform/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from abstract_source_platform.telegram import Telegram - -platforms = [Telegram] diff --git a/mirrortea/abstract_source_platform/abstact_source_platform.py b/mirrortea/abstract_source_platform/abstact_source_platform.py deleted file mode 100644 index f12d8b3..0000000 --- a/mirrortea/abstract_source_platform/abstact_source_platform.py +++ /dev/null @@ -1,9 +0,0 @@ -from abc import ABC, abstractmethod - -from models.user import User - - -class AbstractSourcePlatform(ABC): - @abstractmethod - def get_user_information(self) -> User: - """Init tables in database""" diff --git a/mirrortea/abstract_source_platform/telegram.py b/mirrortea/abstract_source_platform/telegram.py deleted file mode 100644 index 0cb3916..0000000 --- a/mirrortea/abstract_source_platform/telegram.py +++ /dev/null @@ -1,24 +0,0 @@ -import sys -import aiogram as telegram - -from abstract_source_platform.abstact_source_platform import ( - AbstractSourcePlatform, -) -from models.user import User - - -class Telegram(AbstractSourcePlatform): - def __init__(self, app): - self.app = app - self.bot = telegram.Bot(token=app.config.telegram_bot_token) - self.dispatcher = telegram.Dispatcher(bot=self.bot) - self.dispatcher.register_message_handler(self.on_message) - - async def run(self): - await self.dispatcher.start_polling() - - async def on_message(self, msg): - print(msg, file=sys.stderr) - - async def get_user_information(self) -> User: - pass diff --git a/mirrortea/messengers/__init__.py b/mirrortea/messengers/__init__.py index 4200d22..11d43e6 100644 --- a/mirrortea/messengers/__init__.py +++ b/mirrortea/messengers/__init__.py @@ -1 +1,2 @@ from .matrix import Matrix +from .telegram import Telegram diff --git a/mirrortea/messengers/telegram.py b/mirrortea/messengers/telegram.py new file mode 100644 index 0000000..c3355e5 --- /dev/null +++ b/mirrortea/messengers/telegram.py @@ -0,0 +1,15 @@ +import aiogram +import sys + +class Telegram: + def __init__(self, app): + self.app = app + self.bot = aiogram.Bot(token=app.config.telegram_bot_token) + self.dispatcher = aiogram.Dispatcher(bot=self.bot) + self.dispatcher.register_message_handler(self.on_message) + + async def run(self): + await self.dispatcher.start_polling() + + async def on_message(self, msg): + print(msg, file=sys.stderr)