From fcdf98eda203c7cea76de8d49a4b65bcf75412dc Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 May 2012 02:07:48 +0200 Subject: [PATCH] Add a /ban command, and fix completion & parameters for /kick --- src/tabs.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index 86fedb33..2b77961a 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -602,17 +602,18 @@ class MucTab(ChatTab): # commands self.commands['ignore'] = (self.command_ignore, _("Usage: /ignore \nIgnore: Ignore a specified nickname."), self.completion_ignore) self.commands['unignore'] = (self.command_unignore, _("Usage: /unignore \nUnignore: Remove the specified nickname from the ignore list."), self.completion_unignore) - self.commands['kick'] = (self.command_kick, _("Usage: /kick [reason]\nKick: Kick the user with the specified nickname. You also can give an optional reason."), self.completion_ignore) + self.commands['kick'] = (self.command_kick, _("Usage: /kick [reason]\nKick: Kick the user with the specified nickname. You also can give an optional reason."), self.completion_quoted) + self.commands['ban'] = (self.command_ban, _("Usage: /ban [reason]\nBan: ban the user with the specified nickname. You also can give an optional reason."), self.completion_quoted) self.commands['role'] = (self.command_role, _("Usage: /role [reason]\nRole: Set the role of an user. Roles can be: none, visitor, participant, moderator. You also can give an optional reason."), self.completion_role) self.commands['affiliation'] = (self.command_affiliation, _("Usage: /affiliation \nAffiliation: Set the affiliation of an user. Affiliations can be: outcast, none, member, admin, owner."), self.completion_affiliation) self.commands['topic'] = (self.command_topic, _("Usage: /topic \nTopic: Change the subject of the room."), self.completion_topic) - self.commands['query'] = (self.command_query, _('Usage: /query [message]\nQuery: Open a private conversation with . This nick has to be present in the room you\'re currently in. If you specified a message after the nickname, it will immediately be sent to this user.'), self.completion_ignore) + self.commands['query'] = (self.command_query, _('Usage: /query [message]\nQuery: Open a private conversation with . This nick has to be present in the room you\'re currently in. If you specified a message after the nickname, it will immediately be sent to this user.'), self.completion_quoted) self.commands['part'] = (self.command_part, _("Usage: /part [message]\nPart: Disconnect from a room. You can specify an optional message."), None) self.commands['close'] = (self.command_close, _("Usage: /close [message]\nClose: Disconnect from a room and close the tab. You can specify an optional message if you are still connected."), None) self.commands['nick'] = (self.command_nick, _("Usage: /nick \nNick: Change your nickname in the current room."), self.completion_nick) self.commands['recolor'] = (self.command_recolor, _('Usage: /recolor\nRecolor: Re-assign a color to all participants of the current room, based on the last time they talked. Use this if the participants currently talking have too many identical colors.'), self.completion_recolor) self.commands['cycle'] = (self.command_cycle, _('Usage: /cycle [message]\nCycle: Leave the current room and rejoin it immediately.'), None) - self.commands['info'] = (self.command_info, _('Usage: /info \nInfo: Display some information about the user in the MUC: its/his/her role, affiliation, status and status message.'), self.completion_ignore) + self.commands['info'] = (self.command_info, _('Usage: /info \nInfo: Display some information about the user in the MUC: its/his/her role, affiliation, status and status message.'), None) self.commands['configure'] = (self.command_configure, _('Usage: /configure\nConfigure: Configure the current room, through a form.'), None) self.commands['version'] = (self.command_version, _('Usage: /version \nVersion: Get the software version of the given JID or nick in room (usually its XMPP client and Operating System).'), self.completion_version) self.commands['names'] = (self.command_names, _('Usage: /names\nNames: Get the list of the users in the room, and the list of the people assuming the different roles.'), None) @@ -908,6 +909,12 @@ class MucTab(ChatTab): current_topic = self.topic return the_input.auto_completion([current_topic], '', quotify=False) + def completion_quoted(self, the_input): + compare_users = lambda x: x.last_talked + word_list = [user.nick for user in sorted(self.users, key=compare_users, reverse=True)\ + if user.nick != self.own_nick] + return the_input.auto_completion(word_list, '', quotify=True) + def command_kick(self, arg): """ /kick [reason] @@ -917,11 +924,26 @@ class MucTab(ChatTab): self.core.command_help('kick') else: if len(args) > 1: - msg = ' '+args[1] + msg = ' "%s"' % args[1] else: msg = '' self.command_role('"'+args[0]+ '" none'+msg) + def command_ban(self, arg): + """ + /ban [reason] + """ + args = common.shell_split(arg) + if not args: + self.core.command_help('ban') + else: + if len(args) > 1: + msg = ' "%s"' %args[1] + else: + msg = '' + self.command_affiliation('"'+args[0]+ '" outcast'+msg) + + def command_role(self, arg): """ /role [reason]