Compare commits

...

11 Commits

Author SHA1 Message Date
Tulir Asokan 92a6afdd2f Hacky fix for null m.relates_to's and bump version to 0.5.2 2019-05-25 16:03:15 +03:00
Tulir Asokan 41b8292f25 Bump version to 0.5.1 2019-03-21 15:32:37 +02:00
Tulir Asokan 366b95c8e8 Fix Python 3.5 compatibility 2019-03-21 14:42:18 +02:00
Tulir Asokan fecf068455 Revert switching to @as_declarative for SQLAlchemy base class
This reverts commit 1da1133934 and a part of 2cf9dcafd9
2019-03-21 13:48:53 +02:00
Tulir Asokan 1da1133934 Fix reference to old BaseBase class in dbms migration script 2019-03-21 12:10:43 +02:00
Tulir Asokan c4ac84c1a1 Bump version to 0.5.0 2019-03-19 20:08:24 +02:00
Tulir Asokan 2cf9dcafd9 Update copyright year and fix minor lint problems 2019-03-19 18:30:36 +02:00
Tulir Asokan 784abcba4e Update native deps in dockerfile and increase minimum alchemysession version 2019-03-19 18:30:36 +02:00
Tulir Asokan aaa44fb7aa Update ROADMAP.md 2019-03-17 15:47:29 +02:00
Tulir Asokan f7a4a23045 Don't add reply fallback to caption when caption is separate event. Fixes #285 2019-03-16 21:59:37 +02:00
Tulir Asokan 7e3c892ff6 Stop using rawgit in public website. Fixes #289 2019-03-16 18:05:12 +02:00
57 changed files with 157 additions and 158 deletions
+16 -11
View File
@@ -15,18 +15,23 @@ RUN apk add --no-cache \
py3-sqlalchemy \ py3-sqlalchemy \
py3-markdown \ py3-markdown \
py3-psycopg2 \ py3-psycopg2 \
# Not yet in stable repos:
#py3-ruamel \
# Indirect dependencies # Indirect dependencies
py3-numpy \ #commonmark
py3-asn1crypto \ py3-future \
py3-future \ #alembic
py3-markupsafe \ py3-mako \
py3-mako \ py3-dateutil \
py3-decorator \ py3-markupsafe \
py3-dateutil \ #moviepy
py3-idna \ py3-decorator \
py3-six \ #py3-tqdm \
py3-asn1 \ py3-requests \
py3-rsa \ #imageio
py3-numpy \
#telethon
py3-rsa \
# Other dependencies # Other dependencies
python3-dev \ python3-dev \
build-base \ build-base \
+6
View File
@@ -21,6 +21,10 @@
* [ ] ‡ Changes to displayname/avatar * [ ] ‡ Changes to displayname/avatar
* Telegram → Matrix * Telegram → Matrix
* [x] Message content (text, formatting, files, etc..) * [x] Message content (text, formatting, files, etc..)
* [ ] Advanced message content/media
* [x] Polls
* [x] Games
* [ ] Buttons
* [x] Message deletions * [x] Message deletions
* [x] Message edits * [x] Message edits
* [ ] Message history * [ ] Message history
@@ -48,6 +52,8 @@
* [x] Option to use bot to relay messages for unauthenticated Matrix users * [x] Option to use bot to relay messages for unauthenticated Matrix users
* [x] Option to use own Matrix account for messages sent from other Telegram clients * [x] Option to use own Matrix account for messages sent from other Telegram clients
* [ ] ‡ Calls (hard, not yet supported by Telethon) * [ ] ‡ Calls (hard, not yet supported by Telethon)
* [ ] ‡ Secret chats (not yet supported by Telethon)
* [ ] ‡ E2EE in Matrix rooms (not yet supported
† Information not automatically sent from source, i.e. implementation may not be possible † Information not automatically sent from source, i.e. implementation may not be possible
‡ Maybe, i.e. this feature may or may not be implemented at some point ‡ Maybe, i.e. this feature may or may not be implemented at some point
+1 -1
View File
@@ -1,2 +1,2 @@
__version__ = "0.5.0rc4" __version__ = "0.5.2"
__author__ = "Tulir Asokan <tulir@maunium.net>" __author__ = "Tulir Asokan <tulir@maunium.net>"
+3 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -100,7 +100,6 @@ appserv = AppService(config["homeserver.address"], config["homeserver.domain"],
}) })
bot = init_bot(config) bot = init_bot(config)
context = Context(appserv, config, loop, session_container, bot) context = Context(appserv, config, loop, session_container, bot)
context.mx = MatrixHandler(context)
if config["appservice.public.enabled"]: if config["appservice.public.enabled"]:
public_website = PublicBridgeWebsite(loop) public_website = PublicBridgeWebsite(loop)
@@ -113,6 +112,8 @@ if config["appservice.provisioning.enabled"]:
provisioning_api.app) provisioning_api.app)
context.provisioning_api = provisioning_api context.provisioning_api = provisioning_api
context.mx = MatrixHandler(context)
with appserv.run(config["appservice.hostname"], config["appservice.port"]) as start: with appserv.run(config["appservice.hostname"], config["appservice.port"]) as start:
start_ts = time() start_ts = time()
init_db(db_engine) init_db(db_engine)
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+15 -36
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -15,18 +15,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""This module contains classes handling commands issued by Matrix users.""" """This module contains classes handling commands issued by Matrix users."""
from typing import ( from typing import Awaitable, Callable, Dict, List, NamedTuple, Optional
Any,
Awaitable,
Callable,
Coroutine,
Dict,
List,
NamedTuple,
Optional,
Union,
NewType,
)
import logging import logging
import traceback import traceback
@@ -93,6 +82,7 @@ class CommandEvent:
is_portal: Determines whether the room in which the command was issued is_portal: Determines whether the room in which the command was issued
is a portal. is a portal.
""" """
def __init__(self, processor: 'CommandProcessor', room: MatrixRoomID, event: MatrixEventID, def __init__(self, processor: 'CommandProcessor', room: MatrixRoomID, event: MatrixEventID,
sender: u.User, command: str, args: List[str], is_management: bool, sender: u.User, command: str, args: List[str], is_management: bool,
is_portal: bool) -> None: is_portal: bool) -> None:
@@ -111,12 +101,8 @@ class CommandEvent:
self.is_management = is_management self.is_management = is_management
self.is_portal = is_portal self.is_portal = is_portal
def reply( def reply(self, message: str, allow_html: bool = False, render_markdown: bool = True
self, ) -> Awaitable[Dict]:
message: str,
allow_html: bool = False,
render_markdown: bool = True,
) -> Awaitable[Dict]:
"""Write a reply to the room in which the command was issued. """Write a reply to the room in which the command was issued.
Replaces occurences of "$cmdprefix" in the message with the command Replaces occurences of "$cmdprefix" in the message with the command
@@ -136,9 +122,8 @@ class CommandEvent:
Handler for the message sending function. Handler for the message sending function.
""" """
message_cmd = self._replace_command_prefix(message) message_cmd = self._replace_command_prefix(message)
html = self._render_message( html = self._render_message(message_cmd, allow_html=allow_html,
message_cmd, allow_html=allow_html, render_markdown=render_markdown render_markdown=render_markdown)
)
return self.az.intent.send_notice(self.room_id, message_cmd, html=html) return self.az.intent.send_notice(self.room_id, message_cmd, html=html)
@@ -153,9 +138,8 @@ class CommandEvent:
) )
return message.replace("$cmdprefix", self.command_prefix) return message.replace("$cmdprefix", self.command_prefix)
def _render_message( @staticmethod
self, message: str, allow_html: bool, render_markdown: bool def _render_message(message: str, allow_html: bool, render_markdown: bool) -> Optional[str]:
) -> Optional[str]:
"""Renders the message as HTML. """Renders the message as HTML.
Args: Args:
@@ -194,6 +178,7 @@ class CommandHandler:
name: The name of this command. name: The name of this command.
help_section: Section of the help in which this command will appear. help_section: Section of the help in which this command will appear.
""" """
def __init__(self, handler: Callable[[CommandEvent], Awaitable[Dict]], needs_auth: bool, def __init__(self, handler: Callable[[CommandEvent], Awaitable[Dict]], needs_auth: bool,
needs_puppeting: bool, needs_matrix_puppeting: bool, needs_admin: bool, needs_puppeting: bool, needs_matrix_puppeting: bool, needs_admin: bool,
management_only: bool, name: str, help_text: str, help_args: str, management_only: bool, name: str, help_text: str, help_args: str,
@@ -254,7 +239,7 @@ class CommandHandler:
Args: Args:
is_management: If the room in which the command will be issued is a is_management: If the room in which the command will be issued is a
management room. management room.
puppet_whitelited: If the connected Telegram account puppet is puppet_whitelisted: If the connected Telegram account puppet is
allowed to issue the command. allowed to issue the command.
matrix_puppet_whitelisted: If the connected Matrix account puppet is matrix_puppet_whitelisted: If the connected Matrix account puppet is
allowed to issue the command. allowed to issue the command.
@@ -300,18 +285,12 @@ class CommandHandler:
def command_handler(_func: Optional[Callable[[CommandEvent], Awaitable[Dict]]] = None, *, def command_handler(_func: Optional[Callable[[CommandEvent], Awaitable[Dict]]] = None, *,
needs_auth: bool = True, needs_auth: bool = True, needs_puppeting: bool = True,
needs_puppeting: bool = True, needs_matrix_puppeting: bool = False, needs_admin: bool = False,
needs_matrix_puppeting: bool = False, management_only: bool = False, name: Optional[str] = None,
needs_admin: bool = False, help_text: str = "", help_args: str = "", help_section: HelpSection = None
management_only: bool = False,
name: Optional[str] = None,
help_text: str = "",
help_args: str = "",
help_section: HelpSection = None
) -> Callable[[Callable[[CommandEvent], Awaitable[Optional[Dict]]]], ) -> Callable[[Callable[[CommandEvent], Awaitable[Optional[Dict]]]],
CommandHandler]: CommandHandler]:
def decorator(func: Callable[[CommandEvent], Awaitable[Optional[Dict]]]) -> CommandHandler: def decorator(func: Callable[[CommandEvent], Awaitable[Optional[Dict]]]) -> CommandHandler:
actual_name = name or func.__name__.replace("_", "-") actual_name = name or func.__name__.replace("_", "-")
handler = CommandHandler(func, needs_auth, needs_puppeting, needs_matrix_puppeting, handler = CommandHandler(func, needs_auth, needs_puppeting, needs_matrix_puppeting,
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+3 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -65,8 +65,8 @@ def _get_management_status(evt: CommandEvent) -> str:
return "**This is not a management room**: you must prefix commands with `$cmdprefix`." return "**This is not a management room**: you must prefix commands with `$cmdprefix`."
@command_handler(needs_auth=False, needs_puppeting=False, @command_handler(name="help", needs_auth=False, needs_puppeting=False,
help_section=SECTION_GENERAL, help_section=SECTION_GENERAL,
help_text="Show this help message.") help_text="Show this help message.")
async def help(evt: CommandEvent) -> Optional[Dict]: async def help_cmd(evt: CommandEvent) -> Optional[Dict]:
return await evt.reply(_get_management_status(evt) + "\n" + await _get_help_text(evt)) return await evt.reply(_get_management_status(evt) + "\n" + await _get_help_text(evt))
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+3 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -18,9 +18,10 @@ from typing import Dict, Awaitable
from io import StringIO from io import StringIO
from ...config import yaml from ...config import yaml
from ... import portal as po, user as u, util from ... import portal as po, util
from .. import command_handler, CommandEvent, SECTION_PORTAL_MANAGEMENT from .. import command_handler, CommandEvent, SECTION_PORTAL_MANAGEMENT
@command_handler(help_section=SECTION_PORTAL_MANAGEMENT, @command_handler(help_section=SECTION_PORTAL_MANAGEMENT,
help_text="View or change per-portal settings.", help_text="View or change per-portal settings.",
help_args="<`help`|_subcommand_> [...]") help_args="<`help`|_subcommand_> [...]")
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -17,6 +17,7 @@
from typing import Dict from typing import Dict
from ... import portal as po from ... import portal as po
from ...types import TelegramID
from .. import command_handler, CommandEvent, SECTION_CREATING_PORTALS from .. import command_handler, CommandEvent, SECTION_CREATING_PORTALS
from .util import user_has_power_level, get_initial_state from .util import user_has_power_level, get_initial_state
@@ -50,7 +51,8 @@ async def create(evt: CommandEvent) -> Dict:
"group": "chat", "group": "chat",
}[type] }[type]
portal = po.Portal(tgid=None, mxid=evt.room_id, title=title, about=about, peer_type=type) portal = po.Portal(tgid=TelegramID(0), peer_type=type,
mxid=evt.room_id, title=title, about=about)
try: try:
await portal.create_telegram_chat(evt.sender, supergroup=supergroup) await portal.create_telegram_chat(evt.sender, supergroup=supergroup)
except ValueError as e: except ValueError as e:
+13 -13
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -46,11 +46,11 @@ async def filter_mode(evt: CommandEvent) -> Dict:
"`!filter blacklist <chat ID>`.") "`!filter blacklist <chat ID>`.")
@command_handler(needs_admin=True, @command_handler(name="filter", needs_admin=True,
help_section=SECTION_ADMIN, help_section=SECTION_ADMIN,
help_args="<`whitelist`|`blacklist`> <_chat ID_>", help_args="<`whitelist`|`blacklist`> <_chat ID_>",
help_text="Allow or disallow bridging a specific chat.") help_text="Allow or disallow bridging a specific chat.")
async def filter(evt: CommandEvent) -> Optional[Dict]: async def edit_filter(evt: CommandEvent) -> Optional[Dict]:
try: try:
action = evt.args[0] action = evt.args[0]
if action not in ("whitelist", "blacklist", "add", "remove"): if action not in ("whitelist", "blacklist", "add", "remove"):
@@ -58,11 +58,11 @@ async def filter(evt: CommandEvent) -> Optional[Dict]:
id_str = evt.args[1] id_str = evt.args[1]
if id_str.startswith("-100"): if id_str.startswith("-100"):
id = int(id_str[4:]) filter_id = int(id_str[4:])
elif id_str.startswith("-"): elif id_str.startswith("-"):
id = int(id_str[1:]) filter_id = int(id_str[1:])
else: else:
id = int(id_str) filter_id = int(id_str)
except (IndexError, ValueError): except (IndexError, ValueError):
return await evt.reply("**Usage:** `$cmdprefix+sp filter <whitelist/blacklist> <chat ID>`") return await evt.reply("**Usage:** `$cmdprefix+sp filter <whitelist/blacklist> <chat ID>`")
@@ -70,26 +70,26 @@ async def filter(evt: CommandEvent) -> Optional[Dict]:
if mode not in ("blacklist", "whitelist"): if mode not in ("blacklist", "whitelist"):
return await evt.reply(f"Unknown filter mode \"{mode}\". Please fix the bridge config.") return await evt.reply(f"Unknown filter mode \"{mode}\". Please fix the bridge config.")
list = evt.config["bridge.filter.list"] filter_id_list = evt.config["bridge.filter.list"]
if action in ("blacklist", "whitelist"): if action in ("blacklist", "whitelist"):
action = "add" if mode == action else "remove" action = "add" if mode == action else "remove"
def save() -> None: def save() -> None:
evt.config["bridge.filter.list"] = list evt.config["bridge.filter.list"] = filter_id_list
evt.config.save() evt.config.save()
po.Portal.filter_list = list po.Portal.filter_list = filter_id_list
if action == "add": if action == "add":
if id in list: if filter_id in filter_id_list:
return await evt.reply(f"That chat is already {mode}ed.") return await evt.reply(f"That chat is already {mode}ed.")
list.append(id) filter_id_list.append(filter_id)
save() save()
return await evt.reply(f"Chat ID added to {mode}.") return await evt.reply(f"Chat ID added to {mode}.")
elif action == "remove": elif action == "remove":
if id not in list: if filter_id not in filter_id_list:
return await evt.reply(f"That chat is not {mode}ed.") return await evt.reply(f"That chat is not {mode}ed.")
list.remove(id) filter_id_list.remove(filter_id)
save() save()
return await evt.reply(f"Chat ID removed from {mode}.") return await evt.reply(f"Chat ID removed from {mode}.")
return None return None
+3 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -38,10 +38,10 @@ async def sync_state(evt: CommandEvent) -> Dict:
await evt.reply("Synchronization complete") await evt.reply("Synchronization complete")
@command_handler(needs_admin=False, needs_puppeting=False, needs_auth=False, @command_handler(name="id", needs_admin=False, needs_puppeting=False, needs_auth=False,
help_section=SECTION_MISC, help_section=SECTION_MISC,
help_text="Get the ID of the Telegram chat where this room is bridged.") help_text="Get the ID of the Telegram chat where this room is bridged.")
async def id(evt: CommandEvent) -> Dict: async def get_id(evt: CommandEvent) -> Dict:
portal = po.Portal.get_by_mxid(evt.room_id) portal = po.Portal.get_by_mxid(evt.room_id)
if not portal: if not portal:
return await evt.reply("This is not a portal room.") return await evt.reply("This is not a portal room.")
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -55,5 +55,4 @@ class BaseBase:
with self.db.begin() as conn: with self.db.begin() as conn:
conn.execute(self.t.delete().where(self._edit_identity)) conn.execute(self.t.delete().where(self._edit_identity))
Base = declarative_base(cls=BaseBase) Base = declarative_base(cls=BaseBase)
+5 -5
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -29,16 +29,16 @@ class BotChat(Base):
type = Column(String, nullable=False) type = Column(String, nullable=False)
@classmethod @classmethod
def delete(cls, id: TelegramID) -> None: def delete(cls, chat_id: TelegramID) -> None:
with cls.db.begin() as conn: with cls.db.begin() as conn:
conn.execute(cls.t.delete().where(cls.c.id == id)) conn.execute(cls.t.delete().where(cls.c.id == chat_id))
@classmethod @classmethod
def all(cls) -> Iterable['BotChat']: def all(cls) -> Iterable['BotChat']:
rows = cls.db.execute(cls.t.select()) rows = cls.db.execute(cls.t.select())
for row in rows: for row in rows:
id, type = row chat_id, chat_type = row
yield cls(id=id, type=type) yield cls(id=chat_id, type=chat_type)
def insert(self) -> None: def insert(self) -> None:
with self.db.begin() as conn: with self.db.begin() as conn:
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+5 -5
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -35,14 +35,14 @@ class TelegramFile(Base):
thumbnail = None # type: Optional[TelegramFile] thumbnail = None # type: Optional[TelegramFile]
@classmethod @classmethod
def get(cls, id: str) -> Optional['TelegramFile']: def get(cls, loc_id: str) -> Optional['TelegramFile']:
rows = cls.db.execute(cls.t.select().where(cls.c.id == id)) rows = cls.db.execute(cls.t.select().where(cls.c.id == loc_id))
try: try:
id, mxc, mime, conv, ts, s, w, h, thumb_id = next(rows) loc_id, mxc, mime, conv, ts, s, w, h, thumb_id = next(rows)
thumb = None thumb = None
if thumb_id: if thumb_id:
thumb = cls.get(thumb_id) thumb = cls.get(thumb_id)
return cls(id=id, mxc=mxc, mime_type=mime, was_converted=conv, timestamp=ts, return cls(id=loc_id, mxc=mxc, mime_type=mime, was_converted=conv, timestamp=ts,
size=s, width=w, height=h, thumbnail_id=thumb_id, thumbnail=thumb) size=s, width=w, height=h, thumbnail_id=thumb_id, thumbnail=thumb)
except StopIteration: except StopIteration:
return None return None
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -36,7 +36,7 @@ should_bridge_plaintext_highlights = False # type: bool
command_regex = re.compile(r"^!([A-Za-z0-9@]+)") # type: Pattern command_regex = re.compile(r"^!([A-Za-z0-9@]+)") # type: Pattern
not_command_regex = re.compile(r"^\\(![A-Za-z0-9@]+)") # type: Pattern not_command_regex = re.compile(r"^\\(![A-Za-z0-9@]+)") # type: Pattern
plain_mention_regex = None # type: Pattern plain_mention_regex = None # type: Optional[Pattern]
def plain_mention_to_html(match: Match) -> str: def plain_mention_to_html(match: Match) -> str:
@@ -147,5 +147,5 @@ def init_mx(context: "Context") -> None:
config = context.config config = context.config
dn_template = config.get("bridge.displayname_template", "{displayname} (Telegram)") dn_template = config.get("bridge.displayname_template", "{displayname} (Telegram)")
dn_template = re.escape(dn_template).replace(re.escape("{displayname}"), "[^>]+") dn_template = re.escape(dn_template).replace(re.escape("{displayname}"), "[^>]+")
plain_mention_regex = re.compile(f"(\s|^)({dn_template})") plain_mention_regex = re.compile(f"^({dn_template})")
should_bridge_plaintext_highlights = config["bridge.plaintext_highlights"] or False should_bridge_plaintext_highlights = config["bridge.plaintext_highlights"] or False
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+8 -9
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -44,7 +44,6 @@ try:
except ImportError: except ImportError:
htmldiff = None # type: ignore htmldiff = None # type: ignore
log = logging.getLogger("mau.fmt.tg") # type: logging.Logger log = logging.getLogger("mau.fmt.tg") # type: logging.Logger
should_highlight_edits = False # type: bool should_highlight_edits = False # type: bool
@@ -71,7 +70,7 @@ async def _add_forward_header(source, text: str, html: Optional[str],
html = escape(text) html = escape(text)
fwd_from_html, fwd_from_text = None, None fwd_from_html, fwd_from_text = None, None
if fwd_from.from_id: if fwd_from.from_id:
user = u.User.get_by_tgid(fwd_from.from_id) user = u.User.get_by_tgid(TelegramID(fwd_from.from_id))
if user: if user:
fwd_from_text = user.displayname or user.mxid fwd_from_text = user.displayname or user.mxid
fwd_from_html = f"<a href='https://matrix.to/#/{user.mxid}'>{fwd_from_text}</a>" fwd_from_html = f"<a href='https://matrix.to/#/{user.mxid}'>{fwd_from_text}</a>"
@@ -193,8 +192,8 @@ async def telegram_to_matrix(evt: Message, source: "AbstractUser",
main_intent: Optional[IntentAPI] = None, main_intent: Optional[IntentAPI] = None,
is_edit: bool = False, prefix_text: Optional[str] = None, is_edit: bool = False, prefix_text: Optional[str] = None,
prefix_html: Optional[str] = None, override_text: str = None, prefix_html: Optional[str] = None, override_text: str = None,
override_entities: List[TypeMessageEntity] = None override_entities: List[TypeMessageEntity] = None,
) -> Tuple[str, str, Dict]: no_reply_fallback: bool = False) -> Tuple[str, str, Dict]:
text = add_surrogates(override_text or evt.message) text = add_surrogates(override_text or evt.message)
entities = override_entities or evt.entities entities = override_entities or evt.entities
html = _telegram_entities_to_matrix_catch(text, entities) if entities else None html = _telegram_entities_to_matrix_catch(text, entities) if entities else None
@@ -208,7 +207,7 @@ async def telegram_to_matrix(evt: Message, source: "AbstractUser",
if evt.fwd_from: if evt.fwd_from:
text, html = await _add_forward_header(source, text, html, evt.fwd_from) text, html = await _add_forward_header(source, text, html, evt.fwd_from)
if evt.reply_to_msg_id: if evt.reply_to_msg_id and not no_reply_fallback:
text, html = await _add_reply_header(source, text, html, evt, relates_to, main_intent, text, html = await _add_reply_header(source, text, html, evt, relates_to, main_intent,
is_edit) is_edit)
@@ -258,9 +257,9 @@ def _telegram_entities_to_matrix(text: str, entities: List[TypeMessageEntity]) -
elif entity_type == MessageEntityItalic: elif entity_type == MessageEntityItalic:
html.append(f"<em>{entity_text}</em>") html.append(f"<em>{entity_text}</em>")
elif entity_type == MessageEntityCode: elif entity_type == MessageEntityCode:
html.append(f"<pre><code>{entity_text}</code></pre>" html.append(("<pre><code>{entity_text}</code></pre>"
if "\n" in entity_text if "\n" in entity_text
else f"<code>{entity_text}</code>") else "<code>{entity_text}</code>").format(entity_text=entity_text))
elif entity_type == MessageEntityPre: elif entity_type == MessageEntityPre:
skip_entity = _parse_pre(html, entity_text, entity.language) skip_entity = _parse_pre(html, entity_text, entity.language)
elif entity_type == MessageEntityMention: elif entity_type == MessageEntityMention:
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+7 -6
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1258,8 +1258,8 @@ class Portal:
invites = await self._get_telegram_users_in_matrix_room() invites = await self._get_telegram_users_in_matrix_room()
if len(invites) < 2: if len(invites) < 2:
raise ValueError("Not enough Telegram users to create a chat") raise ValueError("Not enough Telegram users to create a chat. "
"Invite more Telegram ghost users to the room, such as the relaybot.")
if self.peer_type == "chat": if self.peer_type == "chat":
response = await source.client(CreateChatRequest(title=self.title, users=invites)) response = await source.client(CreateChatRequest(title=self.title, users=invites))
entity = response.chats[0] entity = response.chats[0]
@@ -1346,9 +1346,10 @@ class Portal:
relates_to=relates_to, timestamp=evt.date, relates_to=relates_to, timestamp=evt.date,
external_url=self.get_external_url(evt)) external_url=self.get_external_url(evt))
if evt.message: if evt.message:
text, html, _ = await formatter.telegram_to_matrix(evt, source, self.main_intent) text, html, _ = await formatter.telegram_to_matrix(evt, source, self.main_intent,
await intent.send_text(self.mxid, text, html=html, timestamp=evt.date, no_reply_fallback=True)
external_url=self.get_external_url(evt)) result = await intent.send_text(self.mxid, text, html=html, timestamp=evt.date,
external_url=self.get_external_url(evt))
return result return result
@staticmethod @staticmethod
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+2 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -65,7 +65,7 @@ class User(AbstractUser):
self.db_portals = db_portals or [] self.db_portals = db_portals or []
self._db_instance = db_instance # type: Optional[DBUser] self._db_instance = db_instance # type: Optional[DBUser]
self.command_status = None # type: Dict self.command_status = None # type: Optional[Dict]
(self.relaybot_whitelisted, (self.relaybot_whitelisted,
self.whitelisted, self.whitelisted,
+6 -4
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -147,9 +147,11 @@ async def transfer_thumbnail_to_matrix(client: MautrixTelegramClient, intent: In
transfer_locks = {} # type: Dict[str, asyncio.Lock] transfer_locks = {} # type: Dict[str, asyncio.Lock]
TypeThumbnail = Optional[Union[TypeLocation, TypePhotoSize]]
async def transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI, async def transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI,
location: TypeLocation, thumbnail: Optional[Union[TypeLocation, TypePhotoSize]] = None, location: TypeLocation, thumbnail: TypeThumbnail = None,
is_sticker: bool = False) -> Optional[DBTelegramFile]: is_sticker: bool = False) -> Optional[DBTelegramFile]:
location_id = _location_to_id(location) location_id = _location_to_id(location)
if not location_id: if not location_id:
@@ -171,8 +173,8 @@ async def transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentA
async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI, async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI,
loc_id: str, location: TypeLocation, loc_id: str, location: TypeLocation,
thumbnail: Optional[Union[TypeLocation, TypePhotoSize]], thumbnail: TypeThumbnail, is_sticker: bool
is_sticker: bool) -> Optional[DBTelegramFile]: ) -> Optional[DBTelegramFile]:
db_file = DBTelegramFile.get(loc_id) db_file = DBTelegramFile.get(loc_id)
if db_file: if db_file:
return db_file return db_file
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+3 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -87,7 +87,8 @@ class AuthAPI(abc.ABC):
except PhoneNumberAppSignupForbiddenError: except PhoneNumberAppSignupForbiddenError:
return self.get_login_response(mxid=user.mxid, state="request", status=403, return self.get_login_response(mxid=user.mxid, state="request", status=403,
errcode="phone_number_app_signup_forbidden", errcode="phone_number_app_signup_forbidden",
error="You have disabled 3rd party apps on your account.") error="You have disabled 3rd party apps on your "
"account.")
except PhoneNumberUnoccupiedError: except PhoneNumberUnoccupiedError:
return self.get_login_response(mxid=user.mxid, state="request", status=404, return self.get_login_response(mxid=user.mxid, state="request", status=404,
errcode="phone_number_unoccupied", errcode="phone_number_unoccupied",
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@@ -247,7 +247,7 @@ class ProvisioningAPI(AuthAPI):
"group": "chat", "group": "chat",
}[type] }[type]
portal = Portal(tgid=None, mxid=room_id, title=title, about=about, peer_type=type) portal = Portal(tgid=TelegramID(0), mxid=room_id, title=title, about=about, peer_type=type)
try: try:
await portal.create_telegram_chat(user, supergroup=supergroup) await portal.create_telegram_chat(user, supergroup=supergroup)
except ValueError as e: except ValueError as e:
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*- # -*- coding: future_fstrings -*-
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2018 Tulir Asokan # Copyright (C) 2019 Tulir Asokan
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
+1 -1
View File
@@ -1,6 +1,6 @@
/* /*
* mautrix-telegram - A Matrix-Telegram puppeting bridge * mautrix-telegram - A Matrix-Telegram puppeting bridge
* Copyright (C) 2018 Tulir Asokan * Copyright (C) 2019 Tulir Asokan
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
+7 -5
View File
@@ -1,6 +1,6 @@
<!-- <!--
mautrix-telegram - A Matrix-Telegram puppeting bridge mautrix-telegram - A Matrix-Telegram puppeting bridge
Copyright (C) 2018 Tulir Asokan Copyright (C) 2019 Tulir Asokan
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by it under the terms of the GNU Affero General Public License as published by
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Login - Mautrix-Telegram bridge</title> <title>Login - Mautrix-Telegram bridge</title>
<link rel="icon" type="image/png" href="favicon.png"/> <link rel="icon" type="image/png" href="favicon.png"/>
@@ -25,9 +25,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<meta property="og:image" content="favicon.png"> <meta property="og:image" content="favicon.png">
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,700"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,700">
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" <link rel="stylesheet"
href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css"> href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css">
<link rel="stylesheet" href="login.css"/> <link rel="stylesheet" href="login.css"/>
<script> <script>
@@ -100,7 +101,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</button> </button>
% elif state == "bot_token": % elif state == "bot_token":
<label for="value">Bot token</label> <label for="value">Bot token</label>
<input type="text" id="value" name="bot_token" placeholder="Enter bot API token"/> <input type="text" id="value" name="bot_token"
placeholder="Enter bot API token"/>
<button type="submit">Sign in</button> <button type="submit">Sign in</button>
% elif state == "code": % elif state == "code":
<label for="value">Phone code</label> <label for="value">Phone code</label>
@@ -1,6 +1,6 @@
<!-- <!--
mautrix-telegram - A Matrix-Telegram puppeting bridge mautrix-telegram - A Matrix-Telegram puppeting bridge
Copyright (C) 2018 Tulir Asokan Copyright (C) 2019 Tulir Asokan
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by it under the terms of the GNU Affero General Public License as published by
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<title>Matrix login - Mautrix-Telegram bridge</title> <title>Matrix login - Mautrix-Telegram bridge</title>
<link rel="icon" type="image/png" href="favicon.png"/> <link rel="icon" type="image/png" href="favicon.png"/>
@@ -25,9 +25,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<meta property="og:image" content="favicon.png"> <meta property="og:image" content="favicon.png">
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,700"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,700">
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" <link rel="stylesheet"
href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css"> href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css">
<link rel="stylesheet" href="login.css"/> <link rel="stylesheet" href="login.css"/>
</head> </head>
<body> <body>
+2 -2
View File
@@ -31,7 +31,7 @@ setuptools.setup(
install_requires=[ install_requires=[
"aiohttp>=3.0.1,<4", "aiohttp>=3.0.1,<4",
"mautrix-appservice>=0.3.8,<0.4.0", "mautrix-appservice>=0.3.10.dev1,<0.4.0",
"SQLAlchemy>=1.2.3,<2", "SQLAlchemy>=1.2.3,<2",
"alembic>=1.0.0,<2", "alembic>=1.0.0,<2",
"commonmark>=0.8.1,<1", "commonmark>=0.8.1,<1",
@@ -39,7 +39,7 @@ setuptools.setup(
"future-fstrings>=0.4.2", "future-fstrings>=0.4.2",
"python-magic>=0.4.15,<0.5", "python-magic>=0.4.15,<0.5",
"telethon>=1.5.5,<1.7", "telethon>=1.5.5,<1.7",
"telethon-session-sqlalchemy>=0.2.11,<0.3", "telethon-session-sqlalchemy>=0.2.12,<0.3",
], ],
extras_require=extras, extras_require=extras,