diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-04-28 17:41:06 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-04-28 17:41:06 +0200 |
| commit | 8c38c0244f8c530bc7a4d67d7f70bb59af942a63 (patch) | |
| tree | 608958c83029db242d6d546a3aee3ba8931355cf /geldschieberbot.py | |
| parent | 7d2b5de4552834628c68228e12a68c2e29e52791 (diff) | |
| download | geldschieberbot-8c38c0244f8c530bc7a4d67d7f70bb59af942a63.tar.gz geldschieberbot-8c38c0244f8c530bc7a4d67d7f70bb59af942a63.zip | |
prevent crashes when money should be transfered to the issuer
Diffstat (limited to 'geldschieberbot.py')
| -rw-r--r-- | geldschieberbot.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index c249dd2..44327e1 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -72,9 +72,11 @@ def record(recipient, donor, amount): """Apply changes to the balance""" # Only change anything if this is not a dry run - if not dry_run: - balance[donor][recipient] += amount - balance[recipient][donor] -= amount + if dry_run: + return + + balance[donor][recipient] += amount + balance[recipient][donor] -= amount def to_cent(euro): if '.' in euro: @@ -275,11 +277,14 @@ def split(sender, args, msg): output = f"Split {to_euro(amount)} between {persons} -> {to_euro(amount_per_person)} each\n" change = [args] for p in args[2:]: - if not p in name2num: - output += p + " not known. Please take care manually\n" + if p in name2num: + if p == recipient: + output += f"{p}, you will be charged multiple times. This may not be what you want\n" + else: + record(recipient, p, amount_per_person) + change.append([recipient, p, amount_per_person]) else: - record(recipient, p, amount_per_person) - change.append([recipient, p, amount_per_person]) + output += f"{p} not known. Please take care manually\n" if record_changes and not dry_run: changes[recipient].append(change) @@ -307,6 +312,9 @@ def transaction(sender, args, msg): else: return None, 'recipient not known' + if sender == recipient: + return None, 'you can not transfere money to or from yourself' + try: amount = to_cent(amount) except: |
