Add option to not bridge chats with too many members
This commit is contained in:
@@ -193,6 +193,8 @@ class Bot(AbstractUser):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return await reply("Portal is not public. Use `/invite <mxid>` to get an invite.")
|
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(
|
async def handle_command_invite(
|
||||||
self, portal: po.Portal, reply: ReplyFunc, mxid_input: UserID
|
self, portal: po.Portal, reply: ReplyFunc, mxid_input: UserID
|
||||||
|
|||||||
@@ -233,7 +233,10 @@ async def join(evt: CommandEvent) -> EventID | None:
|
|||||||
updates.stringify(),
|
updates.stringify(),
|
||||||
)
|
)
|
||||||
raise e
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ class Config(BaseBridgeConfig):
|
|||||||
copy("bridge.allow_avatar_remove")
|
copy("bridge.allow_avatar_remove")
|
||||||
|
|
||||||
copy("bridge.max_initial_member_sync")
|
copy("bridge.max_initial_member_sync")
|
||||||
|
copy("bridge.max_member_count")
|
||||||
copy("bridge.sync_channel_members")
|
copy("bridge.sync_channel_members")
|
||||||
copy("bridge.skip_deleted_members")
|
copy("bridge.skip_deleted_members")
|
||||||
copy("bridge.startup_sync")
|
copy("bridge.startup_sync")
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ bridge:
|
|||||||
# will not send any more members.
|
# will not send any more members.
|
||||||
# -1 means no limit (which means it's limited to 10000 by the server)
|
# -1 means no limit (which means it's limited to 10000 by the server)
|
||||||
max_initial_member_sync: 100
|
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.
|
# 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
|
# If no channel admins have logged into the bridge, the bridge won't be able to sync the member
|
||||||
# list regardless of this setting.
|
# list regardless of this setting.
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ class Portal(DBPortal, BasePortal):
|
|||||||
self._sponsored_msg_lock = asyncio.Lock()
|
self._sponsored_msg_lock = asyncio.Lock()
|
||||||
self._sponsored_seen = {}
|
self._sponsored_seen = {}
|
||||||
self._new_messages_after_sponsored = True
|
self._new_messages_after_sponsored = True
|
||||||
|
self._bridging_blocked_at_runtime = False
|
||||||
|
|
||||||
self._msg_conv = putil.TelegramMessageConverter(self)
|
self._msg_conv = putil.TelegramMessageConverter(self)
|
||||||
|
|
||||||
@@ -385,7 +386,9 @@ class Portal(DBPortal, BasePortal):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def allow_bridging(self) -> bool:
|
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
|
return True
|
||||||
elif self.filter_mode == "whitelist":
|
elif self.filter_mode == "whitelist":
|
||||||
return self.tgid in self.filter_list
|
return self.tgid in self.filter_list
|
||||||
@@ -747,6 +750,16 @@ class Portal(DBPortal, BasePortal):
|
|||||||
entity = await self.get_entity(user)
|
entity = await self.get_entity(user)
|
||||||
self.log.trace("Fetched data: %s", entity)
|
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")
|
self.log.debug("Creating room")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -2636,6 +2649,9 @@ class Portal(DBPortal, BasePortal):
|
|||||||
if not self.mxid:
|
if not self.mxid:
|
||||||
self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id)
|
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)
|
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 (
|
if (
|
||||||
self.peer_type == "user"
|
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.updates import GetStateRequest
|
||||||
from telethon.tl.functions.users import GetUsersRequest
|
from telethon.tl.functions.users import GetUsersRequest
|
||||||
from telethon.tl.types import (
|
from telethon.tl.types import (
|
||||||
|
Channel,
|
||||||
Chat,
|
Chat,
|
||||||
ChatForbidden,
|
ChatForbidden,
|
||||||
InputUserSelf,
|
InputUserSelf,
|
||||||
|
|||||||
Reference in New Issue
Block a user