Add option to bridge notices and command to get relaybot info
This commit is contained in:
@@ -67,6 +67,8 @@ bridge:
|
||||
# Show message editing as a reply to the original message.
|
||||
# If this is false, message edits are not shown at all, as Matrix does not support editing yet.
|
||||
edits_as_replies: False
|
||||
# Whether or not Matrix bot messages (type m.notice) should be bridged.
|
||||
bridge_notices: False
|
||||
|
||||
# The prefix for commands. Only required in non-management rooms.
|
||||
command_prefix: "!tg"
|
||||
|
||||
@@ -32,6 +32,21 @@ async def ping(evt):
|
||||
return await evt.reply("You're not logged in.")
|
||||
|
||||
|
||||
@command_handler()
|
||||
async def ping_bot(evt):
|
||||
if not evt.tgbot:
|
||||
return await evt.reply("Telegram message relay bot not configured.")
|
||||
bot_info = await evt.tgbot.client.get_me()
|
||||
localpart = evt.config.get("bridge.username_template", "telegram_{userid}").format(
|
||||
userid=bot_info.id)
|
||||
hs = evt.config["homeserver"]["domain"]
|
||||
mxid = f"@{localpart}:{hs}"
|
||||
displayname = bot_info.first_name
|
||||
return await evt.reply(f"Telegram message relay bot is active: "
|
||||
+ f"[{displayname}](https://matrix.to/#/{mxid}) (ID {bot_info.id})\n\n"
|
||||
+ f"To use the bot, simply invite it to a portal room.")
|
||||
|
||||
|
||||
@command_handler(needs_auth=False, management_only=True)
|
||||
def register(evt):
|
||||
return evt.reply("Not yet implemented.")
|
||||
|
||||
@@ -45,6 +45,8 @@ class CommandEvent:
|
||||
self.az = handler.az
|
||||
self.log = handler.log
|
||||
self.loop = handler.loop
|
||||
self.tgbot = handler.tgbot
|
||||
self.config = handler.config
|
||||
self.command_prefix = handler.command_prefix
|
||||
self.room_id = room
|
||||
self.sender = sender
|
||||
@@ -87,7 +89,7 @@ class CommandHandler:
|
||||
log = logging.getLogger("mau.commands")
|
||||
|
||||
def __init__(self, context):
|
||||
self.az, self.db, self.config, self.loop, _ = context
|
||||
self.az, self.db, self.config, self.loop, self.tgbot = context
|
||||
self.command_prefix = self.config["bridge.command_prefix"]
|
||||
|
||||
# region Utility functions for handling commands
|
||||
|
||||
@@ -65,6 +65,7 @@ def help(evt):
|
||||
`channel` (defaults to `group`).
|
||||
|
||||
#### Portal management
|
||||
**ping-bot** - Get info of the message relay Telegram bot.
|
||||
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
||||
**invite-link** - Get a Telegram invite link to the current chat.
|
||||
**delete-portal** - Forget the current portal room. Only works for group chats; to delete
|
||||
|
||||
@@ -45,6 +45,7 @@ class Portal:
|
||||
db = None
|
||||
az = None
|
||||
bot = None
|
||||
bridge_notices = False
|
||||
by_mxid = {}
|
||||
by_tgid = {}
|
||||
|
||||
@@ -490,7 +491,7 @@ class Portal:
|
||||
f"<{sender.displayname}> {message['formatted_body']}"
|
||||
message["body"] = f"<{sender.displayname}> {message['body']}"
|
||||
|
||||
if type == "m.text":
|
||||
if type == "m.text" or (self.bridge_notices and type == "m.notice"):
|
||||
if "format" in message and message["format"] == "org.matrix.custom.html":
|
||||
message, entities = formatter.matrix_to_telegram(message["formatted_body"])
|
||||
response = await client.send_message(self.peer, message, entities=entities,
|
||||
@@ -1092,3 +1093,4 @@ class Portal:
|
||||
def init(context):
|
||||
global config
|
||||
Portal.az, Portal.db, config, _, Portal.bot = context
|
||||
Portal.bridge_notices = config["bridge.bridge_notices"]
|
||||
|
||||
Reference in New Issue
Block a user