- 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:
+ 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")
+
+ 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