]> git.treefish.org Git - mtxbot.git/commitdiff
use b64 encoding
authorAlexander Schmidt <alex@treefish.org>
Sun, 4 Oct 2020 06:49:55 +0000 (08:49 +0200)
committerAlexander Schmidt <alex@treefish.org>
Sun, 4 Oct 2020 06:49:55 +0000 (08:49 +0200)
src/mtxbot-post.py
src/presence.py

index 8d1fac8910ca76fb3f80df288247c13c8050e726..3e97ef2043f68675abe6929881002f13f0afab5f 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 
+import base64
 import errno
 import os
 import posix
@@ -25,11 +26,14 @@ if not ( os.path.exists(fifo_path) and
     print("Channel %s does not exist!" % sys.argv[1], file=sys.stderr)
     sys.exit(3)
 
+inBytes = sys.stdin.read().encode("UTF-8")
+inB64 = base64.b64encode(inBytes)
+
 for i in range(0, 10):
     fifo = -1
     try:
         fifo = posix.open(fifo_path, posix.O_WRONLY | posix.O_NONBLOCK)
-        posix.write(fifo, sys.stdin.read().encode())
+        posix.write(fifo, inB64)
         sys.exit(0)
     except OSError as e:
         if e.errno == errno.ENXIO:
index e239bdb454c5cde70a8dc31d87b6cfb4835e4c49..b3da8589dc1614fb250a2e0f352cfd441cdef0f3 100644 (file)
@@ -1,5 +1,6 @@
 import aiofiles
 import asyncio
+import base64
 import errno
 import logging
 import posix
@@ -68,12 +69,18 @@ class Presence:
             if self._stop:
                 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")
+                    continue
                 await client.room_send(
                     room_id=self._joined_room_id,
                     message_type="m.room.message",
                     content={
                         "msgtype": "m.text",
-                        "body": line.rstrip("\n")
+                        "body": msgBytes.decode("UTF-8")
                     }
                 )
             else: