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

This commit is contained in:
2025-03-28 22:26:28 +05:00
parent 73d43f1dbb
commit 29c96fce8a
2 changed files with 44 additions and 34 deletions

View File

@@ -10,7 +10,26 @@ API_TOKEN = os.getenv("BOT_TOKEN")
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
timer_manager = None
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: Message):
await message.reply("Привет! Я твой личный Pomodoro-бот. Выбирай действие:", reply_markup=menu_kb)
@dp.callback_query_handler(Text(equals=["pomodoro", "shortbreak", "longbreak", "stop"]))
async def handle_callback(call: types.CallbackQuery):
if call.data == "pomodoro":
await timer_manager.start_timer(call.from_user.id, 25*60, call.message.chat.id, 'Pomodoro')
await call.message.answer("Начался 25-минутный Pomodoro! 🔥")
elif call.data == "shortbreak":
await timer_manager.start_timer(call.from_user.id, 5*60, call.message.chat.id, 'Short Break')
await call.message.answer("Начался 5-минутный перерыв ☕")
elif call.data == "longbreak":
await timer_manager.start_timer(call.from_user.id, 15*60, call.message.chat.id, 'Long Break')
await call.message.answer("Начался длинный перерыв 😌")
elif call.data == "stop":
await timer_manager.stop_timer(call.from_user.id)
await call.message.answer("Таймер остановлен ⏹")
await call.answer()
menu_kb = InlineKeyboardMarkup(row_width=2)
menu_kb.add(
@@ -20,32 +39,35 @@ menu_kb.add(
InlineKeyboardButton("⏹ Stop", callback_data="stop")
)
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: Message):
await message.reply("Привет! Я твой личный Pomodoro-бот. Выбирай действие:", reply_markup=menu_kb)
@dp.callback_query_handler(Text(equals=["pomodoro", "shortbreak", "longbreak", "stop"]))
async def handle_callback(call: types.CallbackQuery):
if call.data == "pomodoro":
await timer_manager.start_timer(call.from_user.id, 25*60, call.message.chat.id, 'Pomodoro')
await call.message.answer("Начался 25-минутный Pomodoro! 🔥")
elif call.data == "shortbreak":
await timer_manager.start_timer(call.from_user.id, 5*60, call.message.chat.id, 'Short Break')
await call.message.answer("Начался 5-минутный перерыв ☕")
elif call.data == "longbreak":
await timer_manager.start_timer(call.from_user.id, 15*60, call.message.chat.id, 'Long Break')
await call.message.answer("Начался длинный перерыв 😌")
elif call.data == "stop":
await timer_manager.stop_timer(call.from_user.id)
await call.message.answer("Таймер остановлен ⏹")
await call.answer()
from pomodoro_bot.redis_client import init_redis
async def on_startup(dispatcher):
global timer_manager
await init_redis()
timer_manager = TimerManager(bot, dispatcher.loop)
dispatcher['timer_manager'] = TimerManager(bot, dispatcher.loop)
@dispatcher.message_handler(commands=['start', 'help'])
async def send_welcome(message: Message):
await message.reply("Привет! Я твой личный Pomodoro-бот. Выбирай действие:", reply_markup=menu_kb)
@dispatcher.callback_query_handler(Text(equals=["pomodoro", "shortbreak", "longbreak", "stop"]))
async def handle_callback(call: types.CallbackQuery):
timer_manager = dispatcher['timer_manager']
if call.data == "pomodoro":
await timer_manager.start_timer(call.from_user.id, 25*60, call.message.chat.id, 'Pomodoro')
await call.message.answer("Начался 25-минутный Pomodoro! 🔥")
elif call.data == "shortbreak":
await timer_manager.start_timer(call.from_user.id, 5*60, call.message.chat.id, 'Short Break')
await call.message.answer("Начался 5-минутный перерыв ☕")
elif call.data == "longbreak":
await timer_manager.start_timer(call.from_user.id, 15*60, call.message.chat.id, 'Long Break')
await call.message.answer("Начался длинный перерыв 😌")
elif call.data == "stop":
await timer_manager.stop_timer(call.from_user.id)
await call.message.answer("Таймер остановлен ⏹")
await call.answer()
def run_bot():
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)

View File

@@ -29,16 +29,4 @@ class TimerManager:
user.task.cancel()
user.task = None
user.current_timer = 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
)
self.tasks.pop(user_id, None)