Add option to not bridge chats with too many members
This commit is contained in:
@@ -193,6 +193,8 @@ class Bot(AbstractUser):
|
||||
)
|
||||
else:
|
||||
return await reply("Portal is not public. Use `/invite <mxid>` to get an invite.")
|
||||
else:
|
||||
return await reply("Couldn't create portal room")
|
||||
|
||||
async def handle_command_invite(
|
||||
self, portal: po.Portal, reply: ReplyFunc, mxid_input: UserID
|
||||
|
||||
@@ -233,7 +233,10 @@ async def join(evt: CommandEvent) -> EventID | None:
|
||||
updates.stringify(),
|
||||
)
|
||||
raise e
|
||||
return await evt.reply(f"Created room for {portal.title}")
|
||||
if portal.mxid:
|
||||
return await evt.reply(f"Created room for {portal.title}")
|
||||
else:
|
||||
return await evt.reply(f"Couldn't create room for {portal.title}")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ class Config(BaseBridgeConfig):
|
||||
copy("bridge.allow_avatar_remove")
|
||||
|
||||
copy("bridge.max_initial_member_sync")
|
||||
copy("bridge.max_member_count")
|
||||
copy("bridge.sync_channel_members")
|
||||
copy("bridge.skip_deleted_members")
|
||||
copy("bridge.startup_sync")
|
||||
|
||||
@@ -148,6 +148,10 @@ bridge:
|
||||
# will not send any more members.
|
||||
# -1 means no limit (which means it's limited to 10000 by the server)
|
||||
max_initial_member_sync: 100
|
||||
# Maximum number of participants in chats to bridge. Only applies when the portal is being created.
|
||||
# If there are more members when trying to create a room, the room creation will be cancelled.
|
||||
# -1 means no limit (which means all chats can be bridged)
|
||||
max_member_count: -1
|
||||
# Whether or not to sync the member list in channels.
|
||||
# If no channel admins have logged into the bridge, the bridge won't be able to sync the member
|
||||
# list regardless of this setting.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -26,6 +26,7 @@ from telethon.tl.functions.contacts import GetContactsRequest, SearchRequest
|
||||
from telethon.tl.functions.updates import GetStateRequest
|
||||
from telethon.tl.functions.users import GetUsersRequest
|
||||
from telethon.tl.types import (
|
||||
Channel,
|
||||
Chat,
|
||||
ChatForbidden,
|
||||
InputUserSelf,
|
||||
|
||||
Reference in New Issue
Block a user