Use named format parameter for alias/name templates
This commit is contained in:
+6
-6
@@ -30,14 +30,14 @@ appservice:
|
|||||||
# Bridge config
|
# Bridge config
|
||||||
bridge:
|
bridge:
|
||||||
# Localpart template of MXIDs for Telegram users.
|
# Localpart template of MXIDs for Telegram users.
|
||||||
# {} is replaced with the user ID of the Telegram user.
|
# {userid} is replaced with the user ID of the Telegram user.
|
||||||
username_template: "telegram_{}"
|
username_template: "telegram_{userid}"
|
||||||
# Localpart template of room aliases for Telegram portal rooms.
|
# 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/{} )
|
# {groupname} is replaced with the name part of the public channel/group invite link ( https://t.me/{} )
|
||||||
alias_template: "telegram_{}"
|
alias_template: "telegram_{groupname}"
|
||||||
# Displayname template for Telegram users.
|
# Displayname template for Telegram users.
|
||||||
# {} is replaced with the display name of the Telegram user.
|
# {displayname} is replaced with the display name of the Telegram user.
|
||||||
displayname_template: "{} (Telegram)"
|
displayname_template: "{displayname} (Telegram)"
|
||||||
|
|
||||||
# Set the preferred order of user identifiers which to use in the Matrix puppet display name.
|
# 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.
|
# In the (hopefully unlikely) scenario that none of the given keys are found, the numeric user ID is used.
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ class Config(DictWithRecursion):
|
|||||||
def generate_registration(self):
|
def generate_registration(self):
|
||||||
homeserver = self["homeserver.domain"]
|
homeserver = self["homeserver.domain"]
|
||||||
|
|
||||||
username_format = self.get("bridge.username_template", "telegram_{}").format(".+")
|
username_format = self.get("bridge.username_template", "telegram_{userid}").format(userid=".+")
|
||||||
alias_format = self.get("bridge.alias_template", "telegram_{}").format(".+")
|
alias_format = self.get("bridge.alias_template", "telegram_{groupname}").format(groupname=".+")
|
||||||
|
|
||||||
self.set("appservice.as_token", self._new_token())
|
self.set("appservice.as_token", self._new_token())
|
||||||
self.set("appservice.hs_token", self._new_token())
|
self.set("appservice.hs_token", self._new_token())
|
||||||
@@ -100,7 +100,7 @@ class Config(DictWithRecursion):
|
|||||||
}],
|
}],
|
||||||
"aliases": [{
|
"aliases": [{
|
||||||
"exclusive": True,
|
"exclusive": True,
|
||||||
"regex": f"@{alias_format}:{homeserver}"
|
"regex": f"#{alias_format}:{homeserver}"
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
"url": f"{appservice.get('protocol')}://{appservice.get('hostname')}:{appservice.get('port')}",
|
"url": f"{appservice.get('protocol')}://{appservice.get('hostname')}:{appservice.get('port')}",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class MatrixHandler:
|
|||||||
self.log = log.getChild("mx")
|
self.log = log.getChild("mx")
|
||||||
self.commands = CommandHandler(context)
|
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"]
|
hs = self.config["homeserver"]["domain"]
|
||||||
self.localpart_regex = re.compile(f"@{alias_format}:{hs}")
|
self.localpart_regex = re.compile(f"@{alias_format}:{hs}")
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Puppet:
|
|||||||
def __init__(self, id=None, username=None, displayname=None, photo_id=None):
|
def __init__(self, id=None, username=None, displayname=None, photo_id=None):
|
||||||
self.id = id
|
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"]
|
hs = config["homeserver"]["domain"]
|
||||||
self.mxid = f"@{self.localpart}:{hs}"
|
self.mxid = f"@{self.localpart}:{hs}"
|
||||||
self.username = username
|
self.username = username
|
||||||
@@ -75,7 +75,7 @@ class Puppet:
|
|||||||
|
|
||||||
if not format:
|
if not format:
|
||||||
return name
|
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):
|
def update_info(self, source, info):
|
||||||
changed = False
|
changed = False
|
||||||
@@ -141,6 +141,6 @@ def init(context):
|
|||||||
global config
|
global config
|
||||||
Puppet.az, Puppet.db, log, config = context
|
Puppet.az, Puppet.db, log, config = context
|
||||||
Puppet.log = log.getChild("puppet")
|
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"]
|
hs = config["homeserver"]["domain"]
|
||||||
Puppet.mxid_regex = re.compile(f"@{localpart}:{hs}")
|
Puppet.mxid_regex = re.compile(f"@{localpart}:{hs}")
|
||||||
|
|||||||
Reference in New Issue
Block a user