- await client.room_send(
- room_id=room_id,
- message_type="m.room.message",
- content={
- "msgtype": "m.text",
- "body": line.rstrip("\n")
- }
- )
+ if self._joined_room_id != None:
+ try:
+ msgB64Bytes = line.rstrip("\n").encode("UTF-8")
+ msgBytes = base64.b64decode(msgB64Bytes)
+ msgStr = msgBytes.decode("UTF-8")
+ 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": msgStr
+ }
+ )
+ else:
+ self._log(logging.WARNING, "Dropping message cause no room joined")
+
+ def _tickle_fifo(self):
+ fifo = -1
+ try:
+ fifo = posix.open(self._fifo_path, posix.O_WRONLY | posix.O_NONBLOCK)
+ posix.write(fifo, "\n".encode())
+ except OSError as e:
+ if e.errno == errno.ENXIO:
+ pass
+ finally:
+ if fifo != -1:
+ posix.close(fifo)
+
+ async def _get_joined_room_id(self, client):
+ joined_room_ids = ( await client.joined_rooms() ).rooms
+ for room_id, room in client.rooms.items():
+ if room.display_name == self._room_name:
+ if room_id in joined_room_ids:
+ return room_id
+ return None