diff --git a/mautrix_appservice/errors.py b/mautrix_appservice/errors.py index 8c09936f..02c4f87b 100644 --- a/mautrix_appservice/errors.py +++ b/mautrix_appservice/errors.py @@ -31,7 +31,7 @@ class MatrixRequestError(MatrixError): """ The home server returned an error response. """ def __init__(self, code=0, text="", errcode=None, message=None): - super().__init__("%d: %s" % (code, text)) + super().__init__(f"{code}: {text}") self.code = code self.text = text self.errcode = errcode diff --git a/mautrix_appservice/intent_api.py b/mautrix_appservice/intent_api.py index a8434932..fb9710d6 100644 --- a/mautrix_appservice/intent_api.py +++ b/mautrix_appservice/intent_api.py @@ -524,7 +524,7 @@ class IntentAPI: self.log.warning( f"Power level of {self.mxid} is not enough for {event_type} in {room_id}") # raise IntentError(f"Power level of {self.mxid} is not enough" - # + f"for {event_type} in {room_id}") + # f"for {event_type} in {room_id}") return # TODO implement diff --git a/mautrix_telegram/commands/auth.py b/mautrix_telegram/commands/auth.py index de38fdbf..ed254540 100644 --- a/mautrix_telegram/commands/auth.py +++ b/mautrix_telegram/commands/auth.py @@ -42,9 +42,9 @@ async def ping_bot(evt): hs = evt.config["homeserver"]["domain"] mxid = f"@{localpart}:{hs}" displayname = bot_info.first_name - return await evt.reply(f"Telegram message relay bot is active: " - + f"[{displayname}](https://matrix.to/#/{mxid}) (ID {bot_info.id})\n\n" - + f"To use the bot, simply invite it to a portal room.") + return await evt.reply("Telegram message relay bot is active: " + f"[{displayname}](https://matrix.to/#/{mxid}) (ID {bot_info.id})\n\n" + "To use the bot, simply invite it to a portal room.") @command_handler(needs_auth=False, management_only=True) diff --git a/mautrix_telegram/commands/clean_rooms.py b/mautrix_telegram/commands/clean_rooms.py index 12dcd144..06ebb428 100644 --- a/mautrix_telegram/commands/clean_rooms.py +++ b/mautrix_telegram/commands/clean_rooms.py @@ -66,7 +66,7 @@ async def clean_rooms(evt): or ["No management rooms found."]) reply.append("#### Active portal rooms (A)") reply += ([f"{n+1}. [P{n+1}](https://matrix.to/#/{portal.mxid}) " - + f"(to Telegram chat \"{portal.title}\")" + f"(to Telegram chat \"{portal.title}\")" for n, portal in enumerate(portals)] or ["No active portal rooms found."]) reply.append("#### Unidentified rooms (U)") @@ -75,7 +75,7 @@ async def clean_rooms(evt): or ["No unidentified rooms found."]) reply.append("#### Inactive portal rooms (I)") reply += ([f"{n}. [E{n}](https://matrix.to/#/{portal.mxid}) " - + f"(to Telegram chat \"{portal.title}\")" + f"(to Telegram chat \"{portal.title}\")" for n, portal in enumerate(empty_portals)] or ["No inactive portal rooms found."]) @@ -141,21 +141,21 @@ async def set_rooms_to_clean(evt, management_rooms, unidentified_rooms, portals, "**Usage:** `$cmdprefix+sp clean-groups <_M|A|U|I_>") else: return await evt.reply(f"Unknown room cleaning action `{command}`. " - + "Use `$cmdprefix+sp cancel` to cancel room " - + "cleaning.") + "Use `$cmdprefix+sp cancel` to cancel room " + "cleaning.") evt.sender.command_status = { "next": lambda confirm: execute_room_cleanup(confirm, rooms_to_clean), "action": "Room cleaning", } await evt.reply(f"To confirm cleaning up {len(rooms_to_clean)} rooms, type" - + "`$cmdprefix+sp confirm-clean`.") + "`$cmdprefix+sp confirm-clean`.") async def execute_room_cleanup(evt, rooms_to_clean): if len(evt.args) > 0 and evt.args[0] == "confirm-clean": await evt.reply(f"Cleaning {len(rooms_to_clean)} rooms. " - + "This might take a while.") + "This might take a while.") cleaned = 0 for room in rooms_to_clean: if isinstance(room, po.Portal): diff --git a/mautrix_telegram/commands/handler.py b/mautrix_telegram/commands/handler.py index 2ed4679d..94c6a356 100644 --- a/mautrix_telegram/commands/handler.py +++ b/mautrix_telegram/commands/handler.py @@ -27,7 +27,7 @@ def command_handler(needs_auth=True, management_only=False, needs_admin=False, n def wrapper(evt): if management_only and not evt.is_management: return evt.reply(f"`{evt.command}` is a restricted command:" - + "you may only run it in management rooms.") + "you may only run it in management rooms.") elif needs_auth and not evt.sender.logged_in: return evt.reply("This command requires you to be logged in.") elif needs_admin and not evt.sender.is_admin: @@ -112,6 +112,6 @@ class CommandHandler: except FloodWaitError as e: return evt.reply(f"Flood error: Please wait {format_duration(e.seconds)}") except Exception: - self.log.exception(f"Fatal error handling command " - + f"{evt.command} {' '.join(args)} from {sender.mxid}") + self.log.exception("Fatal error handling command " + f"{evt.command} {' '.join(args)} from {sender.mxid}") return evt.reply("Fatal error while handling command. Check logs for more details.") diff --git a/mautrix_telegram/commands/telegram.py b/mautrix_telegram/commands/telegram.py index f77c2110..10693a94 100644 --- a/mautrix_telegram/commands/telegram.py +++ b/mautrix_telegram/commands/telegram.py @@ -51,7 +51,7 @@ async def search(evt): else: reply += ["**Results in contacts:**", ""] reply += [(f"* [{puppet.displayname}](https://matrix.to/#/{puppet.mxid}): " - + f"{puppet.id} ({similarity}% match)") + f"{puppet.id} ({similarity}% match)") for puppet, similarity in results] # TODO somehow show remote channel results when joining by alias is possible? @@ -71,8 +71,8 @@ async def pm(evt): return await evt.reply("That doesn't seem to be a user.") portal = po.Portal.get_by_entity(user, evt.sender.tgid) await portal.create_matrix_room(evt.sender, user, [evt.sender.mxid]) - return await evt.reply( - f"Created private chat room with {pu.Puppet.get_displayname(user, False)}") + return await evt.reply("Created private chat room with " + f"{pu.Puppet.get_displayname(user, False)}") @command_handler() @@ -116,9 +116,9 @@ async def delete_portal(evt): "action": "Portal deletion", } return await evt.reply("Please confirm deletion of portal " - + f"[{room_id}](https://matrix.to/#/{room_id}) " - + f"to Telegram chat \"{portal.title}\" " - + "by typing `$cmdprefix+sp confirm-delete`") + f"[{room_id}](https://matrix.to/#/{room_id}) " + f"to Telegram chat \"{portal.title}\" " + "by typing `$cmdprefix+sp confirm-delete`") @command_handler() @@ -183,16 +183,16 @@ async def create(evt): return await evt.reply("Please set a title before creating a Telegram chat.") elif (not levels or not levels["users"] or evt.az.intent.mxid not in levels["users"] or levels["users"][evt.az.intent.mxid] < 100): - return await evt.reply(f"Please give " - + f"[the bridge bot](https://matrix.to/#/{evt.az.intent.mxid})" - + f" a power level of 100 before creating a Telegram chat.") + return await evt.reply("Please give " + f"[the bridge bot](https://matrix.to/#/{evt.az.intent.mxid})" + " a power level of 100 before creating a Telegram chat.") else: for user, level in levels["users"].items(): if level >= 100 and user != evt.az.intent.mxid: return await evt.reply( f"Please make sure only the bridge bot has power level above" - + f"99 before creating a Telegram chat.\n\n" - + f"Use power level 95 instead of 100 for admins.") + f"99 before creating a Telegram chat.\n\n" + f"Use power level 95 instead of 100 for admins.") supergroup = type == "supergroup" type = { diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index f2f81426..8b4dd5e3 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -94,7 +94,7 @@ class Config(DictWithRecursion): self.set("appservice.hs_token", self._new_token()) url = (f"{self['appservice.protocol']}://" - + f"{self['appservice.hostname']}:{self['appservice.port']}") + f"{self['appservice.hostname']}:{self['appservice.port']}") self._registration = { "id": self.get("appservice.id", "telegram"), "as_token": self["appservice.as_token"], diff --git a/mautrix_telegram/db.py b/mautrix_telegram/db.py index fadd4559..20dff82b 100644 --- a/mautrix_telegram/db.py +++ b/mautrix_telegram/db.py @@ -48,7 +48,7 @@ class Message(Base): tgid = Column(Integer, primary_key=True) tg_space = Column(Integer, primary_key=True) - __table_args__ = (UniqueConstraint('mxid', 'mx_room', 'tg_space', name='_mx_id_room'),) + __table_args__ = (UniqueConstraint("mxid", "mx_room", "tg_space", name="_mx_id_room"),) class UserPortal(Base): diff --git a/mautrix_telegram/formatter.py b/mautrix_telegram/formatter.py index faa03799..1a21d68a 100644 --- a/mautrix_telegram/formatter.py +++ b/mautrix_telegram/formatter.py @@ -244,7 +244,7 @@ async def telegram_event_to_matrix(evt, source, native_replies=False, message_li if not fwd_from: fwd_from = "Unknown user" html = (f"Forwarded message from {fwd_from}
" - + f"
{html}
") + f"
{html}
") if evt.reply_to_msg_id: space = (evt.to_id.channel_id @@ -271,7 +271,7 @@ async def telegram_event_to_matrix(evt, source, native_replies=False, message_li displayname = puppet.displayname if puppet else sender reply_to_user = f"{displayname}" reply_to_msg = (("{reply_text}") + f"{msg.mx_room}/{msg.mxid}'>{reply_text}") if message_link_in_reply else "Reply") quote = f"{reply_to_msg} to {reply_to_user}
{body}
" except (ValueError, KeyError, MatrixRequestError): @@ -331,8 +331,8 @@ def _telegram_to_matrix(text, entities): elif entity_type == MessageEntityPre: if entity.language: html.append("
"
-                            + f"{entity_text}"
-                            + "
") + f"{entity_text}" + "") else: html.append(f"
{entity_text}
") elif entity_type == MessageEntityMention: diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py index 74ca003e..208cfa8c 100644 --- a/mautrix_telegram/matrix.py +++ b/mautrix_telegram/matrix.py @@ -60,8 +60,8 @@ class MatrixHandler: if len(members) > 1: await puppet.intent.error_and_leave(room, text=None, html=( f"Please invite " - + f"the bridge bot " - + f"first if you want to create a Telegram chat.")) + f"the bridge bot " + f"first if you want to create a Telegram chat.")) return await puppet.intent.join_room(room) @@ -71,9 +71,9 @@ class MatrixHandler: await puppet.intent.invite(portal.mxid, inviter.mxid) await puppet.intent.send_notice(room, text=None, html=( "You already have a private chat with me: " - + f"" - + "Link to room" - + "")) + f"" + "Link to room" + "")) await puppet.intent.leave_room(room) return except MatrixRequestError: diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index e25cd8fb..849be917 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -504,8 +504,8 @@ class Portal: type = "m.text" elif not sender.logged_in: if "formatted_body" in message: - message["formatted_body"] = \ - f"<{sender.displayname}> {message['formatted_body']}" + message["formatted_body"] = (f"<{sender.displayname}> " + f"{message['formatted_body']}") message["body"] = f"<{sender.displayname}> {message['body']}" if type == "m.text" or (self.bridge_notices and type == "m.notice"): diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 2a3637f4..336f0892 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -396,14 +396,12 @@ class User(AbstractUser): user = DBUser.query.get(mxid) if user: user = cls.from_db(user) - # asyncio.ensure_future(user.start(), loop=cls.loop) return user if create: user = cls(mxid) cls.db.add(user.to_db()) cls.db.commit() - # asyncio.ensure_future(user.start(), loop=cls.loop) return user return None @@ -418,7 +416,6 @@ class User(AbstractUser): user = DBUser.query.filter(DBUser.tgid == tgid).one_or_none() if user: user = cls.from_db(user) - # asyncio.ensure_future(user.start(), loop=cls.loop) return user return None diff --git a/setup.py b/setup.py index 6f02919e..2b78675c 100644 --- a/setup.py +++ b/setup.py @@ -17,12 +17,12 @@ setuptools.setup( install_requires=[ "aiohttp>=2.3.10,<3", - "SQLAlchemy>=1.2.2,<2", + "SQLAlchemy>=1.2.3,<2", "alembic>=0.9.7", "Markdown>=2.6.11,<3", "ruamel.yaml>=0.15.35,<0.16", "Pillow>=5.0.0,<6", - "future-fstrings>=0.4.1", + "future-fstrings>=0.4.2", "python-magic>=0.4.15,<0.5", ], dependency_links=[