Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion telegram_bot_project/bot/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def task_menu_keyboard() -> ReplyKeyboardMarkup:
button_status = KeyboardButton(text=BUTTON_TOGGLE_STATUS)
button_delete = KeyboardButton(text=BUTTON_DELETE_TASK)
button_update = KeyboardButton(text=BUTTON_EDIT_TASK)
button_all_tasks = KeyboardButton(text=BUTTON_ALL_TASKS)

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])
task_menu_keyboard.keyboard.append([button_menu, button_all_tasks])

return task_menu_keyboard
31 changes: 30 additions & 1 deletion telegram_bot_project/bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bot.utills import format_date
from messages import MESSAGES
from service.idea import IdeaService
from service.task import TaskService
from service.user import UserService
from bot.buttons import get_language_keyboard, menu_reply_keyboard, idea_reply_keyboard, task_menu_keyboard
from states import DialogStates
Expand Down Expand Up @@ -141,4 +142,32 @@ async def task_menu_command(message: types.Message):
if not user_find:
await message.answer(MESSAGES['ENGLISH']['AUTHORIZATION_PROBLEM'])
else:
await message.answer(MESSAGES[language]['TASK_MENU'], reply_markup=task_menu_keyboard())
await message.answer(MESSAGES[language]['TASK_MENU'], reply_markup=task_menu_keyboard())

#Show all tasks handler
async def tasks_show_command(message: types.Message):
user_id = message.from_user.id
user_find = await UserService.get_user_by_id(user_id)
language = await UserService.get_user_language(user_id)

if not user_find:
await message.answer(MESSAGES['ENGLISH']['AUTHORIZATION_PROBLEM'])
return

tasks = await TaskService.get_user_tasks(user_id)
if not tasks:
await message.answer(MESSAGES[language]['NO_TASKS'], reply_markup=task_menu_keyboard())
return

response_text = f"📋 *{MESSAGES[language]['YOUR_TASKS']}*:\n\n"
for i, task in enumerate(tasks, 1):
status_icon = "✅" if task['status'] else "❌"
start_time = task['start_time'].strftime("%Y-%m-%d %H:%M") if task['start_time'] else "—"
response_text += (
f"*{i}. {task['task_name']}* {status_icon}\n"
f"🕒 *Start:* {start_time}\n"
f"📅 *Created:* {task['creation_date'].strftime('%Y-%m-%d')}\n\n"
)

await message.answer(response_text, parse_mode="Markdown", reply_markup=task_menu_keyboard())

22 changes: 12 additions & 10 deletions telegram_bot_project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
delete_idea_command,
update_idea_command,
task_command,
task_menu_command
task_menu_command,
tasks_show_command
)
from bot.handlers import (
process_idea_save,
Expand All @@ -30,14 +31,7 @@
process_task_deadline
)
from config import TOKEN
from messages import (
MENU_BUTTON,
BUTTON_IDEA,
ALL_IDEAS,
DEL_IDEA_BUTTON,
UPDATE_IDEA_BUTTON,
BUTTON_ADD_TASK
)
from messages import *
from states import DialogStates

storage: MemoryStorage = MemoryStorage()
Expand Down Expand Up @@ -87,10 +81,18 @@ async def task(message: Message, state: FSMContext):
async def add_task(message: Message, state: FSMContext):
await task_command(message, state)

@dp.message(Command("/taskmenu"))
@dp.message(Command("taskmenu"))
async def task_menu(message: Message):
await task_menu_command(message)

@dp.message(Command("tasks"))
async def show_tasks(message: Message):
await tasks_show_command(message)

@dp.message(lambda m: m.text == BUTTON_ALL_TASKS)
async def show_all_tasks(message: Message):
await tasks_show_command(message)

@dp.callback_query(F.data.in_({"lang_ua", "lang_en"}))
async def callback_language(callback_query: CallbackQuery):
await start_callback_language(callback_query)
Expand Down
4 changes: 4 additions & 0 deletions telegram_bot_project/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"TASK_DEADLINE_INVALID": "Недійсний термін. Будь ласка, спробуйте ще раз.",
"TASK_SAVED": "Задачу збережено.",
"TASK_MENU": "Меню задач",
"NO_TASKS": "Наразі у вас немає задач. Для добалення - /task",
"YOUR_TASKS": "Ваші задачі:",
"LANGUAGE_ASK": (
"🌐 **Оберіть мову інтерфейсу:**\n"
"Натисніть кнопку нижче, щоб продовжити:"
Expand Down Expand Up @@ -82,6 +84,8 @@
"TASK_DEADLINE_INVALID": "Invalid deadline. Please try again.",
"TASK_SAVED": "Task saved successfully.",
"TASK_MENU": "Task menu",
"NO_TASKS": "You are actually dont have any tasks yet. Be the first to add one! /task",
"YOUR_TASKS": "Your tasks:",
"LANGUAGE_ASK": (
"🌐 **Please choose your interface language:**\n"
"Tap a button below to continue:"
Expand Down