From ee17da20fb504838904f0f06857c76f4c17520e2 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 14 Sep 2020 17:52:14 +0200 Subject: support rewinding specific changes --- geldschieberbot.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'geldschieberbot.py') diff --git a/geldschieberbot.py b/geldschieberbot.py index d74cca5..7ae6454 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -190,7 +190,7 @@ cars pay car-name amount - pay a bill for the specified car tanken amount [person] [car] [info] - calculate fuel costs, service charge and add them to the person's and car's balance respectively -fuck - rewind last change +fuck [change] - rewind last or specific change list-changes [n] [first] - list the last n changes starting at first weekly name cmd - repeat cmd each week @@ -595,11 +595,22 @@ def fuck(sender, args, msg): else: name = num2name[sender] - if len(changes[name]) == 0: + nchanges = len(changes[name]) + if nchanges == 0: return "Nothing to rewind", None + change_to_rewind = -1 + if len(args) >= 2: + try: + change_to_rewind = int(args[1]) - 1 + except ValueError: + return None, "change to rewind must be a number" + + if change_to_rewind > nchanges: + return None, "change to rewind is bigger than there are changes" + # pop last item - last_changes = changes[name].pop() + last_changes = changes[name].pop(change_to_rewind) args, last_changes = last_changes[0], last_changes[1:] output = name + ": sorry I fucked up!\nRewinding:\n" -- cgit v1.2.3