fix notification
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-28 22:17:52 +05:00
parent c4a51ddbc6
commit 73d43f1dbb
2 changed files with 19 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ API_TOKEN = os.getenv("BOT_TOKEN")
bot = Bot(token=API_TOKEN) bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot) dp = Dispatcher(bot)
timer_manager = TimerManager(bot) timer_manager = None
menu_kb = InlineKeyboardMarkup(row_width=2) menu_kb = InlineKeyboardMarkup(row_width=2)
menu_kb.add( menu_kb.add(
@@ -43,7 +43,9 @@ async def handle_callback(call: types.CallbackQuery):
from pomodoro_bot.redis_client import init_redis from pomodoro_bot.redis_client import init_redis
async def on_startup(dispatcher): async def on_startup(dispatcher):
global timer_manager
await init_redis() await init_redis()
timer_manager = TimerManager(bot, dispatcher.loop)
def run_bot(): def run_bot():
executor.start_polling(dp, skip_updates=True, on_startup=on_startup) executor.start_polling(dp, skip_updates=True, on_startup=on_startup)

View File

@@ -3,8 +3,9 @@ from .user_manager import user_manager
from .models import UserState from .models import UserState
class TimerManager: class TimerManager:
def __init__(self, bot): def __init__(self, bot, loop):
self.bot = bot self.bot = bot
self.loop = loop
self.tasks = {} self.tasks = {}
async def start_timer(self, user_id, duration, chat_id, label): async def start_timer(self, user_id, duration, chat_id, label):
@@ -16,7 +17,7 @@ class TimerManager:
await user_manager.increment_pomodoros(user_id) await user_manager.increment_pomodoros(user_id)
await self.bot.send_message(chat_id, f"{label} завершён!") await self.bot.send_message(chat_id, f"{label} завершён!")
task = asyncio.create_task(timer()) task = self.loop.create_task(timer())
user = user_manager.get_user(user_id) user = user_manager.get_user(user_id)
user.current_timer = label user.current_timer = label
user.task = task user.task = task
@@ -29,3 +30,15 @@ class TimerManager:
user.task = None user.task = None
user.current_timer = None user.current_timer = None
self.tasks.pop(user_id, None) self.tasks.pop(user_id, None)
# pomodoro_bot/redis_client.py
import redis.asyncio as redis
import os
r = None
async def init_redis():
global r
r = redis.Redis.from_url(
os.getenv("REDIS_URL", "redis://localhost"), decode_responses=True
)