ops bot: task lists go out one card per task with Сделано / Перенести buttons
This commit is contained in:
+32
-19
@@ -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"]:
|
||||
|
||||
Reference in New Issue
Block a user