From 87dc1a44b27f7828d0915886d7374d4252ee4fb7 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 15 Jul 2018 16:03:46 +0300 Subject: [PATCH] Add bot_avatar config field --- example-config.yaml | 7 +++++-- mautrix_telegram/config.py | 3 ++- mautrix_telegram/context.py | 9 +++------ mautrix_telegram/matrix.py | 9 +++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 69c832f3..9fa15ad6 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -41,14 +41,17 @@ appservice: # The prefix to use in the provisioning API endpoints. prefix: /_matrix/provision/v1 # The shared secret to authorize users of the API. - # If you leave the default token, a random token will be generated and saved at startup. - shared_secret: "Very secret shared secret" + # Set to "generate" to generate and save a new token. + shared_secret: generate # The unique ID of this appservice. id: telegram # Username of the appservice bot. bot_username: telegrambot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. bot_displayname: Telegram bridge bot + bot_avatar: mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. as_token: "This value is generated when generating the registration" diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 77cc6bfb..1dad0fb4 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -162,12 +162,13 @@ class Config(DictWithRecursion): copy("appservice.provisioning.enabled") copy("appservice.provisioning.prefix") copy("appservice.provisioning.shared_secret") - if base["appservice.provisioning.shared_secret"] == "Very secret shared secret": + if base["appservice.provisioning.shared_secret"] == "generate": base["appservice.provisioning.shared_secret"] = self._new_token() copy("appservice.id") copy("appservice.bot_username") copy("appservice.bot_displayname") + copy("appservice.bot_avatar") copy("appservice.as_token") copy("appservice.hs_token") diff --git a/mautrix_telegram/context.py b/mautrix_telegram/context.py index ad48d7e4..5b0b6193 100644 --- a/mautrix_telegram/context.py +++ b/mautrix_telegram/context.py @@ -14,13 +14,13 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from typing import Tuple import asyncio from sqlalchemy.orm import scoped_session from alchemysession import AlchemySessionContainer from mautrix_appservice import AppService - class Context: def __init__(self, az, db, config, loop, bot, mx, session_container, public_website, provisioning_api): @@ -38,10 +38,7 @@ class Context: self.session_container = session_container # type: AlchemySessionContainer self.public_website = public_website # type: PublicBridgeWebsite self.provisioning_api = provisioning_api # type: ProvisioningAPI + self.t = (self.az, self.db, self.config, self.loop, self.bot) def __iter__(self): - yield self.az - yield self.db - yield self.config - yield self.loop - yield self.bot + return iter(self.t) diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py index dc9e3f75..49dfa649 100644 --- a/mautrix_telegram/matrix.py +++ b/mautrix_telegram/matrix.py @@ -36,8 +36,13 @@ class MatrixHandler: self.az.matrix_event_handler(self.handle_event) async def init_as_bot(self): - await self.az.intent.set_display_name( - self.config.get("appservice.bot_displayname", "Telegram bridge bot")) + displayname = self.config["appservice.bot_displayname"] + if displayname: + await self.az.intent.set_display_name(displayname if displayname != "remove" else "") + + avatar = self.config["appservice.bot_avatar"] + if avatar: + await self.az.intent.set_avatar(avatar if avatar != "remove" else "") async def handle_puppet_invite(self, room, puppet, inviter): self.log.debug(f"{inviter} invited puppet for {puppet.tgid} to {room}")