diff options
Diffstat (limited to 'geldschieberbot.py')
| -rw-r--r-- | geldschieberbot.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index 2b2d564..b8d697f 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -23,10 +23,13 @@ send_cmd = "signal-cli -u irgendwer send -g irgendwem" def record(sender, recipient, donor, amount): """Apply change to the balance and save it""" - balance[donor][recipient] -= amount - balance[recipient][donor] += amount + balance[donor][recipient] += amount + balance[recipient][donor] -= amount - last_change[sender] = [recipient, donor, amount] + if not sender in last_change: + last_change[sender] = [] + + last_change[sender].append([recipient, donor, amount]) def to_cent(euro): euro = euro.split('.') @@ -326,11 +329,13 @@ def handle_input(inp): send("Nothing to rewind") continue - changes = last_change[sender_number] + # copy list + changes = [x for x in last_change[sender_number]] + last_change[sender_number] = [] msg = num2name[sender_number] + ": sorry I fucked up!\n Rewinding:\n" for change in changes: - msg += "{} -> {} {}\n".format(*change) + msg += "{} -> {} {}\n".format(change[0], change[1], to_euro(change[2])) record(sender_number, change[1], change[0], change[2]) send(msg) @@ -362,7 +367,7 @@ def main(): global last_change if os.path.isfile(last_change_path): - last_change = json.load(open(last_cahnge_path, "r")) + last_change = json.load(open(last_change_path, "r")) handle_input(sys.stdin.read()) |
