diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2018-10-05 17:47:29 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2018-10-05 17:47:29 +0200 |
| commit | c3428c6ff8c86ff4d3d3c3f50d8141d339968755 (patch) | |
| tree | cb66163a4e8779e01c6d01c621872601b9e15715 | |
| parent | f7fc208aed5e2593ff88e4327abfcd564a6ce1a5 (diff) | |
| parent | 5608caeccac9a1a2060ca4b25553088052de3f19 (diff) | |
| download | geldschieberbot-c3428c6ff8c86ff4d3d3c3f50d8141d339968755.tar.gz geldschieberbot-c3428c6ff8c86ff4d3d3c3f50d8141d339968755.zip | |
Merge branch 'newgen'
| -rw-r--r-- | geldschieberbot.py | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index fd19d7f..9cfe279 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_number = 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] @@ -365,18 +335,11 @@ def main(): dry_run = True print("Dry Run no changes will apply!") - global group_id - group_id = os.environ["GSB_GROUP_ID"] - 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")) |
