From 3d8c91dcb087520bbcc15aafb48bce1df3b5b833 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 11 May 2013 00:33:06 +0200 Subject: Fix the reason in the ban message --- src/multiuserchat.py | 6 ++++++ src/tabs.py | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/multiuserchat.py b/src/multiuserchat.py index 386da341..013fd2cb 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -127,6 +127,12 @@ def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason item = ET.Element('{http://jabber.org/protocol/muc#admin}item', {'affiliation':affiliation, 'nick':nick}) else: item = ET.Element('{http://jabber.org/protocol/muc#admin}item', {'affiliation':affiliation, 'jid':str(jid)}) + + if reason: + reason_item = ET.Element('{http://jabber.org/protocol/muc#admin}reason') + reason_item.text = reason + item.append(reason_item) + query.append(item) iq = xmpp.makeIqSet(query) iq['to'] = muc_jid diff --git a/src/tabs.py b/src/tabs.py index 8dfc8095..63c1558b 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1153,15 +1153,24 @@ class MucTab(ChatTab): """ /ban [reason] """ + def callback(iq): + if iq['type'] == 'error': + self.core.room_error(iq, self.get_name()) args = common.shell_split(arg) if not args: self.core.command_help('ban') + if len(args) > 1: + msg = args[1] else: - if len(args) > 1: - msg = ' "%s"' %args[1] - else: - msg = '' - self.command_affiliation('"'+args[0]+ '" outcast'+msg) + msg = '' + nick = args[0] + + if nick in [user.nick for user in self.users]: + res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), 'outcast', nick=nick, callback=callback, reason=msg) + else: + res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), 'outcast', jid=safeJID(nick), callback=callback, reason=msg) + if not res: + self.core.information('Could not ban user', 'Error') def command_role(self, arg): """ -- cgit v1.2.3