|
|
|
@@ -2,7 +2,7 @@ import os
|
|
|
|
|
import asyncio
|
|
|
|
|
import logging
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText
|
|
|
|
|
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, InviteMemberEvent
|
|
|
|
|
from nio.responses import LoginResponse
|
|
|
|
|
|
|
|
|
|
# --- Load environment variables ---
|
|
|
|
@@ -51,6 +51,15 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
|
|
|
|
)
|
|
|
|
|
logger.info("Replied with greeting to %s", event.sender)
|
|
|
|
|
|
|
|
|
|
async def invite_cb(room, event):
|
|
|
|
|
"""
|
|
|
|
|
Called when the bot is invited to a room.
|
|
|
|
|
"""
|
|
|
|
|
logger.debug("Invite callback triggered")
|
|
|
|
|
if event.state_key == USER_ID:
|
|
|
|
|
await client.join(room.room_id)
|
|
|
|
|
logger.info("Auto-joined invited room %s", room.room_id)
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
|
global client
|
|
|
|
|
logger.debug(HOMESERVER_URL)
|
|
|
|
@@ -79,6 +88,7 @@ async def main():
|
|
|
|
|
|
|
|
|
|
# Register callback and start syncing
|
|
|
|
|
client.add_event_callback(message_callback, RoomMessageText)
|
|
|
|
|
client.add_event_callback(invite_cb, InviteMemberEvent)
|
|
|
|
|
logger.info("Starting sync loop with timeout=30000ms")
|
|
|
|
|
await client.sync_forever(timeout=30000)
|
|
|
|
|
|
|
|
|
|