From 0c5ab590c43be146d3da89ca3072d2b44e4af3e6 Mon Sep 17 00:00:00 2001 From: Trueold89 Date: Wed, 4 Sep 2024 19:41:01 +0300 Subject: [PATCH] Add controller.py --- u232ping/controller.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 u232ping/controller.py diff --git a/u232ping/controller.py b/u232ping/controller.py new file mode 100644 index 0000000..9e454e9 --- /dev/null +++ b/u232ping/controller.py @@ -0,0 +1,27 @@ +from u232ping.abc.db import DataBase +from u232ping.types import Group +from aiogram.types import Message + +class Controller(object): + + db: DataBase + + def __init__(self, db_implementation: DataBase) -> None: + self.db = db_implementation + + async def _ping(self, msg: Message, group: int | None = None) -> None: + gtp: Group + if group is None: + gtp = await self.db.get_all() + else: + gtp = await self.db.get_group(group) + msg.answer(str(gtp)) + + async def all(self, msg: Message) -> None: + await self._ping(msg) + + async def first(self, msg: Message) -> None: + await self._ping(msg, 1) + + async def second(self, msg: Message) -> None: + await self._ping(msg, 2)