aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-09-08 13:11:29 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-09-08 13:11:29 +0200
commit6bc1cc300930dac068d6ff31d84bbd840390b24a (patch)
treedac3307a42ec0e66204ec56e8882d6f4dd3480bf
parentcc2fd03b4ca02b0030eb293cc4fe01944311b0cf (diff)
downloadgeldschieberbot-6bc1cc300930dac068d6ff31d84bbd840390b24a.tar.gz
geldschieberbot-6bc1cc300930dac068d6ff31d84bbd840390b24a.zip
improve transfer
* fix old return codes * restore record_changes * call transaction not with cents because transaction will convert it to cents again
-rw-r--r--geldschieberbot.py38
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