aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2018-10-05 17:40:31 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2018-10-05 17:40:31 +0200
commit68ddd6274696d169a734a5add4406c450c8aeba2 (patch)
tree500e49c40a1f0c56b774c2162dcf3cfd3c72466c
parent3f67415e8f0e94e974240bb1cc9d5fba8a657799 (diff)
downloadgeldschieberbot-68ddd6274696d169a734a5add4406c450c8aeba2.tar.gz
geldschieberbot-68ddd6274696d169a734a5add4406c450c8aeba2.zip
use json output of signal-cli
-rw-r--r--geldschieberbot.py63
1 files changed, 13 insertions, 50 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index a4a7179..191ca9f 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -16,9 +16,9 @@ num2name = {}
"""Dict associating users with their last change"""
last_change = {}
-group_id = "GELD!!!"
+group_id = os.environ["GSB_GROUP_ID"]
-send_cmd = "signal-cli -u irgendwer send -g irgendwem"
+send_cmd = os.environ["GSB_SEND_CMD"]
"""Run without changing the stored state"""
dry_run = False
@@ -113,49 +113,19 @@ Happy Geldschieben!
"""
def handle_input(inp):
- messages = inp.split("\n\n")
- for message in messages:
- lines = message.split('\n')
+ for l in inp.splitlines():
+ message = json.loads(l)["envelope"]
- # A message with Body must have at least 4 lines
- if len(lines) < 4:
- continue
-
- lines[0].lower()
- w = lines[0].split(' ')
-
- # Broken message
- if len(w) < 4:
- print("Broken msg:")
- print(message)
- continue
-
- # TODO support linked devices
- sender_number = w[-3]
-
- body_found = False
- body = []
-
- # message is not in the group with group_id
- not_in_group = True
-
- for idx, line in enumerate(lines[1:]):
- # Collect body till we find Group ID:
- # THIS COULD BREAK VERY EASILY
- if line[0:6] == "Body: ":
- body.append(line[6:])
- body_found = True
- elif body_found:
- if not line == "Group info:":
- body.append(line)
- else:
- not_in_group = lines[idx+1].strip() == "Id: " + group_id
- break
-
- if not_in_group:
+ sender = message["source"]
+ if not "dataMessage" in message:
continue
+ else:
+ message = message["dataMassage"]
+ if message["groupInfo"] != group_id:
+ continue
+ body = message["message"].lower().splitlines()
- w = body[0].lower().split(' ')
+ w = body[0].split(' ')
cmd = w[0]
@@ -363,20 +333,13 @@ def main():
if len(sys.argv) > 1 and sys.argv[1] in ["-d", "--dry-run"]:
global dry_run
dry_run = True
- print("Dry Run no changes will apply!
-
- global group_id
- group_id = os.environ["GSB_GROUP_ID"]
+ print("Dry Run no changes will apply!")
store_path = os.environ["GSB_STORE_PATH"]
balance_path = store_path + "/balance.json"
registration_path = store_path + "/registration.json"
last_change_path = store_path + "/last_change.json"
-
- global send_cmd
- send_cmd = os.environ["GSB_SEND_CMD"]
-
global balance
if os.path.isfile(balance_path):
balance = json.load(open(balance_path, "r"))