From 0676cec53eec893030baf3df2a99baa2e5174607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 1 Mar 2022 00:37:19 +0100 Subject: [PATCH] impromptu: types, fstrings, naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/core/core.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/poezio/core/core.py b/poezio/core/core.py index d4ce6443..bc57024c 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -30,7 +30,7 @@ from typing import ( ) from xml.etree import ElementTree as ET -from slixmpp import JID, InvalidJID +from slixmpp import Iq, JID, InvalidJID from slixmpp.util import FileSystemPerJidCache from slixmpp.xmlstream.handler import Callback from slixmpp.exceptions import IqError, IqTimeout, XMPPError @@ -943,7 +943,7 @@ class Core: ) return True - def _impromptu_room_form(self, room): + def _impromptu_room_form(self, room) -> Iq: fields = [ ('hidden', 'FORM_TYPE', 'http://jabber.org/protocol/muc#roomconfig'), ('boolean', 'muc#roomconfig_changesubject', True), @@ -1009,12 +1009,12 @@ class Core: retries = 3 while retries > 0: localpart = utils.pronounceable() - room_str = '{!s}@{!s}'.format(localpart, default_muc + room_str = f'{localpart}@{default_muc}' try: room = JID(room_str) except InvalidJID: self.information( - 'The generated XMPP address is invalid: {!s}'.format(room_str), + f'The generated XMPP address is invalid: {room_str}', 'Error' ) return None @@ -1042,7 +1042,7 @@ class Core: self.open_new_room(room, self.own_nick).join() - async def join_callback(_presence): + async def configure_and_invite(_presence): iq = self._impromptu_room_form(room) try: await iq.send() @@ -1051,15 +1051,16 @@ class Core: # TODO: destroy? leave room. return None - self.information('Room %s created' % room, 'Info') + self.information(f'Room {room} created', 'Info') for jid in jids: await self.invite(jid, room, force_mediated=True) - self.information('Invited %s to %s' % (', '.join(jids), room.bare), 'Info') + jids_str = ', '.join(jids) + self.information(f'Invited {jids_str} to {room.bare}', 'Info') self.xmpp.add_event_handler( - 'muc::%s::groupchat_subject' % room.bare, - join_callback, + f'muc::{room.bare}::groupchat_subject', + configure_and_invite, disposable=True, )