diff --git a/mautrix_telegram/__main__.py b/mautrix_telegram/__main__.py
index 7e0f0818..ce0e0784 100644
--- a/mautrix_telegram/__main__.py
+++ b/mautrix_telegram/__main__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py
index 6839f2e8..60dc004f 100644
--- a/mautrix_telegram/abstract_user.py
+++ b/mautrix_telegram/abstract_user.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py
index db3f40ea..4506f22c 100644
--- a/mautrix_telegram/bot.py
+++ b/mautrix_telegram/bot.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/clean_rooms.py b/mautrix_telegram/commands/clean_rooms.py
index 0dfb0494..6f584fd4 100644
--- a/mautrix_telegram/commands/clean_rooms.py
+++ b/mautrix_telegram/commands/clean_rooms.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/handler.py b/mautrix_telegram/commands/handler.py
index dc432605..cb39a37b 100644
--- a/mautrix_telegram/commands/handler.py
+++ b/mautrix_telegram/commands/handler.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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
# along with this program. If not, see .
"""This module contains classes handling commands issued by Matrix users."""
-from typing import (
- Any,
- Awaitable,
- Callable,
- Coroutine,
- Dict,
- List,
- NamedTuple,
- Optional,
- Union,
- NewType,
-)
+from typing import Awaitable, Callable, Dict, List, NamedTuple, Optional
import logging
import traceback
@@ -93,6 +82,7 @@ class CommandEvent:
is_portal: Determines whether the room in which the command was issued
is a portal.
"""
+
def __init__(self, processor: 'CommandProcessor', room: MatrixRoomID, event: MatrixEventID,
sender: u.User, command: str, args: List[str], is_management: bool,
is_portal: bool) -> None:
@@ -111,12 +101,8 @@ class CommandEvent:
self.is_management = is_management
self.is_portal = is_portal
- def reply(
- self,
- message: str,
- allow_html: bool = False,
- render_markdown: bool = True,
- ) -> Awaitable[Dict]:
+ def reply(self, message: str, allow_html: bool = False, render_markdown: bool = True
+ ) -> Awaitable[Dict]:
"""Write a reply to the room in which the command was issued.
Replaces occurences of "$cmdprefix" in the message with the command
@@ -136,9 +122,8 @@ class CommandEvent:
Handler for the message sending function.
"""
message_cmd = self._replace_command_prefix(message)
- html = self._render_message(
- message_cmd, allow_html=allow_html, render_markdown=render_markdown
- )
+ html = self._render_message(message_cmd, allow_html=allow_html,
+ render_markdown=render_markdown)
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)
- def _render_message(
- self, message: str, allow_html: bool, render_markdown: bool
- ) -> Optional[str]:
+ @staticmethod
+ def _render_message(message: str, allow_html: bool, render_markdown: bool) -> Optional[str]:
"""Renders the message as HTML.
Args:
@@ -194,6 +178,7 @@ class CommandHandler:
name: The name of this command.
help_section: Section of the help in which this command will appear.
"""
+
def __init__(self, handler: Callable[[CommandEvent], Awaitable[Dict]], needs_auth: bool,
needs_puppeting: bool, needs_matrix_puppeting: bool, needs_admin: bool,
management_only: bool, name: str, help_text: str, help_args: str,
@@ -254,7 +239,7 @@ class CommandHandler:
Args:
is_management: If the room in which the command will be issued is a
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.
matrix_puppet_whitelisted: If the connected Matrix account puppet is
allowed to issue the command.
@@ -308,10 +293,9 @@ def command_handler(_func: Optional[Callable[[CommandEvent], Awaitable[Dict]]] =
name: Optional[str] = None,
help_text: str = "",
help_args: str = "",
- help_section: HelpSection = None
+ help_section: HelpSection = None,
) -> Callable[[Callable[[CommandEvent], Awaitable[Optional[Dict]]]],
CommandHandler]:
-
def decorator(func: Callable[[CommandEvent], Awaitable[Optional[Dict]]]) -> CommandHandler:
actual_name = name or func.__name__.replace("_", "-")
handler = CommandHandler(func, needs_auth, needs_puppeting, needs_matrix_puppeting,
diff --git a/mautrix_telegram/commands/matrix_auth.py b/mautrix_telegram/commands/matrix_auth.py
index 2e27744f..5250224b 100644
--- a/mautrix_telegram/commands/matrix_auth.py
+++ b/mautrix_telegram/commands/matrix_auth.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/meta.py b/mautrix_telegram/commands/meta.py
index cbd8e901..303bfd4f 100644
--- a/mautrix_telegram/commands/meta.py
+++ b/mautrix_telegram/commands/meta.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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`."
-@command_handler(needs_auth=False, needs_puppeting=False,
+@command_handler(name="help", needs_auth=False, needs_puppeting=False,
help_section=SECTION_GENERAL,
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))
diff --git a/mautrix_telegram/commands/portal/admin.py b/mautrix_telegram/commands/portal/admin.py
index 52197008..376549c7 100644
--- a/mautrix_telegram/commands/portal/admin.py
+++ b/mautrix_telegram/commands/portal/admin.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/portal/bridge.py b/mautrix_telegram/commands/portal/bridge.py
index cb6c9b7f..5ae7f153 100644
--- a/mautrix_telegram/commands/portal/bridge.py
+++ b/mautrix_telegram/commands/portal/bridge.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/portal/config.py b/mautrix_telegram/commands/portal/config.py
index 2bec621e..0cacfbcc 100644
--- a/mautrix_telegram/commands/portal/config.py
+++ b/mautrix_telegram/commands/portal/config.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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 ...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
+
@command_handler(help_section=SECTION_PORTAL_MANAGEMENT,
help_text="View or change per-portal settings.",
help_args="<`help`|_subcommand_> [...]")
diff --git a/mautrix_telegram/commands/portal/create_chat.py b/mautrix_telegram/commands/portal/create_chat.py
index 98262591..4d3eb4ff 100644
--- a/mautrix_telegram/commands/portal/create_chat.py
+++ b/mautrix_telegram/commands/portal/create_chat.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
@@ -17,6 +17,7 @@
from typing import Dict
from ... import portal as po
+from ...types import TelegramID
from .. import command_handler, CommandEvent, SECTION_CREATING_PORTALS
from .util import user_has_power_level, get_initial_state
@@ -50,7 +51,8 @@ async def create(evt: CommandEvent) -> Dict:
"group": "chat",
}[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:
await portal.create_telegram_chat(evt.sender, supergroup=supergroup)
except ValueError as e:
diff --git a/mautrix_telegram/commands/portal/filter.py b/mautrix_telegram/commands/portal/filter.py
index 5df42f5d..baa0b2ea 100644
--- a/mautrix_telegram/commands/portal/filter.py
+++ b/mautrix_telegram/commands/portal/filter.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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 `.")
-@command_handler(needs_admin=True,
+@command_handler(name="filter", needs_admin=True,
help_section=SECTION_ADMIN,
help_args="<`whitelist`|`blacklist`> <_chat ID_>",
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:
action = evt.args[0]
if action not in ("whitelist", "blacklist", "add", "remove"):
@@ -58,11 +58,11 @@ async def filter(evt: CommandEvent) -> Optional[Dict]:
id_str = evt.args[1]
if id_str.startswith("-100"):
- id = int(id_str[4:])
+ filter_id = int(id_str[4:])
elif id_str.startswith("-"):
- id = int(id_str[1:])
+ filter_id = int(id_str[1:])
else:
- id = int(id_str)
+ filter_id = int(id_str)
except (IndexError, ValueError):
return await evt.reply("**Usage:** `$cmdprefix+sp filter `")
@@ -70,26 +70,26 @@ async def filter(evt: CommandEvent) -> Optional[Dict]:
if mode not in ("blacklist", "whitelist"):
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"):
action = "add" if mode == action else "remove"
def save() -> None:
- evt.config["bridge.filter.list"] = list
+ evt.config["bridge.filter.list"] = filter_id_list
evt.config.save()
- po.Portal.filter_list = list
+ po.Portal.filter_list = filter_id_list
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.")
- list.append(id)
+ filter_id_list.append(filter_id)
save()
return await evt.reply(f"Chat ID added to {mode}.")
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.")
- list.remove(id)
+ filter_id_list.remove(filter_id)
save()
return await evt.reply(f"Chat ID removed from {mode}.")
return None
diff --git a/mautrix_telegram/commands/portal/misc.py b/mautrix_telegram/commands/portal/misc.py
index a5617848..802dec12 100644
--- a/mautrix_telegram/commands/portal/misc.py
+++ b/mautrix_telegram/commands/portal/misc.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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")
-@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_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)
if not portal:
return await evt.reply("This is not a portal room.")
diff --git a/mautrix_telegram/commands/portal/unbridge.py b/mautrix_telegram/commands/portal/unbridge.py
index 069c14ec..9bc1e3c1 100644
--- a/mautrix_telegram/commands/portal/unbridge.py
+++ b/mautrix_telegram/commands/portal/unbridge.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/portal/util.py b/mautrix_telegram/commands/portal/util.py
index c76450c1..b0556df5 100644
--- a/mautrix_telegram/commands/portal/util.py
+++ b/mautrix_telegram/commands/portal/util.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/telegram/account.py b/mautrix_telegram/commands/telegram/account.py
index ca2e69c3..dd2a17ed 100644
--- a/mautrix_telegram/commands/telegram/account.py
+++ b/mautrix_telegram/commands/telegram/account.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/telegram/auth.py b/mautrix_telegram/commands/telegram/auth.py
index fedb72d7..5f56c4ca 100644
--- a/mautrix_telegram/commands/telegram/auth.py
+++ b/mautrix_telegram/commands/telegram/auth.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/commands/telegram/misc.py b/mautrix_telegram/commands/telegram/misc.py
index 882b947a..5a6848c6 100644
--- a/mautrix_telegram/commands/telegram/misc.py
+++ b/mautrix_telegram/commands/telegram/misc.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py
index c5ad8c4f..d75de4a8 100644
--- a/mautrix_telegram/config.py
+++ b/mautrix_telegram/config.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/context.py b/mautrix_telegram/context.py
index f1b99830..88c332d4 100644
--- a/mautrix_telegram/context.py
+++ b/mautrix_telegram/context.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/__init__.py b/mautrix_telegram/db/__init__.py
index 053f7fa4..724af6a2 100644
--- a/mautrix_telegram/db/__init__.py
+++ b/mautrix_telegram/db/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/base.py b/mautrix_telegram/db/base.py
index 15772fca..a91cc82c 100644
--- a/mautrix_telegram/db/base.py
+++ b/mautrix_telegram/db/base.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
@@ -20,10 +20,11 @@ from sqlalchemy import Table
from sqlalchemy.engine.base import Engine
from sqlalchemy.engine.result import RowProxy
from sqlalchemy.sql.base import ImmutableColumnCollection
-from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.ext.declarative import as_declarative
-class BaseBase:
+@as_declarative()
+class Base:
db = None # type: Engine
t = None # type: Table
__table__ = None # type: Table
@@ -54,6 +55,3 @@ class BaseBase:
def delete(self) -> None:
with self.db.begin() as conn:
conn.execute(self.t.delete().where(self._edit_identity))
-
-
-Base = declarative_base(cls=BaseBase)
diff --git a/mautrix_telegram/db/bot_chat.py b/mautrix_telegram/db/bot_chat.py
index 1afb9c60..c7363cc5 100644
--- a/mautrix_telegram/db/bot_chat.py
+++ b/mautrix_telegram/db/bot_chat.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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)
@classmethod
- def delete(cls, id: TelegramID) -> None:
+ def delete(cls, chat_id: TelegramID) -> None:
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
def all(cls) -> Iterable['BotChat']:
rows = cls.db.execute(cls.t.select())
for row in rows:
- id, type = row
- yield cls(id=id, type=type)
+ chat_id, chat_type = row
+ yield cls(id=chat_id, type=chat_type)
def insert(self) -> None:
with self.db.begin() as conn:
diff --git a/mautrix_telegram/db/message.py b/mautrix_telegram/db/message.py
index b5534b9c..a704b197 100644
--- a/mautrix_telegram/db/message.py
+++ b/mautrix_telegram/db/message.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/portal.py b/mautrix_telegram/db/portal.py
index 7b2d19e7..fd4a1ba1 100644
--- a/mautrix_telegram/db/portal.py
+++ b/mautrix_telegram/db/portal.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/puppet.py b/mautrix_telegram/db/puppet.py
index 149e64ca..531e7122 100644
--- a/mautrix_telegram/db/puppet.py
+++ b/mautrix_telegram/db/puppet.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/room_state.py b/mautrix_telegram/db/room_state.py
index 78eee5e0..0aa9aa84 100644
--- a/mautrix_telegram/db/room_state.py
+++ b/mautrix_telegram/db/room_state.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/telegram_file.py b/mautrix_telegram/db/telegram_file.py
index 65070533..4b36b10a 100644
--- a/mautrix_telegram/db/telegram_file.py
+++ b/mautrix_telegram/db/telegram_file.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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]
@classmethod
- def get(cls, id: str) -> Optional['TelegramFile']:
- rows = cls.db.execute(cls.t.select().where(cls.c.id == id))
+ def get(cls, loc_id: str) -> Optional['TelegramFile']:
+ rows = cls.db.execute(cls.t.select().where(cls.c.id == loc_id))
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
if 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)
except StopIteration:
return None
diff --git a/mautrix_telegram/db/user.py b/mautrix_telegram/db/user.py
index 61729474..ba304894 100644
--- a/mautrix_telegram/db/user.py
+++ b/mautrix_telegram/db/user.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/db/user_profile.py b/mautrix_telegram/db/user_profile.py
index a12401eb..d09262b5 100644
--- a/mautrix_telegram/db/user_profile.py
+++ b/mautrix_telegram/db/user_profile.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/formatter/from_matrix/__init__.py b/mautrix_telegram/formatter/from_matrix/__init__.py
index f71da094..f8a1119e 100644
--- a/mautrix_telegram/formatter/from_matrix/__init__.py
+++ b/mautrix_telegram/formatter/from_matrix/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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
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:
@@ -147,5 +147,5 @@ def init_mx(context: "Context") -> None:
config = context.config
dn_template = config.get("bridge.displayname_template", "{displayname} (Telegram)")
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
diff --git a/mautrix_telegram/formatter/from_matrix/html_reader.py b/mautrix_telegram/formatter/from_matrix/html_reader.py
index 9ac10cf2..a1fbe4bf 100644
--- a/mautrix_telegram/formatter/from_matrix/html_reader.py
+++ b/mautrix_telegram/formatter/from_matrix/html_reader.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/formatter/from_matrix/parser.py b/mautrix_telegram/formatter/from_matrix/parser.py
index 03f24065..bf9b44d1 100644
--- a/mautrix_telegram/formatter/from_matrix/parser.py
+++ b/mautrix_telegram/formatter/from_matrix/parser.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/formatter/from_matrix/telegram_message.py b/mautrix_telegram/formatter/from_matrix/telegram_message.py
index f78af066..dd4af9da 100644
--- a/mautrix_telegram/formatter/from_matrix/telegram_message.py
+++ b/mautrix_telegram/formatter/from_matrix/telegram_message.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/formatter/from_telegram.py b/mautrix_telegram/formatter/from_telegram.py
index 1e5a924f..27f264da 100644
--- a/mautrix_telegram/formatter/from_telegram.py
+++ b/mautrix_telegram/formatter/from_telegram.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
@@ -71,7 +71,7 @@ async def _add_forward_header(source, text: str, html: Optional[str],
html = escape(text)
fwd_from_html, fwd_from_text = None, None
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:
fwd_from_text = user.displayname or user.mxid
fwd_from_html = f"{fwd_from_text}"
diff --git a/mautrix_telegram/formatter/util.py b/mautrix_telegram/formatter/util.py
index 70c19ebb..b0456f51 100644
--- a/mautrix_telegram/formatter/util.py
+++ b/mautrix_telegram/formatter/util.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py
index 3f80bc94..a57cd946 100644
--- a/mautrix_telegram/matrix.py
+++ b/mautrix_telegram/matrix.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py
index 04b3ccd1..c5368b38 100644
--- a/mautrix_telegram/portal.py
+++ b/mautrix_telegram/portal.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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()
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":
response = await source.client(CreateChatRequest(title=self.title, users=invites))
entity = response.chats[0]
diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py
index a3569997..e1ec9ebc 100644
--- a/mautrix_telegram/puppet.py
+++ b/mautrix_telegram/puppet.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/scripts/telematrix_import/__main__.py b/mautrix_telegram/scripts/telematrix_import/__main__.py
index 1c7f6e57..53a3e204 100644
--- a/mautrix_telegram/scripts/telematrix_import/__main__.py
+++ b/mautrix_telegram/scripts/telematrix_import/__main__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/sqlstatestore.py b/mautrix_telegram/sqlstatestore.py
index a4f67ee1..82a305ee 100644
--- a/mautrix_telegram/sqlstatestore.py
+++ b/mautrix_telegram/sqlstatestore.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/tgclient.py b/mautrix_telegram/tgclient.py
index db8920d8..43e0a1a6 100644
--- a/mautrix_telegram/tgclient.py
+++ b/mautrix_telegram/tgclient.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py
index 11aacc00..0de66515 100644
--- a/mautrix_telegram/user.py
+++ b/mautrix_telegram/user.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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_instance = db_instance # type: Optional[DBUser]
- self.command_status = None # type: Dict
+ self.command_status = None # type: Optional[Dict]
(self.relaybot_whitelisted,
self.whitelisted,
diff --git a/mautrix_telegram/util/file_transfer.py b/mautrix_telegram/util/file_transfer.py
index bb707045..fea25088 100644
--- a/mautrix_telegram/util/file_transfer.py
+++ b/mautrix_telegram/util/file_transfer.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# 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]
+TypeThumbnail = Optional[Union[TypeLocation, TypePhotoSize]]
+
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]:
location_id = _location_to_id(location)
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,
loc_id: str, location: TypeLocation,
- thumbnail: Optional[Union[TypeLocation, TypePhotoSize]],
- is_sticker: bool) -> Optional[DBTelegramFile]:
+ thumbnail: TypeThumbnail, is_sticker: bool
+ ) -> Optional[DBTelegramFile]:
db_file = DBTelegramFile.get(loc_id)
if db_file:
return db_file
diff --git a/mautrix_telegram/util/format_duration.py b/mautrix_telegram/util/format_duration.py
index 44d16550..b98c6e71 100644
--- a/mautrix_telegram/util/format_duration.py
+++ b/mautrix_telegram/util/format_duration.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/util/recursive_dict.py b/mautrix_telegram/util/recursive_dict.py
index 6f21a638..ef76fe3e 100644
--- a/mautrix_telegram/util/recursive_dict.py
+++ b/mautrix_telegram/util/recursive_dict.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/util/signed_token.py b/mautrix_telegram/util/signed_token.py
index febb2aa4..c8ba55d3 100644
--- a/mautrix_telegram/util/signed_token.py
+++ b/mautrix_telegram/util/signed_token.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/web/common/auth_api.py b/mautrix_telegram/web/common/auth_api.py
index cf326cbc..d740ddaf 100644
--- a/mautrix_telegram/web/common/auth_api.py
+++ b/mautrix_telegram/web/common/auth_api.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
@@ -87,7 +87,8 @@ class AuthAPI(abc.ABC):
except PhoneNumberAppSignupForbiddenError:
return self.get_login_response(mxid=user.mxid, state="request", status=403,
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:
return self.get_login_response(mxid=user.mxid, state="request", status=404,
errcode="phone_number_unoccupied",
diff --git a/mautrix_telegram/web/provisioning/__init__.py b/mautrix_telegram/web/provisioning/__init__.py
index 995ac2cf..07589831 100644
--- a/mautrix_telegram/web/provisioning/__init__.py
+++ b/mautrix_telegram/web/provisioning/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
@@ -247,7 +247,7 @@ class ProvisioningAPI(AuthAPI):
"group": "chat",
}[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:
await portal.create_telegram_chat(user, supergroup=supergroup)
except ValueError as e:
diff --git a/mautrix_telegram/web/public/__init__.py b/mautrix_telegram/web/public/__init__.py
index 36717872..df338994 100644
--- a/mautrix_telegram/web/public/__init__.py
+++ b/mautrix_telegram/web/public/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: future_fstrings -*-
# 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
# it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/web/public/login.css b/mautrix_telegram/web/public/login.css
index 7b035792..d582ea6b 100644
--- a/mautrix_telegram/web/public/login.css
+++ b/mautrix_telegram/web/public/login.css
@@ -1,6 +1,6 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
diff --git a/mautrix_telegram/web/public/login.html.mako b/mautrix_telegram/web/public/login.html.mako
index fa4f0924..12c9bc63 100644
--- a/mautrix_telegram/web/public/login.html.mako
+++ b/mautrix_telegram/web/public/login.html.mako
@@ -1,6 +1,6 @@