From 64916d6388d7a80c5c6f822cf0385f2d7134a8cb Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Wed, 30 Oct 2024 03:12:14 +0530 Subject: [PATCH] Implement dose lookup Adds ability to lookup the last logged dose for a drug. Signed-off-by: Pratyush Desai --- plugin.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugin.py b/plugin.py index 6b2ba57..0d6f111 100644 --- a/plugin.py +++ b/plugin.py @@ -378,7 +378,30 @@ class Tripsit(callbacks.Plugin): else: irc.error(f'No doses saved for {nick}') + @wrap(["something"]) + def grepdose(self, irc, msg, args, drug): + """ + pulls most recent dose for drug + """ + nick = msg.nick + if nick in self.db: + doselogs = self.db[nick]['doses'] + for doselog in reversed(doselogs): + if doselog['drug'] == drug: + timezone = self.db[nick]['timezone'] + tz = pytz.timezone(str(timezone)) + time = datetime.datetime.now(tz=tz) + since_dose = time - doselog['time'] + since_dose_seconds = since_dose.total_seconds() + re = utils.str.format("You last dosed %s of %s via %s at %s %s, %T ago", doselog["dose"], doselog["drug"], doselog["method"], doselog["time"].strftime("%c"), timezone, since_dose_seconds) + irc.reply(re) + found = True + break + if not found: + irc.error(f"No doses saved for {drug}") + else: + irc.error(f"No doses saved for {nick}") @wrap(["something"]) def amountdosed(self, irc, msg, args, drug):