Here's an updated version with:
 
Reduced redundancy in comments
Added docstrings
Added type hints
```py 
import os
import asyncio
import datetime as dt
 
from logger import get_logger
from nio import AsyncClient, MatrixRoom, RoomMessageText
 
_logger = get_logger()  # type: ignore
 
ELEM_ROOM = os.environ.get("ELEM_ROOM")  # type: str
ELEM_USR = os.environ.get("ELEM_USR")  # type: str
ELEM_PSW = os.environ.get("ELEM_PSW")  # type: str
 
def send(msg: str) -> None:
    """Send a message to a Matrix room."""
 
    async def message_callback_send(room: MatrixRoom, event: RoomMessageText) -> None:
        """Log sent messages."""
        _logger.info(f"Message sent to room {room.display_name} | "
                     f"{room.user_name(event.sender)}: {event.body}")
 
    async def send_message() -> None:
        """Connect to Matrix and send a message."""
        client = AsyncClient("https://matrix.org", ELEM_USR)
        client.add_event_callback(message_callback_send, RoomMessageText)
        try:
            _logger.info(await client.login(ELEM_PSW))
        except ValueError as e:
            _logger.error(f"Failed to login - wrong or missing password?\n{e}")
            raise e
        await client.room_send(
            room_id=ELEM_ROOM,
            message_type="m.room.message",
            content={"msgtype": "m.text", "body": msg},
        )
        _logger.info(f"Message sent to room {ELEM_ROOM} | {ELEM_USR}: {msg}")
        await client.close()
 
    asyncio.get_event_loop().run_until_complete(send_message())
 
if __name__ == "__main__":
    msg = f"Hello world! {dt.datetime.now()}"
    send(msg)
```
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence