Add option to not bridge chats with too many members

This commit is contained in:
Tulir Asokan
2022-06-22 12:05:48 +03:00
parent bac3abcb4c
commit e8eef1c31e
6 changed files with 29 additions and 2 deletions
+17 -1
View File
@@ -326,6 +326,7 @@ class Portal(DBPortal, BasePortal):
self._sponsored_msg_lock = asyncio.Lock()
self._sponsored_seen = {}
self._new_messages_after_sponsored = True
self._bridging_blocked_at_runtime = False
self._msg_conv = putil.TelegramMessageConverter(self)
@@ -385,7 +386,9 @@ class Portal(DBPortal, BasePortal):
@property
def allow_bridging(self) -> bool:
if self.peer_type == "user":
if self._bridging_blocked_at_runtime:
return False
elif self.peer_type == "user":
return True
elif self.filter_mode == "whitelist":
return self.tgid in self.filter_list
@@ -747,6 +750,16 @@ class Portal(DBPortal, BasePortal):
entity = await self.get_entity(user)
self.log.trace("Fetched data: %s", entity)
participants_count = 2
if isinstance(entity, Chat):
participants_count = entity.participants_count
elif isinstance(entity, Channel) and not entity.broadcast:
participants_count = entity.participants_count
if 0 < self.config["bridge.max_member_count"] < participants_count:
self.log.warning(f"Not bridging chat, too many participants (%d)", participants_count)
self._bridging_blocked_at_runtime = True
return None
self.log.debug("Creating room")
try:
@@ -2636,6 +2649,9 @@ class Portal(DBPortal, BasePortal):
if not self.mxid:
self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id)
await self.create_matrix_room(source, invites=[source.mxid], update_if_exists=False)
if not self.mxid:
self.log.warning("Room doesn't exist even after creating, dropping %d", evt.id)
return
if (
self.peer_type == "user"