From de078919263442a2567a75c6f1c8ec1d17ee3aff Mon Sep 17 00:00:00 2001 From: itexpert228 <67105314+fdaser1337@users.noreply.github.com> Date: Fri, 20 Feb 2026 23:28:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=95=D0=B1=D0=B0=D1=82=D1=8C=20=D1=83=20?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8F=20=D0=B8=D0=B4=D0=B5=D0=B8,=20=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=8B=20=D0=B8=20=D0=B4=D0=B0=D0=BB=D1=8C=D1=88=D0=B5?= =?UTF-8?q?=20=D0=B3=D0=BE=D0=B2=D0=BE=D1=80=D0=B8=D1=82=D0=B5=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=20=D0=B0=D0=BB=D0=BA=D0=BE=D0=B3=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=20=D0=B2=D1=80=D0=B5=D0=B4=D0=B5=D0=BD...........7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/main.py b/main.py index 3a441d4..6d19090 100644 --- a/main.py +++ b/main.py @@ -293,6 +293,79 @@ def parse_up_down(text: str) -> tuple[str, str]: down = parts[1].strip() return up, down +def minutes_until_next_lesson(now: datetime | None = None) -> str: + import random + + if now is None: + now = datetime.now(ZoneInfo(DEFAULT_TZ)) + elif now.tzinfo is None: + now = now.replace(tzinfo=ZoneInfo(DEFAULT_TZ)) + + LESSON_DAYS = [1, 3] # 1 = вторник, 3 = четверг + LESSON_START = time(9, 50) + LESSON_END = time(11, 25) + + day = now.weekday() + + def lesson_start_for(day_offset: int) -> datetime: + target = now + timedelta(days=day_offset) + return target.replace( + hour=LESSON_START.hour, + minute=LESSON_START.minute, + second=0, + microsecond=0 + ) + + def lesson_end_today() -> datetime: + return now.replace( + hour=LESSON_END.hour, + minute=LESSON_END.minute, + second=0, + microsecond=0 + ) + + # ---- Проверяем: сейчас внутри пары? ---- + if day in LESSON_DAYS: + start_today = lesson_start_for(0) + end_today = lesson_end_today() + + if start_today <= now < end_today: + # ищем следующую пару (не сегодняшнюю) + for i in range(1, 8): + next_day = (day + i) % 7 + if next_day in LESSON_DAYS: + next_dt = lesson_start_for(i) + break + + delta = next_dt - now + total_seconds = int(delta.total_seconds()) + days = total_seconds // 86400 + hours = (total_seconds % 86400) // 3600 + minutes = (total_seconds % 3600) // 60 + + percent = random.randint(0, 100) + + return ( + f"Сегодня твой мозг сгнил на {percent}%\n" + f"Мозг начнет догнивать через {days} дн {hours} ч {minutes} мин" + ) + + # ---- Ищем ближайшую будущую пару ---- + for i in range(0, 8): + next_day = (day + i) % 7 + if next_day in LESSON_DAYS: + candidate = lesson_start_for(i) + if candidate > now: + delta = candidate - now + break + + total_seconds = int(delta.total_seconds()) + days = total_seconds // 86400 + hours = (total_seconds % 86400) // 3600 + minutes = (total_seconds % 3600) // 60 + + return f"Твой мозг окончательно сгниет, а очко порвется через: {days} дн {hours} ч {minutes} мин" + async def handle_start(message: Message): await message.answer("Соси") @@ -478,6 +551,10 @@ async def handle_fetch(message: Message): except Exception: await message.answer("unable to connect x-server гандон") +async def handle_zvetok(message: Message): + result = minutes_until_next_lesson() + await message.answer(result) + def main(): token = os.getenv("BOT_TOKEN") @@ -499,6 +576,7 @@ def main(): BotCommand(command="size", description="хуй"), BotCommand(command="prices", description="цены x-server"), BotCommand(command="fetch", description="цены (новый источник)"), + BotCommand(command="zvetok", description="Цветянский бля"), ] ) except Exception: # noqa: WPS440 @@ -513,6 +591,7 @@ def main(): dp.message.register(handle_size, Command("size")) dp.message.register(handle_prices, Command("prices")) dp.message.register(handle_fetch, Command("fetch")) + dp.message.register(handle_zvetok, Command("zvetok"))