]> git.treefish.org Git - mtxbot.git/blobdiff - src/presence.py
support html/markdown/plain messages of arbitrary length
[mtxbot.git] / src / presence.py
index b3da8589dc1614fb250a2e0f352cfd441cdef0f3..d9b65294ff68d397a5f5250c3a35fc73c8e39ba1 100644 (file)
@@ -1,12 +1,14 @@
 import aiofiles
 import asyncio
 import aiofiles
 import asyncio
-import base64
 import errno
 import logging
 import posix
 
 import errno
 import logging
 import posix
 
+from inputparser import InputParser
+
 class Presence:
     def __init__(self, room_name, fifo_path):
 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
         self._room_name = room_name
         self._fifo_path = fifo_path
         self._joined_room_id = None
@@ -70,19 +72,16 @@ class Presence:
                 break
             if self._joined_room_id != None:
                 try:
                 break
             if self._joined_room_id != None:
                 try:
-                    msgB64Bytes = line.rstrip("\n").encode("UTF-8")
-                    msgBytes = base64.b64decode(msgB64Bytes)
-                except:
-                    self._log(logging.WARNING, "Error decoding message")
+                    self._input_parser.feed_line(line)
+                except Exception as e:
+                    self._log(logging.WARNING, "Error parsing input: %s" % str(e))
                     continue
                     continue
-                await client.room_send(
-                    room_id=self._joined_room_id,
-                    message_type="m.room.message",
-                    content={
-                        "msgtype": "m.text",
-                        "body": msgBytes.decode("UTF-8")
-                    }
-                )
+                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")
 
             else:
                 self._log(logging.WARNING, "Dropping message cause no room joined")