Add option to invite specific users to all created group chat portals
This commit is contained in:
@@ -292,6 +292,13 @@ bridge:
|
|||||||
# When private_chat_invite is empty, this message is sent to users /starting the
|
# When private_chat_invite is empty, this message is sent to users /starting the
|
||||||
# relaybot. Telegram's "markdown" is supported.
|
# relaybot. Telegram's "markdown" is supported.
|
||||||
message: This is a Matrix bridge relaybot and does not support direct chats
|
message: This is a Matrix bridge relaybot and does not support direct chats
|
||||||
|
# List of users to invite to all group chat portals created by the bridge.
|
||||||
|
group_chat_invite: []
|
||||||
|
# Whether or not the relaybot should not bridge events in unbridged group chats.
|
||||||
|
# If false, portals will be created when the relaybot receives messages, just like normal
|
||||||
|
# users. This behavior is usually not desirable, as it interferes with manually bridging
|
||||||
|
# the chat to another room.
|
||||||
|
ignore_unbridged_group_chat: true
|
||||||
# Whether or not to allow creating portals from Telegram.
|
# Whether or not to allow creating portals from Telegram.
|
||||||
authless_portals: true
|
authless_portals: true
|
||||||
# Whether or not to allow Telegram group admins to use the bot commands.
|
# Whether or not to allow Telegram group admins to use the bot commands.
|
||||||
|
|||||||
@@ -351,6 +351,8 @@ class AbstractUser(ABC):
|
|||||||
Optional[po.Portal]]:
|
Optional[po.Portal]]:
|
||||||
if isinstance(update, UpdateShortChatMessage):
|
if isinstance(update, UpdateShortChatMessage):
|
||||||
portal = po.Portal.get_by_tgid(TelegramID(update.chat_id))
|
portal = po.Portal.get_by_tgid(TelegramID(update.chat_id))
|
||||||
|
if not portal:
|
||||||
|
self.log.warning(f"Received message in chat with unknown type {update.chat_id}")
|
||||||
sender = pu.Puppet.get(TelegramID(update.from_id))
|
sender = pu.Puppet.get(TelegramID(update.from_id))
|
||||||
elif isinstance(update, UpdateShortMessage):
|
elif isinstance(update, UpdateShortMessage):
|
||||||
portal = po.Portal.get_by_tgid(TelegramID(update.user_id), self.tgid, "user")
|
portal = po.Portal.get_by_tgid(TelegramID(update.user_id), self.tgid, "user")
|
||||||
@@ -404,7 +406,9 @@ class AbstractUser(ABC):
|
|||||||
|
|
||||||
async def update_message(self, original_update: UpdateMessage) -> None:
|
async def update_message(self, original_update: UpdateMessage) -> None:
|
||||||
update, sender, portal = self.get_message_details(original_update)
|
update, sender, portal = self.get_message_details(original_update)
|
||||||
if portal and not portal.allow_bridging:
|
if not portal:
|
||||||
|
return
|
||||||
|
elif portal and not portal.allow_bridging:
|
||||||
self.log.debug(f"Ignoring message in portal {portal.tgid_log} (bridging disallowed)")
|
self.log.debug(f"Ignoring message in portal {portal.tgid_log} (bridging disallowed)")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -413,10 +417,9 @@ class AbstractUser(ABC):
|
|||||||
if not config["bridge.relaybot.private_chat.invite"]:
|
if not config["bridge.relaybot.private_chat.invite"]:
|
||||||
self.log.debug(f"Ignoring private message to bot from {sender.id}")
|
self.log.debug(f"Ignoring private message to bot from {sender.id}")
|
||||||
return
|
return
|
||||||
elif not portal or not portal.mxid:
|
elif not portal.mxid and config["bridge.relaybot.ignore_unbridged_group_chat"]:
|
||||||
tgid_log = portal.tgid_log if portal else original_update.chat_id
|
self.log.debug("Ignoring message received by bot"
|
||||||
self.log.debug(
|
f" in unbridged chat {portal.tgid_log}")
|
||||||
f"Ignoring message received by bot in unbridged chat {tgid_log}")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.ignore_incoming_bot_events and self.relaybot and sender.id == self.relaybot.tgid:
|
if self.ignore_incoming_bot_events and self.relaybot and sender.id == self.relaybot.tgid:
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ class Config(BaseBridgeConfig):
|
|||||||
copy("bridge.relaybot.private_chat.invite")
|
copy("bridge.relaybot.private_chat.invite")
|
||||||
copy("bridge.relaybot.private_chat.state_changes")
|
copy("bridge.relaybot.private_chat.state_changes")
|
||||||
copy("bridge.relaybot.private_chat.message")
|
copy("bridge.relaybot.private_chat.message")
|
||||||
|
copy("bridge.relaybot.group_chat_invite")
|
||||||
|
copy("bridge.relaybot.ignore_unbridged_group_chat")
|
||||||
copy("bridge.relaybot.authless_portals")
|
copy("bridge.relaybot.authless_portals")
|
||||||
copy("bridge.relaybot.whitelist_group_admins")
|
copy("bridge.relaybot.whitelist_group_admins")
|
||||||
copy("bridge.relaybot.whitelist")
|
copy("bridge.relaybot.whitelist")
|
||||||
|
|||||||
@@ -293,11 +293,15 @@ class PortalMetadata(BasePortal, ABC):
|
|||||||
users = participants = None
|
users = participants = None
|
||||||
if not direct:
|
if not direct:
|
||||||
users, participants = await self._get_users(user, entity)
|
users, participants = await self._get_users(user, entity)
|
||||||
|
extra_invites = config["bridge.relaybot.group_chat_invite"]
|
||||||
|
invites += extra_invites
|
||||||
|
for invite in extra_invites:
|
||||||
|
power_levels.users.setdefault(invite, 100)
|
||||||
self._participants_to_power_levels(participants, power_levels)
|
self._participants_to_power_levels(participants, power_levels)
|
||||||
elif self.bot and self.tg_receiver == self.bot.tgid:
|
elif self.bot and self.tg_receiver == self.bot.tgid:
|
||||||
invites = config["bridge.relaybot.private_chat.invite"]
|
invites = config["bridge.relaybot.private_chat.invite"]
|
||||||
for invite in invites:
|
for invite in invites:
|
||||||
power_levels.users[invite] = 100
|
power_levels.users.setdefault(invite, 100)
|
||||||
self.title = puppet.displayname
|
self.title = puppet.displayname
|
||||||
initial_state = [{
|
initial_state = [{
|
||||||
"type": EventType.ROOM_POWER_LEVELS.serialize(),
|
"type": EventType.ROOM_POWER_LEVELS.serialize(),
|
||||||
|
|||||||
Reference in New Issue
Block a user