aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-10-25 13:10:58 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-10-25 13:10:58 +0200
commitfddeb8e0788526ae0682a1f821579c992a6f2995 (patch)
tree2108e247a95bcb38bdeacef277d7660bd71fe5a2
parentfe322496dcef750c086e25381c00268ea1a617d4 (diff)
downloadgeldschieberbot-fddeb8e0788526ae0682a1f821579c992a6f2995.tar.gz
geldschieberbot-fddeb8e0788526ae0682a1f821579c992a6f2995.zip
add gib nimm aliases & round numbers
-rw-r--r--geldschieberbot.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index c1a9353..7ae8ce6 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -7,13 +7,10 @@ import sys
"""Dict of dicts associating a second person to an amount"""
balance = {}
-store_path = "."
name2num = {}
num2name = {}
-registration_path = "reg.json"
-
group_id = "GELD!!!"
send_cmd = "signal-cli -u irgendwer send -g irgendwem"
@@ -31,11 +28,11 @@ def create_summary(user):
continue
total -= amount
summary += "\t" + ("<-" if amount < 0 else "->")
- summary += " " + person + " " + str(abs(amount)) + "\n"
+ summary += " " + person + " " + str(abs(amount).round(2)) + "\n"
if summary == "":
summary = "\tAll fine :)\n"
else:
- summary += "\tBalance: " + str(total)
+ summary += "\tBalance: " + str(total.round(2))
summary = user + ":\n" + summary
return summary
@@ -77,6 +74,7 @@ def handle_input(inp):
if len(lines) < 4:
continue
+ lines[0].lower()
w = lines[0].split(' ')
# Broken message
@@ -110,17 +108,16 @@ def handle_input(inp):
w = body.split(' ')
# supported commands are:
- # "!reg" register a name for this number
- # "!sum" send a summary to the group
- # "!schieb" give money to somebody
- # "!zieh" add debt of somebody
- # "!list" "!ls" list members
- # "!help" print all commands
+ # "!reg" register a name for this number
+ # "!sum" send a summary to the group
+ # "!schieb" "!gib" give money to somebody
+ # "!zieh" "!nimm" add debt of somebody
+ # "!list" "!ls" list members
+ # "!help" print all commands
if w[0] == "!reg":
if len(w) != 2:
send('ERROR: not in form "!reg name"')
else:
- w[1] = w[1].lower()
if w[1] in name2num:
send("ERROR: name already registered")
elif sender_number in num2name:
@@ -140,7 +137,6 @@ def handle_input(inp):
if len(w) == 1:
send(create_total_summary())
elif len(w) == 2:
- w[1] = w[1].lower()
if w[1] in name2num:
send("Summary:\n" + create_summary(w[1]))
else:
@@ -148,11 +144,10 @@ def handle_input(inp):
else:
send('ERROR: not in form "!sum [name]"')
- elif w[0] == "!schieb" or w[0] == "!zieh":
+ elif w[0] in ["!schieb", "!gib", "!zieh", "!nimm"]
if len(w) != 3:
- send('ERROR: not in form "!schieb amount recipient"')
+ send('ERROR: not in form "!cmd amount recipient"')
else:
- w[2] = w[2].lower()
if not sender_number in num2name:
send('ERROR: you must register first')
elif not w[2] in name2num:
@@ -169,7 +164,7 @@ def handle_input(inp):
send("ERROR: amount must be positiv")
continue
- if w[0] == "!zieh":
+ if w[0] in ["!zieh", "!nimm"]:
amount *= -1
balance[sender][w[2]] -= amount
@@ -177,7 +172,7 @@ def handle_input(inp):
p_balance = balance[sender][w[2]]
- send("New Balance: {0} {1} {2} {3}\n".format(sender, ("->" if p_balance > 0 else "<-"), abs(p_balance), w[2]))
+ send("New Balance: {0} {1} {2:g} {3}\n".format(sender, ("->" if p_balance > 0 else "<-"), abs(p_balance), w[2]))
elif w[0] == "!list" or w[0] == "!ls":
send(create_members())