From 0dc06a87a550fd52cf0a6179962f7d7c89f0ab02 Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Wed, 30 Jun 2021 08:00:41 +0530 Subject: [PATCH] add @undose command --- plugin.py | 31 +++++++++++++++++++++++++++++-- 1 file 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 ] [] - logs a dose for you, can only be used in private. + logs a dose for your , 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): + """ + + removes your last dose entry, if 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): """