All checks were successful
continuous-integration/drone/push Build is passing
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
from aiogram import Bot, Dispatcher, types
|
|
from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
|
from aiogram.utils import executor
|
|
from aiogram.dispatcher.filters import Text
|
|
from pomodoro_bot.user_manager import user_manager
|
|
from pomodoro_bot.timer_manager import TimerManager
|
|
import os
|
|
|
|
API_TOKEN = os.getenv("BOT_TOKEN")
|
|
|
|
bot = Bot(token=API_TOKEN)
|
|
dp = Dispatcher(bot)
|
|
|
|
menu_kb = InlineKeyboardMarkup(row_width=2)
|
|
menu_kb.add(
|
|
InlineKeyboardButton("▶️ Pomodoro", callback_data="action_pomodoro"),
|
|
InlineKeyboardButton("☕ Short Break", callback_data="action_shortbreak"),
|
|
InlineKeyboardButton("😌 Long Break", callback_data="action_longbreak"),
|
|
InlineKeyboardButton("⏹ Stop", callback_data="action_stop")
|
|
)
|
|
|
|
|
|
|
|
from pomodoro_bot.redis_client import init_redis
|
|
|
|
async def on_startup(dispatcher):
|
|
await init_redis()
|
|
dispatcher['timer_manager'] = TimerManager(bot)
|
|
|
|
@dispatcher.message_handler(commands=['start', 'help'])
|
|
async def send_welcome(message: Message):
|
|
await message.answer("Привет! Я твой личный Pomodoro-бот. Выбирай действие:", reply_markup=menu_kb)
|
|
|
|
@dispatcher.callback_query_handler(lambda call: call.data.startswith("action_"))
|
|
async def handle_callback(call: types.CallbackQuery):
|
|
print(f"[DEBUG handle_callback] Received call.data: {call.data!r}")
|
|
print(f"[DEBUG handle_callback] call.data repr: {repr(call.data)}")
|
|
timer_manager = dispatcher['timer_manager']
|
|
|
|
if "pomodoro" in call.data:
|
|
await timer_manager.start_timer(call.from_user.id, 25*60, call.message.chat.id, 'Pomodoro')
|
|
await call.message.answer("Начался 25-минутный Pomodoro! 🔥")
|
|
elif "shortbreak" in call.data:
|
|
await timer_manager.start_timer(call.from_user.id, 5*60, call.message.chat.id, 'Short Break')
|
|
await call.message.answer("Начался 5-минутный перерыв ☕")
|
|
elif "longbreak" in call.data:
|
|
await timer_manager.start_timer(call.from_user.id, 15*60, call.message.chat.id, 'Long Break')
|
|
await call.message.answer("Начался длинный перерыв 😌")
|
|
elif "stop" in call.data:
|
|
await timer_manager.stop_timer(call.from_user.id)
|
|
await call.message.answer("Таймер остановлен ⏹")
|
|
await call.answer()
|
|
|
|
|
|
print(f"[DEBUG fallback] Got unmatched callback: {call.data!r}")
|
|
|
|
def run_bot():
|
|
executor.start_polling(dp, skip_updates=True, on_startup=on_startup) |