This commit is contained in:
@@ -3,8 +3,9 @@ from .user_manager import user_manager
|
||||
from .models import UserState
|
||||
|
||||
class TimerManager:
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, loop):
|
||||
self.bot = bot
|
||||
self.loop = loop
|
||||
self.tasks = {}
|
||||
|
||||
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 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.current_timer = label
|
||||
user.task = task
|
||||
@@ -28,4 +29,16 @@ class TimerManager:
|
||||
user.task.cancel()
|
||||
user.task = 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
|
||||
)
|
||||
Reference in New Issue
Block a user