From a4f5a89026d97c8f250150cd4f7e4848af069bf7 Mon Sep 17 00:00:00 2001 From: maksarsanjeev Date: Mon, 9 Nov 2026 00:47:21 +0300 Subject: [PATCH] =?UTF-8?q?ops=20bot:=20task=20lists=20go=20out=20one=20ca?= =?UTF-8?q?rd=20per=20task=20with=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=20/=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20buttons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/brovops/app.py | 51 +++++++++++++++++++++++++++++----------------- ops/brovops/fmt.py | 10 +++++++++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/ops/brovops/app.py b/ops/brovops/app.py index 4c1a590..83eece7 100644 --- a/ops/brovops/app.py +++ b/ops/brovops/app.py @@ -89,27 +89,37 @@ async def send_long(update: Update, text: str, **kw): await update.effective_message.reply_text(chunk, parse_mode=ParseMode.HTML, **(kw if last else {})) -def task_buttons(tasks: list, limit: int = 12) -> InlineKeyboardMarkup | None: - """One row per open task: ✓ completes, ⏰ snoozes a day — same callbacks as reminders.""" - rows = [] - for t in tasks[:limit]: - title = t["title"] if len(t["title"]) <= 20 else t["title"][:19] + "…" - rows.append([InlineKeyboardButton(f"✓ {title}", callback_data=f"done:task:{t['id']}"), - InlineKeyboardButton("⏰", callback_data=f"snooze:task:{t['id']}")]) - return InlineKeyboardMarkup(rows) if rows else None +def one_task_buttons(task_id: int) -> InlineKeyboardMarkup: + """Buttons under a single task card — same callbacks as reminders.""" + return InlineKeyboardMarkup([[ + InlineKeyboardButton("✓ Сделано", callback_data=f"done:task:{task_id}"), + InlineKeyboardButton("⏰ Перенести", callback_data=f"snooze:task:{task_id}")]]) def flat_tasks(tree: list) -> list: + """[(task, depth)] in display order.""" out = [] - def walk(nodes): + def walk(nodes, depth): for n in nodes: - out.append(n) - walk(n["children"]) - walk(tree) + out.append((n, depth)) + walk(n["children"], depth + 1) + walk(tree, 0) return out +async def send_task_cards(update: Update, tree: list, limit: int = 12): + """Every open task as its own message: task text, then Сделано / Перенести.""" + tasks = flat_tasks(tree) + today = ops.today() + for t, depth in tasks[:limit]: + await update.effective_message.reply_text(fmt.task_line(t, depth, today), + parse_mode=ParseMode.HTML, + reply_markup=one_task_buttons(t["id"])) + if len(tasks) > limit: + await update.effective_message.reply_text(f"…и ещё {len(tasks) - limit}. Повтори /tasks.") + + @owner_only async def cmd_start(update: Update, ctx): await update.message.reply_text( @@ -123,16 +133,20 @@ async def cmd_start(update: Update, ctx): async def cmd_today(update: Update, ctx): with lock: agenda, tree = ops.agenda(), ops.task_tree() - await send_long(update, fmt.agenda(agenda), reply_markup=task_buttons(flat_tasks(tree))) + await send_long(update, fmt.agenda(agenda)) + await send_task_cards(update, tree) @owner_only async def cmd_tasks(update: Update, ctx): with lock: tree = ops.task_tree() - lines = fmt.tree(tree) - await send_long(update, "\n".join(lines) if lines else "Открытых задач нет 👌", - reply_markup=task_buttons(flat_tasks(tree))) + if not tree: + await update.effective_message.reply_text("Открытых задач нет 👌") + return + await update.effective_message.reply_text( + f"Открытые задачи ({len(flat_tasks(tree))}) — по одной, жми Сделано или Перенести:") + await send_task_cards(update, tree) @owner_only @@ -176,10 +190,9 @@ async def think(update: Update, text: str): except Exception as e: # Kimi timeout, CLI missing… log.exception("brain") answer = f"Ошибка: {e.__class__.__name__}" - markup = None + await msg.edit_text(answer[:4000]) if "✓" not in answer and any(h in text.lower() for h in LIST_HINTS): - markup = task_buttons(flat_tasks(locked(ops.task_tree))) - await msg.edit_text(answer[:4000], reply_markup=markup) + await send_task_cards(update, locked(ops.task_tree)) for sid in paid: # paid by text: ask «repeat?» with buttons s = locked(ops.sub, sid) if s["paid"] and s["active"]: diff --git a/ops/brovops/fmt.py b/ops/brovops/fmt.py index 3fa3095..b5eaef1 100644 --- a/ops/brovops/fmt.py +++ b/ops/brovops/fmt.py @@ -55,6 +55,16 @@ def tree(nodes: list, depth: int = 0) -> list[str]: return out +def task_line(t: dict, depth: int, today: date) -> str: + """One task as a standalone card text (sent as its own message with buttons).""" + mark = "⏱" if t["running"] else ("▶️" if t["status"] == "doing" else "📌") + due = f"\nСрок: {human_day(t['due'], today)}" if t["due"] else "" + mins = f"\nУчтено: {t['minutes']} мин" if t["minutes"] else "" + client = f" [{client_name(t['client'])}]" if t["client"] else "" + indent = "└ " * depth + return f"{indent}{mark} {escape(t['title'])}{client}{due}{mins}" + + def subs(rows: list, by_client: dict, today: date) -> str: """Grouped by company, each with its monthly total.""" if not rows: