From b7f05a8aafd87b103b2ee04540370baad94a9f5e Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 25 Nov 2011 11:54:15 +0100 Subject: =?UTF-8?q?/recolor=20now=20reloads=20OWN=5FNICK=5FCOLOR=20from=20?= =?UTF-8?q?the=20theme,=20and=20also=20add=20an=20option=20to=20make=20/re?= =?UTF-8?q?color=20choose=20random=20colors=20for=20others=E2=80=99=20nick?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tabs.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/tabs.py') diff --git a/src/tabs.py b/src/tabs.py index c97f8a9f..e67cf5b6 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -28,6 +28,7 @@ import string import common import core import singleton +import random import xhtml import weakref import timed_events @@ -535,7 +536,7 @@ class MucTab(ChatTab): 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.'), None) + 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['configure'] = (self.command_configure, _('Usage: /configure\nConfigure: Configure the current room, through a form.'), None) @@ -561,6 +562,9 @@ class MucTab(ChatTab): nicks.remove('') return the_input.auto_completion(nicks, '') + def completion_recolor(self, the_input): + return the_input.auto_completion(['random'], '') + def completion_ignore(self, the_input): """Completion for /ignore""" userlist = [user.nick for user in self.users] @@ -653,14 +657,20 @@ class MucTab(ChatTab): """ Re-assign color to the participants of the room """ + args = common.shell_split(arg) compare_users = lambda x: x.last_talked users = list(self.users) - # search our own user, to remove it from the room - for user in users: + sorted_users = sorted(users, key=compare_users, reverse=True) + if len(args) >= 1: + if args[0] == 'random': + random.shuffle(sorted_users) + # search our own user, to remove it from the list + for user in sorted_users: if user.nick == self.own_nick: - users.remove(user) + sorted_users.remove(user) + user.color = get_theme().COLOR_OWN_NICK nb_color = len(get_theme().LIST_COLOR_NICKNAMES) - for i, user in enumerate(sorted(users, key=compare_users, reverse=True)): + for i, user in enumerate(sorted_users): user.color = get_theme().LIST_COLOR_NICKNAMES[i % nb_color] self.text_win.rebuild_everything(self._text_buffer) self.text_win.refresh() -- cgit v1.2.3