]> git.treefish.org Git - mtxbot.git/blobdiff - src/presence.py
Fix shutdown on error
[mtxbot.git] / src / presence.py
index e239bdb454c5cde70a8dc31d87b6cfb4835e4c49..d9b65294ff68d397a5f5250c3a35fc73c8e39ba1 100644 (file)
@@ -4,8 +4,11 @@ import errno
 import logging
 import posix
 
+from inputparser import InputParser
+
 class Presence:
     def __init__(self, room_name, fifo_path):
+        self._input_parser = InputParser()
         self._room_name = room_name
         self._fifo_path = fifo_path
         self._joined_room_id = None
@@ -68,14 +71,17 @@ class Presence:
             if self._stop:
                 break
             if self._joined_room_id != None:
-                await client.room_send(
-                    room_id=self._joined_room_id,
-                    message_type="m.room.message",
-                    content={
-                        "msgtype": "m.text",
-                        "body": line.rstrip("\n")
-                    }
-                )
+                try:
+                    self._input_parser.feed_line(line)
+                except Exception as e:
+                    self._log(logging.WARNING, "Error parsing input: %s" % str(e))
+                    continue
+                for content in self._input_parser.fetch_decoded():
+                    await client.room_send(
+                        room_id=self._joined_room_id,
+                        message_type="m.room.message",
+                        content=content
+                    )
             else:
                 self._log(logging.WARNING, "Dropping message cause no room joined")