diff --git a/example-config.yaml b/example-config.yaml index da59d47d..f402aa2b 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -30,14 +30,14 @@ appservice: # Bridge config bridge: # Localpart template of MXIDs for Telegram users. - # {} is replaced with the user ID of the Telegram user. - username_template: "telegram_{}" + # {userid} is replaced with the user ID of the Telegram user. + username_template: "telegram_{userid}" # Localpart template of room aliases for Telegram portal rooms. - # {} is replaced with the name part of the public channel/group invite link ( https://t.me/{} ) - alias_template: "telegram_{}" + # {groupname} is replaced with the name part of the public channel/group invite link ( https://t.me/{} ) + alias_template: "telegram_{groupname}" # Displayname template for Telegram users. - # {} is replaced with the display name of the Telegram user. - displayname_template: "{} (Telegram)" + # {displayname} is replaced with the display name of the Telegram user. + displayname_template: "{displayname} (Telegram)" # Set the preferred order of user identifiers which to use in the Matrix puppet display name. # In the (hopefully unlikely) scenario that none of the given keys are found, the numeric user ID is used. diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 09b4f738..4316e5a4 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -82,8 +82,8 @@ class Config(DictWithRecursion): def generate_registration(self): homeserver = self["homeserver.domain"] - username_format = self.get("bridge.username_template", "telegram_{}").format(".+") - alias_format = self.get("bridge.alias_template", "telegram_{}").format(".+") + username_format = self.get("bridge.username_template", "telegram_{userid}").format(userid=".+") + alias_format = self.get("bridge.alias_template", "telegram_{groupname}").format(groupname=".+") self.set("appservice.as_token", self._new_token()) self.set("appservice.hs_token", self._new_token()) @@ -100,7 +100,7 @@ class Config(DictWithRecursion): }], "aliases": [{ "exclusive": True, - "regex": f"@{alias_format}:{homeserver}" + "regex": f"#{alias_format}:{homeserver}" }] }, "url": f"{appservice.get('protocol')}://{appservice.get('hostname')}:{appservice.get('port')}", diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py index 1a5303f0..796bed55 100644 --- a/mautrix_telegram/matrix.py +++ b/mautrix_telegram/matrix.py @@ -26,7 +26,7 @@ class MatrixHandler: self.log = log.getChild("mx") self.commands = CommandHandler(context) - alias_format = self.config.get("bridge.alias_template", "telegram_{}").format("(.+)") + alias_format = self.config.get("bridge.alias_template", "telegram_{groupname}").format(groupname="(.+)") hs = self.config["homeserver"]["domain"] self.localpart_regex = re.compile(f"@{alias_format}:{hs}") diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py index 0bae3c74..086532cb 100644 --- a/mautrix_telegram/puppet.py +++ b/mautrix_telegram/puppet.py @@ -29,7 +29,7 @@ class Puppet: def __init__(self, id=None, username=None, displayname=None, photo_id=None): self.id = id - self.localpart = config.get("bridge.alias_template", "telegram_{}").format(self.id) + self.localpart = config.get("bridge.username_template", "telegram_{userid}").format(userid=self.id) hs = config["homeserver"]["domain"] self.mxid = f"@{self.localpart}:{hs}" self.username = username @@ -75,7 +75,7 @@ class Puppet: if not format: return name - return config.get("bridge.displayname_template", "{} (Telegram)").format(name) + return config.get("bridge.displayname_template", "{displayname} (Telegram)").format(displayname=name) def update_info(self, source, info): changed = False @@ -141,6 +141,6 @@ def init(context): global config Puppet.az, Puppet.db, log, config = context Puppet.log = log.getChild("puppet") - localpart = config.get("bridge.alias_template", "telegram_{}").format("(.+)") + localpart = config.get("bridge.username_template", "telegram_{userid}").format(userid="(.+)") hs = config["homeserver"]["domain"] Puppet.mxid_regex = re.compile(f"@{localpart}:{hs}")