mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2025-12-06 06:21:36 +01:00
wip:
This commit is contained in:
@@ -14,15 +14,23 @@ def signal_send(phone, message):
|
||||
'''Send message via signal'''
|
||||
cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone]
|
||||
p = subprocess.run(cmd)
|
||||
# TODO check return code #
|
||||
|
||||
|
||||
def report_dispatch_error(target, uid, error):
|
||||
'''Report an error for a give dispatch'''
|
||||
|
||||
pass # TODO
|
||||
|
||||
def confirm_dispatch(target, uid):
|
||||
|
||||
'''Confirm to server that message has been dispatched and can be removed'''
|
||||
|
||||
response = requests.post(target + "/confirm-dispatch", json=[{ "uid" : uid }],
|
||||
auth=(args.user, args.password))
|
||||
|
||||
if response.status_code not in [200, 204]:
|
||||
print("Failed to confirm disptach with server for {} ({})".format(uid, response.text), file=sys.stderr)
|
||||
print("Failed to confirm disptach with server for {} ({})".format(
|
||||
uid, response.text), file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -43,6 +51,7 @@ if __name__ == "__main__":
|
||||
if args.signal_cli_bin:
|
||||
signal_cli_bin = args.signal_cli_bin
|
||||
|
||||
# request dispatches #
|
||||
response = requests.get(args.target + "/get-dispatch?method={}".format(args.method),
|
||||
auth=(args.user, args.password))
|
||||
|
||||
@@ -50,9 +59,16 @@ if __name__ == "__main__":
|
||||
if response.status_code == HTTP_NOT_FOUND:
|
||||
sys.exit(0)
|
||||
|
||||
# fallback check for status #
|
||||
response.raise_for_status()
|
||||
|
||||
# track dispatches that were confirmed to avoid duplicate confirmation #
|
||||
dispatch_confirmed = []
|
||||
|
||||
# track failed dispatches #
|
||||
errors = dict()
|
||||
|
||||
# iterate over dispatch requests #
|
||||
for entry in response.json():
|
||||
|
||||
user = entry["person"]
|
||||
@@ -62,16 +78,22 @@ if __name__ == "__main__":
|
||||
|
||||
# send message #
|
||||
if entry["method"] == "signal":
|
||||
signal_send(phone, message)
|
||||
uid, error = signal_send(phone, message)
|
||||
else:
|
||||
print("Unsupported dispatch method {}".format(entry["method"]), sys=sys.stderr)
|
||||
print("Unsupported dispatch method {}".format(entry["method"]),
|
||||
sys=sys.stderr)
|
||||
|
||||
# confirm dispatch
|
||||
if not args.no_confirm:
|
||||
for uid in uid_list:
|
||||
if uid not in dispatch_confirmed:
|
||||
confirm_dispatch(args.target, uid)
|
||||
dispatch_confirmed.append(uid)
|
||||
|
||||
# confirm or report fail #
|
||||
if errors[uid]:
|
||||
report_dispatch_error(args.target, uid, errors[uid])
|
||||
else:
|
||||
confirm_dispatch(args.target, uid)
|
||||
dispatch_confirmed.append(uid)
|
||||
else:
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user