diff options
| -rw-r--r-- | geldschieberbot.py | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index a1209dd..0b6a1c6 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -21,19 +21,27 @@ send_cmd = "signal-cli -u irgendwer send -g irgendwem" def send(msg): subprocess.run(send_cmd.split(' '), input=msg.encode()) -def create_summary(): - summary = "Summary:\n" +def create_summary(user): + summary = "" + p_balances = balance[user] # failes if user is not in balance + for person in p_balances: + amount = p_balances[person] + if amount == 0: + continue + summary += "\t" + ("<-" if amount < 0 else "->") + summary += " " + person2 + " " + str(abs(amount)) + "\n" + if summary == "": + summary = "\tAll fine :)\n" + summary = user + ":\n" + summary + return summary + +def create_total_summary(): + summary = "Summary:" for person in balance: - summary += person + ":\n" - - p_balance = balance[person] - for person2 in p_balance: - amount = p_balance[person2] - summary += "\t" + ("<-" if amount < 0 else "->") - summary += " " + person2 + " " + str(abs(amount)) + "\n" - summary += "\n" - + summary += '\n' + summary += "* " + create_summary(person) + return summary def create_members(): @@ -119,10 +127,15 @@ def handle_input(inp): balance[w[1]] = nm elif w[0] == "!sum": - if len(w) > 2: - send('ERROR: not in form "!sum [name]"') + if len(w) == 1: + send(create_total_summary()) + elif len(w) == 2: + if w[1] in name2num: + send("Summary:\n" + create_summary(w[1])) + else: + send("ERROR: name not registered") else: - send(create_summary()) + send('ERROR: not in form "!sum [name]"') elif w[0] == "!schieb" or w[0] == "!zieh": if len(w) != 3: |
