Add support for bridging or responding to private chats with relaybot
This commit is contained in:
@@ -147,7 +147,8 @@ class BasePortal(ABC):
|
||||
|
||||
@property
|
||||
def has_bot(self) -> bool:
|
||||
return bool(self.bot and self.bot.is_in_chat(self.tgid))
|
||||
return ((bool(self.bot) and self.bot.is_in_chat(self.tgid))
|
||||
or (self.peer_type == "user" and self.tg_receiver == self.bot.tgid))
|
||||
|
||||
@property
|
||||
def main_intent(self) -> IntentAPI:
|
||||
|
||||
@@ -90,6 +90,8 @@ class PortalMatrix(BasePortal, MautrixBasePortal, ABC):
|
||||
**kwargs: Any) -> None:
|
||||
if not self.has_bot:
|
||||
return
|
||||
elif self.peer_type == "user" and not config["bridge.relaybot.private_chat.state_changes"]:
|
||||
return
|
||||
async with self.send_lock(self.bot.tgid):
|
||||
message = await self._get_state_change_message(event, user, **kwargs)
|
||||
if not message:
|
||||
|
||||
@@ -164,7 +164,8 @@ class PortalMetadata(BasePortal, ABC):
|
||||
AddChatUserRequest(chat_id=self.tgid, user_id=puppet.tgid, fwd_limit=0))
|
||||
elif self.peer_type == "channel":
|
||||
await source.client(InviteToChannelRequest(channel=self.peer, users=[puppet.tgid]))
|
||||
else:
|
||||
# We don't care if there are invites for private chat portals with the relaybot.
|
||||
elif not self.bot or self.tg_receiver != self.bot.tgid:
|
||||
raise ValueError("Invalid peer type for Telegram user invite")
|
||||
|
||||
async def sync_matrix_members(self) -> None:
|
||||
@@ -293,6 +294,10 @@ class PortalMetadata(BasePortal, ABC):
|
||||
if not direct:
|
||||
users, participants = await self._get_users(user, entity)
|
||||
self._participants_to_power_levels(participants, power_levels)
|
||||
elif self.tg_receiver == self.bot.tgid:
|
||||
invites = config["bridge.relaybot.private_chat.invite"]
|
||||
for invite in invites:
|
||||
power_levels.users[invite] = 100
|
||||
initial_state = [{
|
||||
"type": EventType.ROOM_POWER_LEVELS.serialize(),
|
||||
"content": power_levels.serialize(),
|
||||
@@ -302,11 +307,15 @@ class PortalMetadata(BasePortal, ABC):
|
||||
"type": "m.room.related_groups",
|
||||
"content": {"groups": [config["appservice.community_id"]]},
|
||||
})
|
||||
creation_content = {}
|
||||
if not config["bridge.federate_rooms"]:
|
||||
creation_content["m.federate"] = False
|
||||
|
||||
room_id = await self.main_intent.create_room(alias_localpart=alias, preset=preset,
|
||||
is_direct=direct, invitees=invites or [],
|
||||
name=self.title, topic=self.about,
|
||||
initial_state=initial_state)
|
||||
initial_state=initial_state,
|
||||
creation_content=creation_content)
|
||||
if not room_id:
|
||||
raise Exception(f"Failed to create room")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user