aboutsummaryrefslogtreecommitdiff
path: root/geldschieberbot.py
diff options
context:
space:
mode:
Diffstat (limited to 'geldschieberbot.py')
-rw-r--r--geldschieberbot.py69
1 files changed, 68 insertions, 1 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index 26ee8e1..c011b40 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -149,7 +149,7 @@ gib amount recipient - give money to recipient
zieh amount donor - get money from donor
nimm amount donor - get money from donor
-transfer amount source destination - transfer amount of your balance with source to destination
+transfer amount source destination - transfer amount of your balance from source to destination
cars [cmd] - interact with the available cars
cars [list | ls] - list available cars and their service charge
@@ -313,6 +313,73 @@ cmds["gib"] = transaction
cmds["zieh"] = transaction
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
+
+ sender_num = sender
+ if not sender in num2name:
+ send('ERROR: you must register first')
+ return 1
+ else:
+ sender = num2name[sender]
+
+ try:
+ amount = int(args[1])
+ except:
+ send("ERROR: amount must be a number")
+ return 1
+
+ if amount < 0:
+ send("ERROR: amount must be positiv")
+ return 1
+
+ source, destination = args[2:4]
+ if source not in balance:
+ send("ERROR: source {} not known".format(source))
+ return 1
+
+ elif destination not in balance:
+ send("ERROR: destination {} not known".format(destination))
+ return 1
+
+ output = ""
+ global record_changes
+ record_changes = False
+ change = [args]
+
+ ret, err = transaction(sender_num, "!zieh {} {}".format(source, amount).split(), "")
+ if err:
+ # No changes yet we can fail
+ return None, err
+ else:
+ output += ret
+ change.append((sender, source, amount))
+
+ ret, err = transaction(sender_num, "!schieb {} {}".format(destination, amount).split(), "")
+ if err:
+ output += "ERROR: " + err + "\nThe balance may be in a inconsistent state please take care manually"
+ return output, None
+ else:
+ output += ret
+ change.append((sender, source, amount))
+
+ ret, err = transaction(name2num[source], "!zieh {} {}".format(destination, amount).split(), "")
+ if err:
+ output += "ERROR: " + err + "\nThe balance may be in a inconsistent state please take care manually"
+ return output, None
+ else:
+ output += ret
+ change.append((sender, source, amount))
+
+ if record_changes and not dry_run:
+ changes[sender].append(change)
+
+ return output, None
+
+cmds["transfer"] = transfer
+
def cars(sender, args, msg):
# list cars
if len(args) < 2 or args[1] in ["ls", "list"]: