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
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

View file

@ -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