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