diff options
| author | Pratyush Desai | 2021-06-30 08:00:41 +0530 |
|---|---|---|
| committer | Pratyush Desai | 2021-06-30 08:00:41 +0530 |
| commit | 0dc06a87a550fd52cf0a6179962f7d7c89f0ab02 (patch) | |
| tree | c2a71a6613a7da6c95aabb3cd974563dac0776a9 | |
| parent | 15bfb9b34e93f8a0ad506ca823a71f76f73eaef6 (diff) | |
| download | tripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.tar.gz tripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.tar.bz2 tripsit-0dc06a87a550fd52cf0a6179962f7d7c89f0ab02.zip | |
add @undose command
| -rw-r--r-- | plugin.py | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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> |
