QOL and private @idose

This commit is contained in:
mogad0n 2021-01-03 05:08:12 +05:30
parent f559b1faa5
commit 587a90fe19
1 changed files with 41 additions and 25 deletions

View File

@ -53,7 +53,7 @@ filename = conf.supybot.directories.data.dirize("Tripsit.db")
url_drug = "http://tripbot.tripsit.me/api/tripsit/getDrug" url_drug = "http://tripbot.tripsit.me/api/tripsit/getDrug"
url_combo = "http://tripbot.tripsit.me/api/tripsit/getInteraction" url_combo = "http://tripbot.tripsit.me/api/tripsit/getInteraction"
insufflated = ["Insufflated", "Insufflated-IR", "Insufflated-XR"] insufflated = ["Insufflation", "Insufflation-IR", "Insufflation-XR"]
METHODS = { METHODS = {
"iv": ["IV"], "iv": ["IV"],
@ -106,6 +106,7 @@ class Tripsit(callbacks.Plugin):
@wrap(['something', optional('something')]) @wrap(['something', optional('something')])
def drug(self, irc, msg, args, name, category): def drug(self, irc, msg, args, name, category):
"""<drug> [<category>] """<drug> [<category>]
fetches data on drug from tripsit wiki fetches data on drug from tripsit wiki
""" """
category_list = [] category_list = []
@ -115,7 +116,7 @@ class Tripsit(callbacks.Plugin):
properties = r["data"][0]["properties"] properties = r["data"][0]["properties"]
for key in properties: for key in properties:
category_list.append(key) category_list.append(key)
if category == None: if category is None:
re = drug + " Available categories are: " + ", ".join(category_list) re = drug + " Available categories are: " + ", ".join(category_list)
irc.reply(re) irc.reply(re)
else: else:
@ -129,6 +130,7 @@ class Tripsit(callbacks.Plugin):
def combo(self, irc, msg, args, drugA, drugB): def combo(self, irc, msg, args, drugA, drugB):
"""<drugA> <drugB> """<drugA> <drugB>
fetches known interactions between the substances provided. fetches known interactions between the substances provided.
""" """
r = requests.get(url_combo, params={f"drugA": drugA, f"drugB": drugB}).json() r = requests.get(url_combo, params={f"drugA": drugA, f"drugB": drugB}).json()
@ -151,24 +153,29 @@ class Tripsit(callbacks.Plugin):
def set(self, irc, msg, args, timezone): def set(self, irc, msg, args, timezone):
"""<timezone> """<timezone>
Sets location for your current ident@host to <timezone>
Sets location for your current nick to <timezone>
for eg. America/Chicago for eg. America/Chicago
""" """
nick = msg.nick nick = msg.nick
if nick in self.db: try:
self.db[nick]['timezone'] = timezone timezone = pytz.timezone(timezone)
else: if nick in self.db:
self.db[nick] = {'timezone': timezone } self.db[nick]['timezone'] = timezone
irc.replySuccess() else:
self.db[nick] = {'timezone': timezone }
irc.replySuccess()
except pytz.UnknownTimeZoneError:
irc.error(_('Unknown timezone'), Raise=True)
set = wrap(set, ["something"]) set = wrap(set, ["something"])
@wrap(["something", "something", optional("something"), optional("something")]) @wrap(["private", "something", "something", optional("something"), getopts({'ago': 'something'})])
def idose(self, irc, msg, args, dose, name, method, ago): def idose(self, irc, msg, args, dose, name, method, opts):
"""<amount> <drug> [<method>] [<ago>] """<amount> <drug> [<method>] [--ago <HHMM>]
<ago> is in the format HHMM logs a dose for you, can only be used in private.
logs a dose for you, use 'lastdose' command to retrieve
""" """
opts = dict(opts)
r = requests.get(url_drug, params={"name": name}).json() r = requests.get(url_drug, params={"name": name}).json()
found_method = False found_method = False
onset = None onset = None
@ -205,10 +212,11 @@ class Tripsit(callbacks.Plugin):
nick = msg.nick nick = msg.nick
if nick in self.db: if nick in self.db:
timezone = self.db[nick].get('timezone', 'UTC') timezone = self.db[nick].get('timezone', 'UTC')
tz = pytz.timezone(timezone) tz = pytz.timezone(str(timezone))
time = datetime.datetime.now(tz=tz) time = datetime.datetime.now(tz=tz)
dose_td = 0 dose_td = 0
if ago is not None and len(ago) == 4: if 'ago' in opts and len(opts['ago']) == 4:
ago = opts['ago']
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4])) dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
dose_td_s = dose_td.total_seconds() dose_td_s = dose_td.total_seconds()
time = time - dose_td time = time - dose_td
@ -221,10 +229,10 @@ class Tripsit(callbacks.Plugin):
self.db[nick]['doses'] = doses self.db[nick]['doses'] = doses
else: else:
timezone = 'UTC' timezone = 'UTC'
tz = pytz.timezone(timezone) time = datetime.datetime.utcnow()
time = datetime.datetime.now(tz=tz)
dose_td = 0 dose_td = 0
if ago is not None and len(ago) == 4: if 'ago' in opts and len(opts['ago']) == 4:
ago = opts['ago']
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4])) dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
dose_td_s = dose_td.total_seconds() dose_td_s = dose_td.total_seconds()
time = time - dose_td time = time - dose_td
@ -233,11 +241,11 @@ class Tripsit(callbacks.Plugin):
self.db[nick] = {'timezone': timezone, 'doses': doses} self.db[nick] = {'timezone': timezone, 'doses': doses}
if dose_td == 0: if dose_td == 0:
re = utils.str.format("You dosed %s of %s at %t, %s", dose, drug_and_method, time.timetuple(), timezone) re = utils.str.format("You dosed %s of %s at %s, %s", dose, drug_and_method, str(time), timezone)
if onset is not None: if onset is not None:
re += utils.str.format(". You should start feeling effects %s from now", onset) re += utils.str.format(". You should start feeling effects %s from now", onset)
else: else:
re = utils.str.format("You dosed %s of %s at %t, %s ; %T ago", dose, drug_and_method, time.timetuple(), timezone, dose_td.total_seconds()) re = utils.str.format("You dosed %s of %s at %s, %s ; %T ago", dose, drug_and_method, str(time), timezone, dose_td.total_seconds())
if onset is not None: if onset is not None:
re += utils.str.format(". You should have/will start feeling effects %s from/after dosing", onset) re += utils.str.format(". You should have/will start feeling effects %s from/after dosing", onset)
irc.reply(re) irc.reply(re)
@ -251,22 +259,30 @@ class Tripsit(callbacks.Plugin):
nick = msg.nick nick = msg.nick
if nick in self.db: if nick in self.db:
if history: if history:
hist = -int(history) try:
lastdose = self.db[nick]['doses'][-int(history)] lastdose = self.db[nick]['doses'][-int(history)]
except IndexError:
irc.error("You haven't logged that many doses")
else: else:
lastdose = self.db[nick]['doses'][-1] lastdose = self.db[nick]['doses'][-1]
dose = lastdose['dose'] dose = lastdose['dose']
drug = lastdose['drug'] drug = lastdose['drug']
method = lastdose['method']
dose_time = lastdose['time'] dose_time = lastdose['time']
timezone = self.db[nick]['timezone'] timezone = self.db[nick]['timezone']
tz = pytz.timezone(timezone) tz = pytz.timezone(str(timezone))
time = datetime.datetime.now(tz=tz) time = datetime.datetime.now(tz=tz)
since_dose = time - dose_time since_dose = time - dose_time
since_dose_seconds = since_dose.total_seconds() since_dose_seconds = since_dose.total_seconds()
if history: if history:
re = utils.str.format("Your %i'th last dose was %s of %s at %t %s, %T ago", history, dose, drug, dose_time.timetuple(), timezone, since_dose_seconds) if history == '2':
re = utils.str.format("Your %i'nd last dose was %s of %s via %s at %s %s, %T ago", history, dose, drug, method, str(dose_time), timezone, since_dose_seconds)
if history == '3':
re = utils.str.format("Your %i'rd last dose was %s of %s via %s at %s %s, %T ago", history, dose, drug, method, str(dose_time), timezone, since_dose_seconds)
else:
re = utils.str.format("Your %i'th last dose was %s of %s via %s at %s %s, %T ago", history, dose, drug, method, str(dose_time), timezone, since_dose_seconds)
else: else:
re = utils.str.format("You last dosed %s of %s at %t %s, %T ago", dose, drug, dose_time.timetuple(), timezone, since_dose_seconds) re = utils.str.format("You last dosed %s of %s via %s at %s %s, %T ago", dose, drug, method, str(dose_time), timezone, since_dose_seconds)
irc.reply(re) irc.reply(re)
else: else:
irc.error(f'No doses saved for {nick}') irc.error(f'No doses saved for {nick}')