Compare commits
2 Commits
00925a640b
...
0dcd07a89f
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dcd07a89f | |||
| e10db9b674 |
@@ -3,6 +3,3 @@ HOMESERVER_URL = "https://matrix.org"
|
|||||||
USER_ID = "@botbot_user:matrix.org"
|
USER_ID = "@botbot_user:matrix.org"
|
||||||
PASSWORD = "botbot_password"
|
PASSWORD = "botbot_password"
|
||||||
LOG_LEVEL=INFO
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
# comma-separated list of rooms or aliases to join on startup
|
|
||||||
BOT_ROOMS=!room1:matrix.org,!another-room:matrix.org,!someroomalias:matrix.org
|
|
||||||
12
main.py
12
main.py
@@ -2,7 +2,7 @@ import os
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from dotenv import load_dotenv
|
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
|
from nio.responses import LoginResponse
|
||||||
|
|
||||||
# --- Load environment variables ---
|
# --- Load environment variables ---
|
||||||
@@ -51,6 +51,15 @@ async def message_callback(room: MatrixRoom, event: RoomMessageText):
|
|||||||
)
|
)
|
||||||
logger.info("Replied with greeting to %s", event.sender)
|
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():
|
async def main():
|
||||||
global client
|
global client
|
||||||
logger.debug(HOMESERVER_URL)
|
logger.debug(HOMESERVER_URL)
|
||||||
@@ -79,6 +88,7 @@ async def main():
|
|||||||
|
|
||||||
# Register callback and start syncing
|
# Register callback and start syncing
|
||||||
client.add_event_callback(message_callback, RoomMessageText)
|
client.add_event_callback(message_callback, RoomMessageText)
|
||||||
|
client.add_event_callback(invite_cb, InviteMemberEvent)
|
||||||
logger.info("Starting sync loop with timeout=30000ms")
|
logger.info("Starting sync loop with timeout=30000ms")
|
||||||
await client.sync_forever(timeout=30000)
|
await client.sync_forever(timeout=30000)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user