diff --git a/modules/room.py b/modules/room.py index e944afe..3c25dcb 100644 --- a/modules/room.py +++ b/modules/room.py @@ -17,6 +17,8 @@ class MatrixModule(BotModule): await MatrixModule.servers_in_room(bot, room) elif args[0] == 'joined': await MatrixModule.joined_members(bot, room) + elif args[0] == 'banned': + await MatrixModule.banned_members(bot, room) @staticmethod async def servers_in_room(bot, room: nio.MatrixRoom): @@ -39,3 +41,23 @@ class MatrixModule(BotModule): @staticmethod async def joined_members(bot, room: nio.MatrixRoom): await bot.send_text(room, f"Member count: {room.member_count}") + + @staticmethod + async def banned_members(bot, room: nio.MatrixRoom): + banned_members = "Banned members:\n" + count = 0 + res = await bot.client.room_get_state(room.room_id) + + if isinstance(res, nio.RoomGetStateError): + raise res + else: + for state in res.events: + if state["type"] == "m.room.member": + content = state["content"] + if content["membership"] == "ban": + name = state["state_key"] + reason = content.get("reason") or "No reason" + banned_members += f" - {name}: \"{reason}\"\n" + count += 1 + banned_members = f"({count}) {banned_members}" + await bot.send_text(room, banned_members)