matrix-gptbot/callbacks/roommember.py
2023-05-02 06:58:49 +00:00

10 lines
430 B
Python

from nio import RoomMemberEvent, MatrixRoom
async def roommember_callback(room: MatrixRoom, event: RoomMemberEvent, bot):
if event.membership == "leave":
bot.logger.log(f"User {event.state_key} left room {room.room_id} - am I alone now?")
if len(room.users) == 1:
bot.logger.log("Yes, I was abandoned - leaving...")
await bot.matrix_client.room_leave(room.room_id)
return