Bug fixes

This commit is contained in:
Ben 2025-06-19 16:50:03 -07:00
parent 99871321c2
commit 8cb53d1ab9
2 changed files with 14 additions and 26 deletions

View file

@ -15,17 +15,17 @@ allowed_locations:
# Otherwise only listed senders # Otherwise only listed senders
allowed_senders: allowed_senders:
foo: foo:
- "@reports:fiftyfiftyonerarizona.org" - "@reports:fiftyfiftyonearizona.org"
bar: bar:
- "@reports:example.org" - "@reports:example.org"
- "@reports:example.com" - "@reports:example.com"
# Where and how the plugin will send the data to # Where and how the plugin will send the data to
brair_url: "http://localhost:7000" briar_url: "http://localhost:7000"
# Authentication token # Authentication token
brair_token: "changeMe" briar_token: "changeMe"
# Which user IDs to send alerts to (these are incremental integers) # Which user IDs to send alerts to (these are incremental integers)
brair_sendto: briar_sendto:
- 1 - 1
- 2 - 2

View file

@ -14,12 +14,9 @@ class Config(BaseProxyConfig):
helper.copy("allowed_locations_enabled") helper.copy("allowed_locations_enabled")
helper.copy("allowed_locations") helper.copy("allowed_locations")
helper.copy("allowed_senders") helper.copy("allowed_senders")
helper.copy("server_url") helper.copy("briar_url")
helper.copy("server_topic") helper.copy("briar_token")
helper.copy("command_prefix") helper.copy("briar_sendto")
helper.copy("server_use_authentication")
helper.copy("server_username")
helper.copy("server_password")
helper.copy("send_reaction") helper.copy("send_reaction")
class ConsumerBriar(Plugin): class ConsumerBriar(Plugin):
@ -55,11 +52,9 @@ class ConsumerBriar(Plugin):
# Check allowed senders # Check allowed senders
allowed_senders = self.config["allowed_senders"] allowed_senders = self.config["allowed_senders"]
print(evt.sender)
if st_desig in self.config["allowed_senders"]: 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'][st_desig]:
if not evt.sender in self.config['allowed_senders'].get(st_desig, []):
return return
# Sending notification to Briar # Sending notification to Briar
@ -67,29 +62,22 @@ class ConsumerBriar(Plugin):
# AND that it has been sent to all contacts # AND that it has been sent to all contacts
# Loop through each user # 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 # Reset sent status first time, as we want to detect if
if sent is None: sent = True 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:]) body = {"text": ' '.join(tokens[1:])}
if len(self.config["allowed_locations"]) != 1:
body = tokens[0] + ": " + body
body = '{"text":"' + body + '"}'
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: if not response.status == 200:
sent = False sent = False
if self.config.["send_reaction"]: if self.config["send_reaction"]:
if sent is True: if sent is True:
await evt.react("👍") await evt.react("👍")
if sent is False: if sent is False:
await evt.react("👎") await evt.react("👎")
# That's all, folks