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:
2026-02-16 06:04:19 -06:00
parent 7d7d6fb3a0
commit 20f995119c
3 changed files with 86 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -225,8 +225,49 @@ async def handle_medication(message, session, parsed):
else: else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to fetch adherence')}") await message.channel.send(f"Error: {resp.get('error', 'Failed to fetch adherence')}")
elif action == "delete":
med_id = parsed.get("medication_id")
name = parsed.get("name")
needs_confirmation = parsed.get("needs_confirmation", True)
med_id, name, found = await _find_medication_by_name(message, token, med_id, name)
if not found:
return
if not med_id:
await message.channel.send("Which medication should I delete?")
return
# Handle confirmation
if needs_confirmation:
if "pending_confirmations" not in session:
session["pending_confirmations"] = {}
confirmation_id = f"med_delete_{name}"
session["pending_confirmations"][confirmation_id] = {
"action": "delete",
"interaction_type": "medication",
"medication_id": med_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 logs for this medication.\n\n"
f"Reply **yes** to confirm deletion, or **no** to cancel."
)
return
# Actually delete
resp, status = api_request("delete", f"/api/medications/{med_id}", token)
if status == 200:
await message.channel.send(f"🗑️ Deleted **{name}** and all its logs.")
else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to delete medication')}")
else: else:
await message.channel.send(f"Unknown action: {action}. Try: list, add, take, skip, today, refills, snooze, or adherence.") await message.channel.send(f"Unknown action: {action}. Try: list, add, delete, take, skip, today, refills, snooze, or adherence.")
async def _add_medication(message, token, name, dosage, unit, frequency, times, days_of_week, interval_days): async def _add_medication(message, token, name, dosage, unit, frequency, times, days_of_week, interval_days):

View File

@@ -458,8 +458,49 @@ async def handle_routine(message, session, parsed):
else: else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to add tag')}") 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: 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): async def _create_routine(message, token, name, description):