# HG changeset patch # User Goffi # Date 1622735245 -7200 # Node ID f19718296c2016e6675cc598e0af929036d931f8 # Parent 53c1724a89ea32528e9505d661a998d76a5c75a6 plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands diff -r 53c1724a89ea -r f19718296c20 sat/plugins/plugin_xep_0045.py --- a/sat/plugins/plugin_xep_0045.py Thu Jun 03 15:40:57 2021 +0200 +++ b/sat/plugins/plugin_xep_0045.py Thu Jun 03 17:47:25 2021 +0200 @@ -720,12 +720,16 @@ self.text_cmds.feedBack(client, feedback, mess_data) return False - d = self.kick(client, nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) + reason = ' '.join(options[1:]) if len(options) > 1 else None + + d = self.kick(client, nick, mess_data["to"], {"reason": reason}) def cb(__): feedback_msg = _('You have kicked {}').format(nick) - if len(options) > 1: - feedback_msg += _(' for the following reason: {}').format(options[1]) + if reason is not None: + feedback_msg += _(' for the following reason: {reason}').format( + reason=reason + ) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb) @@ -744,17 +748,24 @@ entity_jid = jid.JID(jid_s).userhostJID() assert(entity_jid.user) assert(entity_jid.host) - except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError): - feedback = _("You must provide a valid JID to ban, like in '/ban contact@example.net'") + except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, + AssertionError): + feedback = _( + "You must provide a valid JID to ban, like in '/ban contact@example.net'" + ) self.text_cmds.feedBack(client, feedback, mess_data) return False - d = self.ban(client, entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}) + reason = ' '.join(options[1:]) if len(options) > 1 else None + + d = self.ban(client, entity_jid, mess_data["to"], {"reason": reason}) def cb(__): feedback_msg = _('You have banned {}').format(entity_jid) - if len(options) > 1: - feedback_msg += _(' for the following reason: {}').format(options[1]) + if reason is not None: + feedback_msg += _(' for the following reason: {reason}').format( + reason=reason + ) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb) @@ -791,7 +802,8 @@ d = self.affiliate(client, entity_jid, mess_data["to"], {'affiliation': affiliation}) def cb(__): - feedback_msg = _('New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation) + feedback_msg = _('New affiliation for {entity}: {affiliation}').format( + entity=entity_jid, affiliation=affiliation) self.text_cmds.feedBack(client, feedback_msg, mess_data) return True d.addCallback(cb) @@ -837,7 +849,8 @@ elif client.muc_service is not None: service = client.muc_service else: - msg = D_("No known default MUC service".format(unparsed)) + msg = D_("No known default MUC service {unparsed}").format( + unparsed=unparsed) self.text_cmds.feedBack(client, msg, mess_data) return False except jid.InvalidFormat: