Update mautrix-python

This commit is contained in:
Tulir Asokan
2021-12-08 12:17:26 +02:00
parent 782cd426a4
commit 3ddd4449b1
2 changed files with 22 additions and 3 deletions
+21 -2
View File
@@ -1,5 +1,5 @@
# mautrix-telegram - A Matrix-Telegram puppeting bridge # mautrix-telegram - A Matrix-Telegram puppeting bridge
# Copyright (C) 2019 Tulir Asokan # Copyright (C) 2021 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
@@ -14,6 +14,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/>.
from typing import Dict, Any from typing import Dict, Any
import sys
from telethon import __version__ as __telethon_version__ from telethon import __version__ as __telethon_version__
from alchemysession import AlchemySessionContainer from alchemysession import AlchemySessionContainer
@@ -21,6 +22,7 @@ from alchemysession import AlchemySessionContainer
from mautrix.types import UserID, RoomID from mautrix.types import UserID, RoomID
from mautrix.bridge import Bridge from mautrix.bridge import Bridge
from mautrix.util.db import Base from mautrix.util.db import Base
from mautrix.bridge.state_store.sqlalchemy import SQLBridgeStateStore
from .web.provisioning import ProvisioningAPI from .web.provisioning import ProvisioningAPI
from .web.public import PublicBridgeWebsite from .web.public import PublicBridgeWebsite
@@ -36,6 +38,9 @@ from .puppet import Puppet, init as init_puppet
from .user import User, init as init_user from .user import User, init as init_user
from .version import version, linkified_version from .version import version, linkified_version
import sqlalchemy as sql
from sqlalchemy.engine.base import Engine
try: try:
import prometheus_client as prometheus import prometheus_client as prometheus
except ImportError: except ImportError:
@@ -53,18 +58,32 @@ class TelegramBridge(Bridge):
markdown_version = linkified_version markdown_version = linkified_version
config_class = Config config_class = Config
matrix_class = MatrixHandler matrix_class = MatrixHandler
state_store_class = SQLBridgeStateStore
db: 'Engine'
config: Config config: Config
session_container: AlchemySessionContainer session_container: AlchemySessionContainer
bot: Bot bot: Bot
def prepare_db(self) -> None: def prepare_db(self) -> None:
super().prepare_db() if not sql:
raise RuntimeError("SQLAlchemy is not installed")
self.db = sql.create_engine(self.config["appservice.database"],
**self.config["appservice.database_opts"])
Base.metadata.bind = self.db
if not self.db.has_table("alembic_version"):
self.log.critical("alembic_version table not found. "
"Did you forget to `alembic upgrade head`?")
sys.exit(10)
init_db(self.db) init_db(self.db)
self.session_container = AlchemySessionContainer( self.session_container = AlchemySessionContainer(
engine=self.db, table_base=Base, session=False, engine=self.db, table_base=Base, session=False,
table_prefix="telethon_", manage_tables=False) table_prefix="telethon_", manage_tables=False)
def make_state_store(self) -> None:
self.state_store = self.state_store_class(self.get_puppet, self.get_double_puppet)
def _prepare_website(self, context: Context) -> None: def _prepare_website(self, context: Context) -> None:
if self.config["appservice.public.enabled"]: if self.config["appservice.public.enabled"]:
public_website = PublicBridgeWebsite(self.loop) public_website = PublicBridgeWebsite(self.loop)
+1 -1
View File
@@ -5,7 +5,7 @@ python-magic>=0.4,<0.5
commonmark>=0.8,<0.10 commonmark>=0.8,<0.10
aiohttp>=3,<4 aiohttp>=3,<4
yarl>=1,<2 yarl>=1,<2
mautrix>=0.11.4,<0.13 mautrix>=0.13rc1,<0.14
telethon>=1.24,<1.25 telethon>=1.24,<1.25
telethon-session-sqlalchemy>=0.2.14,<0.3 telethon-session-sqlalchemy>=0.2.14,<0.3
# Temporarily always depend on aiosqlite to prevent breaking old installs # Temporarily always depend on aiosqlite to prevent breaking old installs