diff --git a/sample.config.yaml b/sample.config.yaml index 9839dc1..d5621f5 100644 --- a/sample.config.yaml +++ b/sample.config.yaml @@ -48,6 +48,9 @@ vetting: max_no_votes: 0 # Minimum power level to automatically invite users from vetting room power_level_invite: 10 + # List of additional rooms to invite vetted members to + # The bot must be in these rooms and have the invite permission + additional_rooms: [] # Logging setup logging: diff --git a/vetting_bot/callbacks.py b/vetting_bot/callbacks.py index 3a9601f..d3cdeeb 100644 --- a/vetting_bot/callbacks.py +++ b/vetting_bot/callbacks.py @@ -212,16 +212,15 @@ class Callbacks: if row is None: return - # Invite the user user_id = row[0] + # Invite user to main space logger.info("Inviting new user (%s) to the main space.", user_id) resp = await self.client.room_invite(self.config.main_space_id, user_id) if isinstance(resp, RoomInviteError): text = f"Failed inviting user: {resp}" logger.error(text, stack_info=True) - else: text = f"Invited {user_id}." logger.info(text) @@ -229,6 +228,20 @@ class Callbacks: self.client, self.config.vetting_room_id, text, notice=True ) + # Invite user to additional rooms + for room_id in self.config.additional_rooms: + resp = await self.client.room_invite(room_id, user_id) + if isinstance(resp, RoomInviteError): + logger.error( + "Couldn't invite %s to %s: %s", + user_id, + room_id, + resp, + stack_info=True, + ) + else: + logger.info("Invited %s to %s", user_id, room_id) + async def unknown(self, room: MatrixRoom, event: UnknownEvent) -> None: """Callback for when an event with a type that is unknown to matrix-nio is received. diff --git a/vetting_bot/config.py b/vetting_bot/config.py index 967c2e3..6565d91 100644 --- a/vetting_bot/config.py +++ b/vetting_bot/config.py @@ -138,6 +138,10 @@ class Config: self._get_cfg(["vetting", "power_level_invite"], required=True) ) + self.additional_rooms: tuple[str] = tuple( + self._get_cfg(["vetting", "additional_rooms"], required=False, default=[]) + ) + def _get_cfg( self, path: List[str],