Fix minor things and type hints
This commit is contained in:
@@ -4,6 +4,6 @@ from .from_telegram import (telegram_reply_to_matrix, telegram_to_matrix, init_t
|
||||
from .. import context as c
|
||||
|
||||
|
||||
def init(context: c.Context):
|
||||
def init(context: c.Context) -> None:
|
||||
init_mx(context)
|
||||
init_tg(context)
|
||||
|
||||
@@ -148,7 +148,7 @@ def plain_mention_to_text() -> Tuple[List[TypeMessageEntity], Callable[[str], st
|
||||
return entities, replacer
|
||||
|
||||
|
||||
def init_mx(context: "Context"):
|
||||
def init_mx(context: "Context") -> None:
|
||||
global plain_mention_regex, should_bridge_plaintext_highlights
|
||||
config = context.config
|
||||
dn_template = config.get("bridge.displayname_template", "{displayname} (Telegram)")
|
||||
|
||||
@@ -26,11 +26,11 @@ class MatrixParserCommon:
|
||||
"ol", "ul", "li",
|
||||
"h1", "h2", "h3", "h4", "h5", "h6",
|
||||
"div", "hr", "table") # type: Tuple[str, ...]
|
||||
list_bullets = ("●", "○", "■", "‣")
|
||||
list_bullets = ("●", "○", "■", "‣") # type: Tuple[str, ...]
|
||||
|
||||
@classmethod
|
||||
def list_bullet(cls, depth: int) -> str:
|
||||
return cls.list_bullets[(depth - 1) % len(cls.list_bullets)]
|
||||
return cls.list_bullets[(depth - 1) % len(cls.list_bullets)] + " "
|
||||
|
||||
|
||||
ParsedMessage = Tuple[str, List[TypeMessageEntity]]
|
||||
|
||||
@@ -202,7 +202,7 @@ class MatrixParser(HTMLParser, MatrixParserCommon):
|
||||
else:
|
||||
prefix = int(math.log(n, 10)) * 3 * " " + 4 * " "
|
||||
else:
|
||||
prefix = (f"{self.list_bullet(self._open_tags.count('ul'))} "
|
||||
prefix = (self.list_bullet(self._open_tags.count('ul'))
|
||||
if self._list_entry_is_new else 3 * " ")
|
||||
if not self._list_entry_is_new and not self._line_is_new:
|
||||
prefix = ""
|
||||
|
||||
@@ -80,7 +80,7 @@ class MatrixParser(MatrixParserCommon):
|
||||
prefix = f"{counter}. "
|
||||
counter += 1
|
||||
else:
|
||||
prefix = f"{cls.list_bullet(ctx.ul_depth)} "
|
||||
prefix = cls.list_bullet(ctx.ul_depth)
|
||||
child = child.prepend(prefix)
|
||||
parts = child.split("\n")
|
||||
parts = parts[:1] + [part.prepend(indent) for part in parts[1:]]
|
||||
|
||||
@@ -19,11 +19,11 @@ from html import escape
|
||||
import logging
|
||||
import re
|
||||
|
||||
from telethon.tl.types import (MessageEntityMention, MessageEntityMentionName,
|
||||
MessageEntityEmail, MessageEntityUrl, MessageEntityTextUrl,
|
||||
MessageEntityBold, MessageEntityItalic, MessageEntityCode,
|
||||
MessageEntityPre, MessageEntityBotCommand, Message, PeerChannel,
|
||||
MessageEntityHashtag, TypeMessageEntity, MessageFwdHeader, PeerUser)
|
||||
from telethon.tl.types import (MessageEntityMention, MessageEntityMentionName, MessageEntityUrl,
|
||||
MessageEntityEmail, MessageEntityTextUrl, MessageEntityBold,
|
||||
MessageEntityItalic, MessageEntityCode, MessageEntityPre,
|
||||
MessageEntityBotCommand, Message, PeerChannel, MessageEntityHashtag,
|
||||
TypeMessageEntity, MessageFwdHeader, PeerUser)
|
||||
|
||||
from mautrix_appservice import MatrixRequestError
|
||||
from mautrix_appservice.intent_api import IntentAPI
|
||||
|
||||
@@ -32,14 +32,14 @@ TelematrixBase.metadata.bind = telematrix_db_engine
|
||||
chat_links = telematrix.query(ChatLink).all()
|
||||
tg_users = telematrix.query(TgUser).all()
|
||||
mx_users = telematrix.query(MatrixUser).all()
|
||||
messages = telematrix.query(TMMessage).all()
|
||||
tm_messages = telematrix.query(TMMessage).all()
|
||||
|
||||
telematrix.close()
|
||||
telematrix_db_engine.dispose()
|
||||
|
||||
portals = {}
|
||||
chats = {}
|
||||
messages = {}
|
||||
portals = {} # Dict[int, Portal]
|
||||
chats = {} # Dict[int, BotChat]
|
||||
messages = {} # Dict[str, Message]
|
||||
puppets = {} # Dict[int, Puppet]
|
||||
|
||||
for chat_link in chat_links:
|
||||
@@ -65,11 +65,12 @@ for chat_link in chat_links:
|
||||
portals[chat_link.tg_room] = portal
|
||||
chats[tgid] = bot_chat
|
||||
|
||||
for tm_msg in messages:
|
||||
for tm_msg in tm_messages:
|
||||
try:
|
||||
portal = portals[tm_msg.tg_group_id]
|
||||
except KeyError:
|
||||
print("Found message entry %d in unlinked chat %d, ignoring..." % (tm_msg.tg_message_id, tm_msg.tg_group_id))
|
||||
print("Found message entry %d in unlinked chat %d, ignoring..." % (tm_msg.tg_message_id,
|
||||
tm_msg.tg_group_id))
|
||||
continue
|
||||
tg_space = portal.tgid if portal.peer_type == "channel" else args.bot_id
|
||||
message = Message(mxid=tm_msg.matrix_event_id, mx_room=tm_msg.matrix_room_id,
|
||||
@@ -77,7 +78,8 @@ for tm_msg in messages:
|
||||
messages[tm_msg.matrix_event_id] = message
|
||||
|
||||
for user in tg_users:
|
||||
puppets[user.tg_id] = Puppet(id=user.tg_id, displayname=user.name, displayname_source=args.bot_id)
|
||||
puppets[user.tg_id] = Puppet(id=user.tg_id, displayname=user.name,
|
||||
displayname_source=args.bot_id)
|
||||
|
||||
for k, v in portals.items():
|
||||
mxtg.add(v)
|
||||
|
||||
@@ -5,7 +5,7 @@ Base = declarative_base()
|
||||
|
||||
|
||||
class ChatLink(Base):
|
||||
__tablename__ = 'chat_link'
|
||||
__tablename__ = "chat_link"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
matrix_room = sa.Column(sa.String)
|
||||
@@ -14,7 +14,7 @@ class ChatLink(Base):
|
||||
|
||||
|
||||
class TgUser(Base):
|
||||
__tablename__ = 'tg_user'
|
||||
__tablename__ = "tg_user"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
tg_id = sa.Column(sa.BigInteger)
|
||||
@@ -23,7 +23,7 @@ class TgUser(Base):
|
||||
|
||||
|
||||
class MatrixUser(Base):
|
||||
__tablename__ = 'matrix_user'
|
||||
__tablename__ = "matrix_user"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
matrix_id = sa.Column(sa.String)
|
||||
|
||||
Reference in New Issue
Block a user