Add controller.py
This commit is contained in:
parent
3b7c9cacc7
commit
0c5ab590c4
|
@ -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)
|
Loading…
Reference in New Issue