bot improvements

This commit is contained in:
2026-02-16 04:49:31 -06:00
parent f8903f74cf
commit 12bbc5c0b4
3 changed files with 61 additions and 5 deletions

View File

@@ -44,9 +44,28 @@ async def handle_medication(message, session, parsed):
elif action == "take":
med_id = parsed.get("medication_id")
if not med_id:
name = parsed.get("name")
if not med_id and name:
# Look up medication by name
resp, status = api_request("get", "/api/medications", token)
if status == 200:
meds = resp if isinstance(resp, list) else []
# Find medication by name (case-insensitive partial match)
matching = [m for m in meds if name.lower() in m['name'].lower() or m['name'].lower() in name.lower()]
if matching:
med_id = matching[0]['id']
name = matching[0]['name']
else:
await message.channel.send(f"I couldn't find a medication called '{name}'. Use 'list' to see your medications.")
return
else:
await message.channel.send("Error looking up medication. Please try again.")
return
elif not med_id:
await message.channel.send("Which medication did you take?")
return
resp, status = api_request("post", f"/api/medications/{med_id}/take", token, {})
if status == 201:
await message.channel.send("Logged it! Great job staying on track.")
@@ -55,10 +74,29 @@ async def handle_medication(message, session, parsed):
elif action == "skip":
med_id = parsed.get("medication_id")
name = parsed.get("name")
reason = parsed.get("reason", "Skipped by user")
if not med_id:
if not med_id and name:
# Look up medication by name
resp, status = api_request("get", "/api/medications", token)
if status == 200:
meds = resp if isinstance(resp, list) else []
# Find medication by name (case-insensitive partial match)
matching = [m for m in meds if name.lower() in m['name'].lower() or m['name'].lower() in name.lower()]
if matching:
med_id = matching[0]['id']
name = matching[0]['name']
else:
await message.channel.send(f"I couldn't find a medication called '{name}'. Use 'list' to see your medications.")
return
else:
await message.channel.send("Error looking up medication. Please try again.")
return
elif not med_id:
await message.channel.send("Which medication are you skipping?")
return
resp, status = api_request("post", f"/api/medications/{med_id}/skip", token, {"reason": reason})
if status == 201:
await message.channel.send("OK, noted.")

View File

@@ -40,7 +40,25 @@ async def handle_routine(message, session, parsed):
elif action == "start":
routine_id = parsed.get("routine_id")
if not routine_id:
name = parsed.get("name")
if not routine_id and name:
# Look up routine by name
resp, status = api_request("get", "/api/routines", token)
if status == 200:
routines = resp if isinstance(resp, list) else []
# Find routine by name (case-insensitive partial match)
matching = [r for r in routines if name.lower() in r['name'].lower() or r['name'].lower() in name.lower()]
if matching:
routine_id = matching[0]['id']
name = matching[0]['name']
else:
await message.channel.send(f"I couldn't find a routine called '{name}'. Use 'list' to see your routines.")
return
else:
await message.channel.send("Error looking up routine. Please try again.")
return
elif not routine_id:
await message.channel.send("Which routine would you like to start?")
return