diff options
Diffstat (limited to 'geldschieberbot.py')
| -rw-r--r-- | geldschieberbot.py | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index 7778af4..2c13ca8 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -317,60 +317,58 @@ cmds["nimm"] = transaction def transfer(sender, args, msg): if len(args) < 4: - send('ERROR: not in form "{} amount source destination"'.format(args[0])) - return 1 + return None, 'not in form "{} amount source destination"'.format(args[0]) - sender_num = sender if not sender in num2name: - send('ERROR: you must register first') - return 1 + return None, 'you must register first' else: sender = num2name[sender] try: - amount = int(args[1]) + amount_raw = args[1] + amount_cent = to_cent(amount_raw) except: - return None, "ERROR: amount must be a positive number" + return None, "amount must be a positive number" source, destination = args[2:4] if source not in balance: - send("ERROR: source {} not known".format(source)) - return 1 + return None, "source {} not known".format(source) elif destination not in balance: - send("ERROR: destination {} not known".format(destination)) - return 1 + return None, "destination {} not known".format(destination) output = "" global record_changes + saved_record_changes = record_changes record_changes = False change = [args] - ret, err = transaction(sender_num, "!zieh {} {}".format(source, amount).split(), "") + ret, err = transaction(sender, "!zieh {} {}".format(source, amount_raw).split(), "") if err: # No changes yet we can fail return None, err else: output += ret - change.append((sender, source, amount)) + change.append((sender, source, amount_cent)) - ret, err = transaction(sender_num, "!schieb {} {}".format(destination, amount).split(), "") + ret, err = transaction(sender, "!schieb {} {}".format(destination, amount_raw).split(), "") if err: - output += "ERROR: " + err + "\nThe balance may be in a inconsistent state please take care manually" + output += err + "\nThe balance may be in a inconsistent state please take care manually" return output, None else: output += ret - change.append((sender, source, amount)) + change.append((sender, source, amount_cent)) - ret, err = transaction(name2num[source], "!zieh {} {}".format(destination, amount).split(), "") + ret, err = transaction(source, "!zieh {} {}".format(destination, amount_raw).split(), "") if err: - output += "ERROR: " + err + "\nThe balance may be in a inconsistent state please take care manually" + output += err + "\nThe balance may be in a inconsistent state please take care manually" return output, None else: output += ret - change.append((sender, source, amount)) + change.append((sender, source, amount_cent)) - if record_changes and not dry_run: + record_changes = saved_record_changes + if err is None and record_changes and not dry_run: changes[sender].append(change) return output, None |
