From d9e015d3935826b1d0f243d7fe94e05de5f6db39 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 23 Jul 2021 02:45:31 -0400 Subject: [PATCH] Forbid invalid joins --- matrix_puppeteer_line/matrix.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/matrix_puppeteer_line/matrix.py b/matrix_puppeteer_line/matrix.py index bc7ed55..b135140 100644 --- a/matrix_puppeteer_line/matrix.py +++ b/matrix_puppeteer_line/matrix.py @@ -130,6 +130,24 @@ class MatrixHandler(BaseMatrixHandler): finally: await invited_by.client.resume() + async def handle_join(self, room_id: RoomID, user_id: UserID, _: EventID) -> None: + user = await u.User.get_by_mxid(user_id) + + portal = await po.Portal.get_by_mxid(room_id) + if not portal: + return + + if not user.is_whitelisted: + await portal.main_intent.kick_user(room_id, user.mxid, + "You are not whitelisted on this LINE bridge.") + return + elif not await user.is_logged_in(): + await portal.main_intent.kick_user(room_id, user.mxid, + "You are not logged in to this LINE bridge.") + return + + self.log.debug(f"{user.mxid} joined {room_id}") + async def handle_leave(self, room_id: RoomID, user_id: UserID, event_id: EventID) -> None: portal = await po.Portal.get_by_mxid(room_id) if not portal: