feat(bot): add delete action for medications and routines
- Added delete action to medications handler with confirmation flow - Added delete action to routines handler with confirmation flow - Updated AI config with delete examples for both meds and routines - Added 'delete', 'remove', 'get rid of' to action recognition
This commit is contained in:
@@ -458,8 +458,49 @@ async def handle_routine(message, session, parsed):
|
||||
else:
|
||||
await message.channel.send(f"Error: {resp.get('error', 'Failed to add tag')}")
|
||||
|
||||
elif action == "delete":
|
||||
routine_id = parsed.get("routine_id")
|
||||
name = parsed.get("name")
|
||||
needs_confirmation = parsed.get("needs_confirmation", True)
|
||||
|
||||
routine_id, name, found = await _find_routine_by_name(message, token, routine_id, name)
|
||||
if not found:
|
||||
return
|
||||
|
||||
if not routine_id:
|
||||
await message.channel.send("Which routine should I delete?")
|
||||
return
|
||||
|
||||
# Handle confirmation
|
||||
if needs_confirmation:
|
||||
if "pending_confirmations" not in session:
|
||||
session["pending_confirmations"] = {}
|
||||
|
||||
confirmation_id = f"routine_delete_{name}"
|
||||
session["pending_confirmations"][confirmation_id] = {
|
||||
"action": "delete",
|
||||
"interaction_type": "routine",
|
||||
"routine_id": routine_id,
|
||||
"name": name,
|
||||
"needs_confirmation": False # Skip confirmation next time
|
||||
}
|
||||
|
||||
await message.channel.send(
|
||||
f"⚠️ Are you sure you want to delete **{name}**?\n\n"
|
||||
f"This will also delete all steps and history for this routine.\n\n"
|
||||
f"Reply **yes** to confirm deletion, or **no** to cancel."
|
||||
)
|
||||
return
|
||||
|
||||
# Actually delete
|
||||
resp, status = api_request("delete", f"/api/routines/{routine_id}", token)
|
||||
if status == 200:
|
||||
await message.channel.send(f"🗑️ Deleted **{name}** and all its data.")
|
||||
else:
|
||||
await message.channel.send(f"Error: {resp.get('error', 'Failed to delete routine')}")
|
||||
|
||||
else:
|
||||
await message.channel.send(f"Unknown action: {action}. Try: list, create, start, complete, skip, cancel, history, pause, resume, abort, note, stats, streak, templates, clone, or tag.")
|
||||
await message.channel.send(f"Unknown action: {action}. Try: list, create, delete, start, complete, skip, cancel, history, pause, resume, abort, note, stats, streak, templates, clone, or tag.")
|
||||
|
||||
|
||||
async def _create_routine(message, token, name, description):
|
||||
|
||||
Reference in New Issue
Block a user