changeset 3543:f19718296c20

plugin XEP-0045: fix "reason" parsing for /ban and /kick text commands
author Goffi <goffi@goffi.org>
date Thu, 03 Jun 2021 17:47:25 +0200 (2021-06-03)
parents 53c1724a89ea
children ae5f63e5ed2c
files sat/plugins/plugin_xep_0045.py
diffstat 1 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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: