From 8cb53d1ab9ec2401b923848890190fc8a34a119c Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 19 Jun 2025 16:50:03 -0700 Subject: [PATCH] Bug fixes --- base-config.yaml | 8 ++++---- consumerbriar.py | 32 ++++++++++---------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/base-config.yaml b/base-config.yaml index 70026bf..5ab2e96 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -15,17 +15,17 @@ allowed_locations: # Otherwise only listed senders allowed_senders: foo: - - "@reports:fiftyfiftyonerarizona.org" + - "@reports:fiftyfiftyonearizona.org" bar: - "@reports:example.org" - "@reports:example.com" # Where and how the plugin will send the data to -brair_url: "http://localhost:7000" +briar_url: "http://localhost:7000" # Authentication token -brair_token: "changeMe" +briar_token: "changeMe" # Which user IDs to send alerts to (these are incremental integers) -brair_sendto: +briar_sendto: - 1 - 2 diff --git a/consumerbriar.py b/consumerbriar.py index 9e951d7..9aae729 100644 --- a/consumerbriar.py +++ b/consumerbriar.py @@ -14,12 +14,9 @@ class Config(BaseProxyConfig): helper.copy("allowed_locations_enabled") helper.copy("allowed_locations") helper.copy("allowed_senders") - helper.copy("server_url") - helper.copy("server_topic") - helper.copy("command_prefix") - helper.copy("server_use_authentication") - helper.copy("server_username") - helper.copy("server_password") + helper.copy("briar_url") + helper.copy("briar_token") + helper.copy("briar_sendto") helper.copy("send_reaction") class ConsumerBriar(Plugin): @@ -55,11 +52,9 @@ class ConsumerBriar(Plugin): # Check allowed senders allowed_senders = self.config["allowed_senders"] - print(evt.sender) if st_desig in self.config["allowed_senders"]: - print(f"Allowed senders for {st_desig}: {self.config['allowed_senders'].get(st_desig, [])}") - if not evt.sender in self.config['allowed_senders'].get(st_desig, []): + if not evt.sender in self.config['allowed_senders'][st_desig]: return # Sending notification to Briar @@ -67,29 +62,22 @@ class ConsumerBriar(Plugin): # AND that it has been sent to all contacts # Loop through each user - for userId in self.config["brair_sendto"]: + for userId in self.config["briar_sendto"].keys(): # Reset sent status first time, as we want to detect if if sent is None: sent = True - url = self.config["brair_url"] + "/v1/messages/" + str(userId) + url = self.config["briar_url"] + "/v1/messages/" + str(userId) - body = ' '.join(tokens[1:]) - if len(self.config["allowed_locations"]) != 1: - body = tokens[0] + ": " + body - body = '{"text":"' + body + '"}' + body = {"text": ' '.join(tokens[1:])} - headers = {'Authorization': 'Bearer ' + self.config["brair_token"]} + headers = {'Authorization': "Bearer " + self.config["briar_token"]} - async with self.http.post(url, data=body, auth=authentication, headers=headers) as response: + async with self.http.post(url, json=body, headers=headers) as response: if not response.status == 200: sent = False - if self.config.["send_reaction"]: + if self.config["send_reaction"]: if sent is True: await evt.react("👍") if sent is False: await evt.react("👎") - - - -# That's all, folks \ No newline at end of file