From 03ac89574ac726a0e80edd4264642df2f9152fb8 Mon Sep 17 00:00:00 2001 From: Trueold89 Date: Wed, 4 Sep 2024 22:57:58 +0300 Subject: [PATCH] ebal --- u232ping/setup.py => setup.py | 0 u232ping/bot.py | 12 +++++++++--- u232ping/controller.py | 17 ++++++++--------- u232ping/db.py | 4 ++-- u232ping/types.py | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) rename u232ping/setup.py => setup.py (100%) diff --git a/u232ping/setup.py b/setup.py similarity index 100% rename from u232ping/setup.py rename to setup.py diff --git a/u232ping/bot.py b/u232ping/bot.py index 71225e9..32462dc 100644 --- a/u232ping/bot.py +++ b/u232ping/bot.py @@ -6,6 +6,8 @@ from aiogram.filters import Command from aiogram.types import Message from u232ping.db import Sqlite from u232ping.controller import Controller +import logging +import sys TOKEN = environ["BOT_TOKEN"] dp = Dispatcher() @@ -14,19 +16,23 @@ c = Controller(Sqlite()) @dp.message(Command("all")) async def all(message: Message) -> None: - await c.all(message) + group = await c.all() + await message.answer(str(group)) @dp.message(Command("1")) async def first(message: Message) -> None: - await c.first(message) + group = await c.first() + await message.answer(str(group)) @dp.message(Command("2")) async def second(message: Message) -> None: - await c.second(message) + group = await c.second() + await message.answer(str(group)) async def main() -> None: bot = Bot(token=TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) + logging.basicConfig(level=logging.INFO, stream=sys.stdout) await dp.start_polling(bot) diff --git a/u232ping/controller.py b/u232ping/controller.py index 9e454e9..e19b25b 100644 --- a/u232ping/controller.py +++ b/u232ping/controller.py @@ -1,6 +1,5 @@ from u232ping.abc.db import DataBase from u232ping.types import Group -from aiogram.types import Message class Controller(object): @@ -9,19 +8,19 @@ class Controller(object): def __init__(self, db_implementation: DataBase) -> None: self.db = db_implementation - async def _ping(self, msg: Message, group: int | None = None) -> None: + async def _ping(self, group: int | None = None) -> Group: gtp: Group if group is None: gtp = await self.db.get_all() else: gtp = await self.db.get_group(group) - msg.answer(str(gtp)) + return gtp - async def all(self, msg: Message) -> None: - await self._ping(msg) + async def all(self) -> Group: + return await self._ping() - async def first(self, msg: Message) -> None: - await self._ping(msg, 1) + async def first(self) -> Group: + return await self._ping(1) - async def second(self, msg: Message) -> None: - await self._ping(msg, 2) + async def second(self) -> Group: + return await self._ping(2) diff --git a/u232ping/db.py b/u232ping/db.py index 9e98e0e..b30b1ad 100644 --- a/u232ping/db.py +++ b/u232ping/db.py @@ -13,12 +13,12 @@ class Sqlite(DataBase): async def _get(self, group: int | None = None) -> Group: req = "SELECT telegram FROM u232" if group is not None: - where = f" WHERE group = {group}" - req += where + req += f" WHERE sub = '{group}'" async with sq(self.path) as db: cursor = await db.cursor() await cursor.execute(req) fetch = await cursor.fetchall() + fetch = tuple(map(lambda i: i[0], fetch)) return Group(fetch) async def get_group(self, group_idx: int): diff --git a/u232ping/types.py b/u232ping/types.py index 59b207d..642cec1 100644 --- a/u232ping/types.py +++ b/u232ping/types.py @@ -9,4 +9,4 @@ class Group(object): def __str__(self) -> str: lst = tuple(map(lambda member: f"@{member}", self.members)) - return "/n".join(lst) + return "\n".join(lst)