Subscriptions: «Оплачено?» → paid status → «repeat?»; edit and create everything

- ops: paying marks the current charge paid (paid_for, persisted) instead of jumping to
  the next date; repeat_sub moves to the next period or closes the subscription.
  Paid-and-undecided subscriptions leave reminders and show in agenda['paid'].
  update_sub can set paid; tasks reopen when their status goes back; delete for subs and
  routines (BroV only, /api/delete); /api/tasks?all=1 and /api/subs?all=1.
- Bot: «₽ Оплачено?» on reminders, then «🔁 Да, <date> / Нет, закрыть»; after paying by
  text it asks the same with buttons.
- BroV: «Оплачено?» everywhere; «Оплачено — повторить?» section under the notch;
  «Весь план»: forms to edit or create tasks (title, description, status, due, company),
  subscriptions (amount, currency, period, date, reminder, company, paid, active) and
  routines, delete with confirmation, «+» per list, done tasks on demand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maksarsanjeev
2026-10-10 03:57:18 +03:00
parent 011c709acf
commit 882632b7ce
9 changed files with 628 additions and 65 deletions
+43 -10
View File
@@ -125,16 +125,27 @@ async def cmd_stop(update: Update, ctx):
await update.message.reply_text(f"⏹ Остановил: {t['title']}" if t else "Таймер не шёл.")
def repeat_buttons(sub: dict) -> InlineKeyboardMarkup:
return InlineKeyboardMarkup([[
InlineKeyboardButton(f"🔁 Да, {ru_day(sub['next_if_repeat'])}", callback_data=f"rep:sub:{sub['id']}:1"),
InlineKeyboardButton("Нет, закрыть", callback_data=f"rep:sub:{sub['id']}:0")]])
async def think(update: Update, text: str):
msg = await update.effective_message.reply_text("🤔 думаю…")
paid: list = []
try:
answer = await asyncio.to_thread(brain.handle_text, ops, text, lock, CFG["claude"], CFG["model"])
answer = await asyncio.to_thread(brain.handle_text, ops, text, lock, CFG["claude"], CFG["model"], paid)
except OpsError as e:
answer = f"Не получилось: {e}"
except Exception as e: # Claude timeout, CLI missing…
log.exception("brain")
answer = f"Ошибка: {e.__class__.__name__}"
await msg.edit_text(answer[:4000])
for sid in paid: # paid by text: ask «repeat?» with buttons
s = locked(ops.sub, sid)
if s["paid"] and s["active"]:
await update.effective_message.reply_text(f"₽ {s['name']} оплачена. Повторить?", reply_markup=repeat_buttons(s))
@owner_only
@@ -168,7 +179,7 @@ async def on_voice(update: Update, ctx):
def reminder_buttons(it: dict) -> InlineKeyboardMarkup:
kind, ref = it["kind"], it["id"]
first = {"task": "✓ Сделано", "sub": "₽ Оплачено", "routine": "✓ Сделано"}[kind]
first = {"task": "✓ Сделано", "sub": "₽ Оплачено?", "routine": "✓ Сделано"}[kind]
return InlineKeyboardMarkup([[InlineKeyboardButton(first, callback_data=f"done:{kind}:{ref}"),
InlineKeyboardButton("⏰ Завтра", callback_data=f"snooze:{kind}:{ref}")]])
@@ -177,16 +188,22 @@ async def on_button(update: Update, ctx):
q = update.callback_query
if not q or q.message.chat.id != owner():
return
action, kind, ref = q.data.split(":")
ref = int(ref)
parts = q.data.split(":")
action, kind, ref = parts[0], parts[1], int(parts[2])
markup = None
try:
with lock:
if action == "done":
if action == "rep":
s = ops.repeat_sub(ref, parts[3] == "1")
note = (f"🔁 Следующее списание {ru_day(s['next_date'])}" if s["active"]
else "✓ Закрыта, больше не повторяется")
elif action == "done":
if kind == "task":
note = f"✓ Сделано: {ops.complete_task(ref)['title']}"
elif kind == "sub":
s = ops.pay_sub(ref)
note = f"₽ Оплачено: {s['name']}, следующее списание {ru_day(s['next_date'])}"
note = f"₽ Оплачено. Повторить {ru_day(s['next_if_repeat'])}?"
markup = repeat_buttons(s)
else:
r = ops.done_routine(ref)
note = f"✓ {r['title']}: следующий раз {ru_day(r['next_date'])}"
@@ -196,7 +213,7 @@ async def on_button(update: Update, ctx):
except OpsError as e:
note = f"Не получилось: {e}"
await q.answer()
await q.edit_message_text(q.message.text + "\n\n" + note)
await q.edit_message_text(q.message.text + "\n\n" + note, reply_markup=markup)
# MARK: - Reminders
@@ -248,13 +265,14 @@ async def api_agenda(request):
async def api_tasks(request):
check_auth(request)
return ok(locked(ops.task_tree))
return ok(locked(ops.task_tree, request.query.get("all") == "1"))
async def api_subs(request):
check_auth(request)
with lock:
return ok({"subs": ops.subs(), "monthly_cost": ops.monthly_cost(), "by_client": ops.monthly_by_client()})
return ok({"subs": ops.subs(active_only=request.query.get("all") != "1"), "monthly_cost": ops.monthly_cost(),
"by_client": ops.monthly_by_client()})
async def api_routines(request):
@@ -288,6 +306,21 @@ async def api_action(request):
return ok({"ok": not any(r.startswith("✗") for r in result), "result": result})
async def api_delete(request):
"""Delete by an explicit click in BroV (Claude never deletes)."""
check_auth(request)
body = await request.json()
kind, ref = str(body.get("kind")), int(body.get("id"))
fn = {"task": ops.delete_task, "sub": ops.delete_sub, "routine": ops.delete_routine}.get(kind)
if not fn:
raise web.HTTPBadRequest(text="kind")
try:
locked(fn, ref)
except OpsError as e:
return ok({"ok": False, "result": [str(e)]})
return ok({"ok": True, "result": ["🗑 удалено"]})
async def api_health(request):
return ok({"ok": True})
@@ -297,7 +330,7 @@ def make_api() -> web.Application:
app.add_routes([web.get("/api/health", api_health), web.get("/api/agenda", api_agenda),
web.get("/api/tasks", api_tasks), web.get("/api/subs", api_subs),
web.get("/api/routines", api_routines), web.post("/api/say", api_say),
web.post("/api/action", api_action)])
web.post("/api/action", api_action), web.post("/api/delete", api_delete)])
return app