fixed spamming i hope

This commit is contained in:
2026-02-17 18:11:44 -06:00
parent 80ebecf0b1
commit 8ac7a5129a
3 changed files with 49 additions and 11 deletions

View File

@@ -423,6 +423,44 @@ async def handle_medication(message, session, parsed):
else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to log')}")
elif action == "take_all":
# Mark all currently pending (untaken, non-skipped, non-PRN) doses as taken
timezone_offset = await _get_user_timezone(message, session, token)
resp, status = api_request("get", "/api/medications/today", token)
if status != 200:
await message.channel.send("Error fetching today's medications.")
return
meds_today = resp if isinstance(resp, list) else []
marked = []
skipped_already = []
for item in meds_today:
med = item.get("medication", {})
if item.get("is_prn"):
continue
times = item.get("scheduled_times", [])
taken = set(item.get("taken_times", []))
skipped = set(item.get("skipped_times", []))
med_id_local = med.get("id")
med_name = med.get("name", "Unknown")
pending_times = [t for t in times if t not in taken and t not in skipped]
if not pending_times:
skipped_already.append(med_name)
continue
for t in pending_times:
api_request("post", f"/api/medications/{med_id_local}/take", token, {"scheduled_time": t})
marked.append(f"**{med_name}** ({', '.join(pending_times)})")
if not marked:
await message.channel.send("✅ All medications are already logged for today!")
else:
lines = "\n".join(f"{m}" for m in marked)
await message.channel.send(f"Logged as taken:\n{lines}")
elif action == "skip":
med_id = parsed.get("medication_id")
name = parsed.get("name")
@@ -645,7 +683,7 @@ async def handle_medication(message, session, parsed):
else:
await message.channel.send(
f"Unknown action: {action}. Try: list, add, delete, take, skip, today, refills, snooze, or adherence."
f"Unknown action: {action}. Try: list, add, delete, take, take_all, skip, today, refills, snooze, or adherence."
)