summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormogad0n2020-09-17 11:25:24 +0530
committermogad0n2020-09-17 11:25:24 +0530
commitd4d6d8417ea851171fbfa795de0b325e93814d67 (patch)
treee5764024bedfd23e3c615a9f5ff544fb247b9ff4
parented596671db35df4affe9e39ac955b1c44c7ebc29 (diff)
downloadtripsit-d4d6d8417ea851171fbfa795de0b325e93814d67.tar.gz
tripsit-d4d6d8417ea851171fbfa795de0b325e93814d67.tar.bz2
tripsit-d4d6d8417ea851171fbfa795de0b325e93814d67.zip
Initial implementation of historical dose logging
-rw-r--r--plugin.py48
1 files changed, 36 insertions, 12 deletions
diff --git a/plugin.py b/plugin.py
index 8cb7358..0e52fb7 100644
--- a/plugin.py
+++ b/plugin.py
@@ -104,6 +104,7 @@ class Tripsit(callbacks.Plugin):
@wrap(['something', optional('something')])
def drug(self, irc, msg, args, name, category):
"""<drug> [<category>]
+
fetches data on drug from tripsit wiki
"""
category_list = []
@@ -127,6 +128,7 @@ class Tripsit(callbacks.Plugin):
def combo(self, irc, msg, args, drugA, drugB):
"""<drugA> <drugB>
+
fetches known interactions between the substances provided.
"""
r = requests.get(url_combo, params={f"drugA": drugA, f"drugB": drugB}).json()
@@ -147,9 +149,11 @@ class Tripsit(callbacks.Plugin):
combo = wrap(combo, [("something"), ("something")])
- def idose(self, irc, msg, args, dose, name, method):
- """<amountt> <drug> <method>
- logs a dose in the database for retrieval
+ def idose(self, irc, msg, args, dose, name, ago, method):
+ """<amount> <drug> [<ago>] [<method>]
+
+ <ago> is in the format HHMM
+ logs a dose for you, use 'lastdose' command to retrieve
"""
r = requests.get(url_drug, params={"name": name}).json()
found_method = False
@@ -176,29 +180,49 @@ class Tripsit(callbacks.Plugin):
if onset and "_unit" in drug["formatted_onset"]:
onset = "%s %s" % (
onset, drug["formatted_onset"]["_unit"])
- drug_and_method = drug_name
+ drug_and_method = drug_name
+ else:
+ drug_name = name
+ drug_and_method = name
+
if method:
if not found_method:
method = method.title()
drug_and_method = "%s via %s" % (drug_and_method, method)
+ hours = int(ago[0:2])
+ minutes = int(ago[2:4])
time = datetime.utcnow()
- self.db[msg.nick] = { 'time': str(time), 'dose': dose, 'drug': drug_name, 'method': method }
- re = f"{msg.nick} dosed {dose} of {drug_and_method} at {str(time)}"
-
- if not onset == None:
- re += f". You should start feeling effects {onset} from now"
+ if not ago:
+ self.db[msg.nick] = {'type': 'idose' ,'time': str(time), 'dose': dose, 'drug': drug_name, 'method': method }
+ re = f" You dosed {dose} of {drug_and_method} at {str(time)}"
+ if not onset == None:
+ re += f". You should start feeling effects {onset} from now"
+ else:
+ dose_td = datetime.timedelta(hours=hours, minutes=minutes)
+ time_dosed = time - dose_td
+ self.db[msg.nick] = {'type': 'hdose', 'time': str(time), 'time_dosed': str(time_dosed) 'dose': dose, 'drug': drug_name, 'method': method }
+ re = f" You dosed {dose} of {drug_and_method} at {str(time_dosed)}"
+ if not onset == None:
+ re += f". You should start feeling effects {onset} from now"
irc.reply(re)
- idose = wrap(idose, [("something"), ("something"), ("something")])
+
+ idose = wrap(idose, [("something"), ("something"), optional("something"), optional("something")])
+
def lastdose(self, irc, msg, args):
- """ retrieves saved dose
+ """This command takes no arguments
+
+ retrieves your last logged dose
"""
if msg.nick in self.db:
lastdose = self.db[msg.nick]
time = datetime.utcnow()
- dose_time = dateutil.parser.isoparse(lastdose['time'])
+ if lastdose['type'] == 'idose'
+ dose_time = dateutil.parser.isoparse(lastdose['time'])
+ elif lastdose['type'] == 'hdose':
+ dose_time = dateutil.parser.isoparse(lastdose['time_dosed'])
since_dose = time - dose_time
since_dose_seconds = since_dose.total_seconds()
since_dose_formatted = utils.str.format('%T', since_dose_seconds)