diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-09-14 17:52:14 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-09-14 17:52:14 +0200 |
| commit | ee17da20fb504838904f0f06857c76f4c17520e2 (patch) | |
| tree | 4726ccc9de45d9263d70526f90fe94f528602acb /geldschieberbot.py | |
| parent | 46e38d1ce0e4d25342b7d0adb3db0f3855d959eb (diff) | |
| download | geldschieberbot-ee17da20fb504838904f0f06857c76f4c17520e2.tar.gz geldschieberbot-ee17da20fb504838904f0f06857c76f4c17520e2.zip | |
support rewinding specific changes
Diffstat (limited to 'geldschieberbot.py')
| -rw-r--r-- | geldschieberbot.py | 17 |
1 files changed, 14 insertions, 3 deletions
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" |
