From 52d36613ee05b8f727da6424107a99da372475ce Mon Sep 17 00:00:00 2001 From: gnatykdm Date: Wed, 16 Jul 2025 22:15:58 +0200 Subject: [PATCH] Task-Configuration[Task-Menu] C:4 --- telegram_bot_project/bot/buttons.py | 17 ++++++++++++++++- telegram_bot_project/bot/callbacks.py | 4 ++-- telegram_bot_project/bot/handlers.py | 6 +++--- telegram_bot_project/main.py | 4 ++++ telegram_bot_project/messages.py | 6 ++++++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/telegram_bot_project/bot/buttons.py b/telegram_bot_project/bot/buttons.py index 5fe7e8f..26bdb1d 100644 --- a/telegram_bot_project/bot/buttons.py +++ b/telegram_bot_project/bot/buttons.py @@ -59,4 +59,19 @@ def task_reply_keyboard() -> InlineKeyboardMarkup: button_no: InlineKeyboardButton = InlineKeyboardButton(text=BUTTON_NO, callback_data="no_task") inline_markup.inline_keyboard.append([button_yes, button_no]) - return inline_markup \ No newline at end of file + return inline_markup + +def task_menu_keyboard() -> ReplyKeyboardMarkup: + task_menu_keyboard = ReplyKeyboardMarkup(keyboard=[], resize_keyboard=True, row_width=2) + + button_menu = KeyboardButton(text=MENU_BUTTON) + button_add = KeyboardButton(text=BUTTON_ADD_TASK) + button_status = KeyboardButton(text=BUTTON_TOGGLE_STATUS) + button_delete = KeyboardButton(text=BUTTON_DELETE_TASK) + button_update = KeyboardButton(text=BUTTON_EDIT_TASK) + + task_menu_keyboard.keyboard.append([button_add, button_status]) + task_menu_keyboard.keyboard.append([button_delete, button_update]) + task_menu_keyboard.keyboard.append([button_menu]) + + return task_menu_keyboard \ No newline at end of file diff --git a/telegram_bot_project/bot/callbacks.py b/telegram_bot_project/bot/callbacks.py index dbd8af4..ca39aed 100644 --- a/telegram_bot_project/bot/callbacks.py +++ b/telegram_bot_project/bot/callbacks.py @@ -2,7 +2,7 @@ from aiogram import types from aiogram.fsm.context import FSMContext -from bot.buttons import menu_reply_keyboard, idea_reply_keyboard +from bot.buttons import menu_reply_keyboard, idea_reply_keyboard, task_menu_keyboard from messages import MESSAGES from service.idea import IdeaService from service.task import TaskService @@ -102,7 +102,7 @@ async def callback_task_deadline(callback_query: types.CallbackQuery, state: FSM print(f"--[INFO] - User {user_id} ({user_name}) saved task: {saved_task}") await TaskService.create_task(user_id, saved_task, False) - await callback_query.message.answer(MESSAGES[language]["TASK_DEADLINE_NO"], reply_markup=menu_reply_keyboard()) + await callback_query.message.answer(MESSAGES[language]["TASK_DEADLINE_NO"], reply_markup=task_menu_keyboard()) await state.clear() case _: print(f"--[INFO] - User {user_id} ({user_name}) sent invalid callback: {callback_query.data}") diff --git a/telegram_bot_project/bot/handlers.py b/telegram_bot_project/bot/handlers.py index 266d279..6f9c12e 100644 --- a/telegram_bot_project/bot/handlers.py +++ b/telegram_bot_project/bot/handlers.py @@ -1,7 +1,7 @@ from aiogram.fsm.context import FSMContext from aiogram.types import Message -from bot.buttons import get_idea_conf_keyboard, menu_reply_keyboard, idea_reply_keyboard, task_reply_keyboard +from bot.buttons import get_idea_conf_keyboard, menu_reply_keyboard, idea_reply_keyboard, task_reply_keyboard, task_menu_keyboard from messages import MESSAGES from service.idea import IdeaService from service.task import TaskService @@ -185,8 +185,8 @@ async def process_task_deadline(message: Message, state: FSMContext): print(f"--[INFO] User with id: {user_id} provided deadline: {deadline_dt}") await TaskService.create_task(user_id, task, False, deadline_dt) - await message.answer(MESSAGES[language]['TASK_SAVED'], reply_markup=menu_reply_keyboard()) + await message.answer(MESSAGES[language]['TASK_SAVED'], reply_markup=task_menu_keyboard()) await state.clear() except ValueError: - await message.answer(MESSAGES[language]['TASK_DEADLINE_INVALID']) + await message.answer(MESSAGES[language]['TASK_DEADLINE_INVALID']) \ No newline at end of file diff --git a/telegram_bot_project/main.py b/telegram_bot_project/main.py index 537c829..7661dc2 100644 --- a/telegram_bot_project/main.py +++ b/telegram_bot_project/main.py @@ -53,6 +53,10 @@ async def update_idea(message: Message, state: FSMContext): async def task(message: Message, state: FSMContext): await task_command(message, state) +@dp.message(lambda m: m.text == BUTTON_ADD_TASK) +async def add_task(message: Message, state: FSMContext): + await task_command(message, state) + @dp.callback_query(F.data.in_({"lang_ua", "lang_en"})) async def callback_language(callback_query: CallbackQuery): await start_callback_language(callback_query) diff --git a/telegram_bot_project/messages.py b/telegram_bot_project/messages.py index ba3f524..0d1ada8 100644 --- a/telegram_bot_project/messages.py +++ b/telegram_bot_project/messages.py @@ -110,3 +110,9 @@ ALL_IDEAS: str = "📋 View All Ideas" BUTTON_YES: str = "Yes" BUTTON_NO: str = "No" +BUTTON_DELETE_TASK = "Delete Task" +BUTTON_EDIT_TASK = "Edit Task" +BUTTON_TOGGLE_STATUS = "Complete" +BUTTON_ALL_TASKS = "All tasks" + +