diff --git a/janine/janine.py b/janine/janine.py
index d1b54f0..d7c4291 100644
--- a/janine/janine.py
+++ b/janine/janine.py
@@ -80,7 +80,7 @@ def to_warning(data):
sender=info.get('senderName', 'N/A'),
headline=info['headline'],
description=info['description'],
- instruction=info.get('instruction', 'N/A'),
+ instruction=info.get('instruction', ''),
landkreise=get_landkreise(data))
def get_landkreise(data):
@@ -189,6 +189,10 @@ class WarningBot:
if not self.__is_message_valid(msg):
return
+ # Send a deliverability receipt
+ receipt = aioxmpp.mdr.compose_receipt(msg)
+ self._client.enqueue(receipt)
+
cmd_parts = str(msg.body.any()).split(' ')
cmd = cmd_parts[0].lower()
@@ -304,15 +308,15 @@ help - Gebe diese Hilfe aus'''
if warning.id in ids:
continue
- if len(set(warning.landkreise).intersection(self._warn_clients.keys())):
+ # We need to use a set as a warning can apply to more than one
+ # Landkreis
+ if set(warning.landkreise).intersection(self._warn_clients.keys()):
body = format_warning(warning)
for landkreis in warning.landkreise:
for to in self._warn_clients.get(landkreis, []):
- msg = aioxmpp.stanza.Message(
- to=aioxmpp.JID.fromstr(to),
- type_=aioxmpp.MessageType.CHAT)
- msg.body[None] = body
- await self._client.send(msg)
+ await self._client.send(make_msg(
+ aioxmpp.JID.fromstr(to),
+ body))
def _load_config(self, config_file):
# Load config
@@ -332,6 +336,11 @@ help - Gebe diese Hilfe aus'''
with open(self._client_store, 'r') as clients_file:
self._warn_clients = json.loads(clients_file.read())
log.info('Clients read from disk')
+ else:
+ with open(self._client_store, 'w') as clients_file:
+ clients_file.write('{}')
+ os.chmod(self._client_store, S_IRUSR | S_IWUSR)
+ log.info('Clients file created with 0600')
## Warnings
self._warnings_file = os.path.join(self._data_dir, 'warnings.json')
diff --git a/janine/utils.py b/janine/utils.py
index 9306dc4..8ef4fb8 100644
--- a/janine/utils.py
+++ b/janine/utils.py
@@ -54,6 +54,11 @@ def format_warning(warning):
{warning.description}'''
+ if warning.instruction:
+ body = f'''{body}
+
+{warning.instruction}'''
+
# Smells like script injection, but okay
body = body.replace('
', '\n')
body = body.replace('
', '\n')