From 887db84039667d11f1de83979a95d8acd684acba Mon Sep 17 00:00:00 2001 From: Belikov Maxim Date: Tue, 4 Mar 2025 14:28:20 +0200 Subject: [PATCH] fix tomorrow command --- app/bot/handlers/group/enable.py | 6 +++++- app/bot/handlers/group/tomorrow.py | 14 ++++++++------ app/bot/handlers/private/enable.py | 6 +++++- app/bot/handlers/private/tomorrow.py | 7 ++----- app/services/base_api.py | 4 ++-- app/services/exceptions/response_exception.py | 4 ++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/bot/handlers/group/enable.py b/app/bot/handlers/group/enable.py index 3d7fa07..5e03978 100644 --- a/app/bot/handlers/group/enable.py +++ b/app/bot/handlers/group/enable.py @@ -24,6 +24,10 @@ async def enable(message: Message, user: Student, telegram_groups: TelegramGroup post_info=not telegram_group.post_info ) ) - await message.reply("Сповіщення увімкнено" if telegram_group.post_info else "Сповіщення вимкнено") + await message.reply( + "Сповіщення увімкнено" + if (not telegram_group or telegram_group.post_info) + else "Сповіщення вимкнено" + ) except ResponseException as e: logging.error(e) diff --git a/app/bot/handlers/group/tomorrow.py b/app/bot/handlers/group/tomorrow.py index cbd5ff5..f6c7f7d 100644 --- a/app/bot/handlers/group/tomorrow.py +++ b/app/bot/handlers/group/tomorrow.py @@ -6,19 +6,21 @@ from app.utils.date_service import DateService -async def tomorrow(message: Message, telegram_groups: TelegramGroupsByTelegramId) -> None: +async def tomorrow( + message: Message, telegram_groups: TelegramGroupsByTelegramId +) -> None: for telegram_group in telegram_groups.telegram_groups: async with ScheduleAPI() as schedule_api: general_events = await schedule_api.get_general_group_events_by_day( - telegram_group.group.id, - day=(DateService.get_current_weekday() + 2) % 7, - week=DateService.get_week_by_day(DateService.get_current_day() + 1) + telegram_group.group.id, day=DateService.get_current_day() + 1 ) if not general_events.events: await message.reply(f"У групи {telegram_group.group.code} пар немає") else: await message.reply( - await EVENT_LIST.render_async(group=telegram_group.group.code, events=general_events.events), - disable_web_page_preview=True + await EVENT_LIST.render_async( + group=telegram_group.group.code, events=general_events.events + ), + disable_web_page_preview=True, ) diff --git a/app/bot/handlers/private/enable.py b/app/bot/handlers/private/enable.py index 3b7b0e7..1af4321 100644 --- a/app/bot/handlers/private/enable.py +++ b/app/bot/handlers/private/enable.py @@ -41,6 +41,10 @@ async def enable(message: Message) -> None: post_info=not telegram_group.post_info ) ) - await message.reply("Сповіщення увімкнено" if telegram_group.post_info else "Сповіщення вимкнено") + await message.reply( + "Сповіщення увімкнено" + if (not telegram_group or telegram_group.post_info) + else "Сповіщення вимкнено" + ) except ResponseException as e: logging.error(e) diff --git a/app/bot/handlers/private/tomorrow.py b/app/bot/handlers/private/tomorrow.py index 573efb4..344fced 100644 --- a/app/bot/handlers/private/tomorrow.py +++ b/app/bot/handlers/private/tomorrow.py @@ -11,10 +11,7 @@ async def tomorrow(message: Message) -> None: user = await user_api.get_user_by_telegram_id(message.from_user.id) # type: ignore[union-attr] async with ScheduleAPI() as schedule_api: general_events = await schedule_api.get_general_group_events_by_day( - user.group.id, - user_id=user.id, - day=(DateService.get_current_weekday() + 2) % 7, - week=DateService.get_week_by_day(DateService.get_current_day() + 1) + user.group.id, user_id=user.id, day=DateService.get_current_day() + 1 ) if not general_events.events: @@ -23,5 +20,5 @@ async def tomorrow(message: Message) -> None: await message.answer( await EVENT_LIST.render_async(events=general_events.events), - disable_web_page_preview=True + disable_web_page_preview=True, ) diff --git a/app/services/base_api.py b/app/services/base_api.py index b0d748f..da6c677 100644 --- a/app/services/base_api.py +++ b/app/services/base_api.py @@ -1,5 +1,5 @@ from types import TracebackType -from typing import Dict, Optional, Self, Type +from typing import Dict, Optional, Type import aiohttp from pydantic import AnyUrl @@ -27,7 +27,7 @@ def base_url(self) -> URL: def path(self) -> str: return self.base_url.path + self._path - async def __aenter__(self) -> Self: + async def __aenter__(self): # type: ignore return self async def __aexit__( diff --git a/app/services/exceptions/response_exception.py b/app/services/exceptions/response_exception.py index 1320ea1..426f082 100644 --- a/app/services/exceptions/response_exception.py +++ b/app/services/exceptions/response_exception.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Any, Dict, Self +from typing import Any, Dict from pydantic import BaseModel from pydantic.dataclasses import dataclass @@ -23,7 +23,7 @@ def __str__(self) -> str: return self.message @classmethod - def from_json(cls, json: Dict[str, Any]) -> Self: + def from_json(cls, json: Dict[str, Any]): # type: ignore return cls( **ResponseExceptionData .model_validate(json)