summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratyush Desai2021-06-30 08:00:41 +0530
committerPratyush Desai2021-06-30 08:00:41 +0530
commit0dc06a87a550fd52cf0a6179962f7d7c89f0ab02 (patch)
treec2a71a6613a7da6c95aabb3cd974563dac0776a9
parent15bfb9b34e93f8a0ad506ca823a71f76f73eaef6 (diff)
downloadtripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.tar.gz
tripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.tar.bz2
tripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.zip
add @undose command
-rw-r--r--plugin.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/plugin.py b/plugin.py
index 93c502a..413d395 100644
--- a/plugin.py
+++ b/plugin.py
@@ -28,6 +28,7 @@
###
+from humanize import ordinal
from supybot import utils, plugins, ircutils, callbacks, world, conf, log
from supybot.commands import *
@@ -172,11 +173,13 @@ class Tripsit(callbacks.Plugin):
irc.error(_('Unknown timezone'), Raise=True)
set = wrap(set, ["something"])
- @wrap(["private", getopts({'ago': 'something'}), "something", "something", optional("something")])
+ @wrap([getopts({'ago': 'something'}), "something", "something", optional("something")])
def idose(self, irc, msg, args, opts, dose, name, method):
"""[--ago <HHMM>] <amount> <drug> [<method/ROA>]
- logs a dose for you, can only be used in private.
+ logs a dose for your <nick>, eg. @idose --ago 0100 20mg mph oral
+ would log that dose as if it was taken an hour ago
+ [--ago] and [ROA] fields are optional
"""
opts = dict(opts)
r = requests.get(url_drug, params={"name": name}).json()
@@ -254,6 +257,30 @@ class Tripsit(callbacks.Plugin):
re += utils.str.format(". You should have/will start feeling effects %s from/after dosing", onset)
irc.reply(re)
+ @wrap([optional('postiveInt')])
+ def undose(self, irc, msg, args, entry):
+ """<n>
+
+ removes your last dose entry, if <n> is provided then
+ deletes the nth last dose
+ """
+ nick = msg.nick
+ if nick in self.db:
+ nick_dose_log = self.db[nick]['doses']
+ if entry:
+ try:
+ del nick_dose_log[-int(entry)]
+ entry = num2words(entry, to='ordinal')
+ irc.replySuccess(f"Deleted the {entry} last dose logged for {nick} ")
+ except IndexError:
+ irc.error("The dose entry doesn't exist")
+ return
+ else:
+ del nick_dose_log[-1]
+ irc.replySuccess(f"Deleted the last dose logged for {nick} ")
+ else:
+ irc.error(f'No doses saved for {nick}')
+
@wrap([optional('positiveInt')])
def lastdose(self, irc, msg, args, history):
"""<n>