From f7e7836f977555bd589b693947b8e4d06c1134b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Mon, 22 Dec 2014 18:47:25 +0100 Subject: Add a /color command to fix color for a nick --- src/tabs/muctab.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/tabs') diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 72478bd4..160c4b0e 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -158,6 +158,11 @@ class MucTab(ChatTab): ' for a non-deterministic result.'), shortdesc=_('Change the nicks colors.'), completion=self.completion_recolor) + self.register_command('color', self.command_color, + usage=_(' '), + desc=_('Fix a color for a nick.'), + shortdesc=_('Fix a color for a nick.'), + completion=self.completion_color) self.register_command('cycle', self.command_cycle, usage=_('[message]'), desc=_('Leave the current room and rejoin it immediately.'), @@ -261,6 +266,19 @@ class MucTab(ChatTab): return the_input.new_completion(['random'], 1, '', quotify=False) return True + def completion_color(self, the_input): + """Completion for /color""" + n = the_input.get_argument_position(quoted=True) + if n == 1: + userlist = [user.nick for user in self.users] + if self.own_nick in userlist: + userlist.remove(self.own_nick) + return the_input.new_completion(userlist, 1, '', quotify=True) + elif n == 2: + colors = [i for i in xhtml.colors if i] + colors.sort() + return the_input.new_completion(colors, 2, '', quotify=False) + def completion_ignore(self, the_input): """Completion for /ignore""" userlist = [user.nick for user in self.users] @@ -432,6 +450,31 @@ class MucTab(ChatTab): self.text_win.refresh() self.input.refresh() + @command_args_parser.quoted(2, 2, ['']) + def command_color(self, args): + """ + /color + Fix a color for a nick. + """ + if args is None: + return self.core.command_help('color') + nick = args[0] + color = args[1].lower() + user = self.get_user_by_name(nick) + if not user: + return self.core.information(_("Unknown user: %s") % nick) + if not color in xhtml.colors: + return self.core.information(_("Unknown color: %s") % color, 'Error') + if user.nick == self.own_nick: + return self.core.information(_("You cannot change the color of your" + " own nick.", 'Error')) + colors = list(get_theme().LIST_COLOR_NICKNAMES) + user.color = (xhtml.colors[color], -1) + self.text_win.rebuild_everything(self._text_buffer) + self.user_win.refresh(self.users) + self.text_win.refresh() + self.input.refresh() + @command_args_parser.quoted(1) def command_version(self, args): """ -- cgit v1.2.3 From 251a10ab0d78ef9f4f68fc59ab41e064466d9145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 23 Dec 2014 16:01:58 +0100 Subject: Add a muc_color section in the config file to permanently fix a color to a nick --- src/tabs/muctab.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/tabs') diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 160c4b0e..b9dba7ab 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -424,6 +424,9 @@ class MucTab(ChatTab): for user in self.users: if user.nick == self.own_nick: continue + color = config.get_by_tabname(user.nick, 'muc_colors') + if color != '': + continue user.set_deterministic_color() if args[0] == 'random': self.core.information(_('"random" was provided, but poezio is ' @@ -435,11 +438,17 @@ class MucTab(ChatTab): compare_users = lambda x: x.last_talked users = list(self.users) sorted_users = sorted(users, key=compare_users, reverse=True) + full_sorted_users = sorted_users[:] # search our own user, to remove it from the list - for user in sorted_users: + # Also remove users whose color is fixed + for user in full_sorted_users: + color = config.get_by_tabname(user.nick, 'muc_colors') if user.nick == self.own_nick: sorted_users.remove(user) user.color = get_theme().COLOR_OWN_NICK + elif color != '': + sorted_users.remove(user) + user.change_color(color, deterministic) colors = list(get_theme().LIST_COLOR_NICKNAMES) if args[0] == 'random': random.shuffle(colors) @@ -468,8 +477,8 @@ class MucTab(ChatTab): if user.nick == self.own_nick: return self.core.information(_("You cannot change the color of your" " own nick.", 'Error')) - colors = list(get_theme().LIST_COLOR_NICKNAMES) - user.color = (xhtml.colors[color], -1) + user.change_color(color) + config.write_in_file('muc_colors', nick, color) self.text_win.rebuild_everything(self._text_buffer) self.user_win.refresh(self.users) self.text_win.refresh() @@ -1052,12 +1061,13 @@ class MucTab(ChatTab): jid = presence['muc']['jid'] typ = presence['type'] deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) + color = config.get_by_tabname(from_nick, 'muc_colors') if not self.joined: # user in the room BEFORE us. # ignore redondant presence message, see bug #1509 if (from_nick not in [user.nick for user in self.users] and typ != "unavailable"): new_user = User(from_nick, affiliation, show, - status, role, jid, deterministic) + status, role, jid, deterministic, color) self.users.append(new_user) self.core.events.trigger('muc_join', presence, self) if '110' in status_codes or self.own_nick == from_nick: @@ -1134,7 +1144,7 @@ class MucTab(ChatTab): if not user: self.core.events.trigger('muc_join', presence, self) self.on_user_join(from_nick, affiliation, show, status, role, - jid) + jid, color) # nick change elif change_nick: self.core.events.trigger('muc_nickchange', presence, self) @@ -1189,13 +1199,13 @@ class MucTab(ChatTab): typ=2) self.disconnect() - def on_user_join(self, from_nick, affiliation, show, status, role, jid): + def on_user_join(self, from_nick, affiliation, show, status, role, jid, color): """ When a new user joins the groupchat """ deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) user = User(from_nick, affiliation, - show, status, role, jid, deterministic) + show, status, role, jid, deterministic, color) self.users.append(user) hide_exit_join = config.get_by_tabname('hide_exit_join', self.general_jid) @@ -1236,6 +1246,12 @@ class MucTab(ChatTab): self.own_nick = new_nick # also change our nick in all private discussions of this room self.core.on_muc_own_nickchange(self) + else: + color = config.get_by_tabname(new_nick, 'muc_colors') + if color != '': + deterministic = config.get_by_tabname('deterministic_nick_colors', + self.name) + user.change_color(color, deterministic) user.change_nick(new_nick) if config.get_by_tabname('display_user_color_in_join_part', -- cgit v1.2.3 From 1bbdab7f12df2f1cd71db86ba6caf6c888e2a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 23 Dec 2014 16:43:40 +0100 Subject: Unset color with /color unset --- src/tabs/muctab.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/tabs') diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index b9dba7ab..89cecca8 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -160,7 +160,8 @@ class MucTab(ChatTab): completion=self.completion_recolor) self.register_command('color', self.command_color, usage=_(' '), - desc=_('Fix a color for a nick.'), + desc=_('Fix a color for a nick. Use "unset" instead of a color' + ' to remove the attribution'), shortdesc=_('Fix a color for a nick.'), completion=self.completion_color) self.register_command('cycle', self.command_cycle, @@ -277,6 +278,7 @@ class MucTab(ChatTab): elif n == 2: colors = [i for i in xhtml.colors if i] colors.sort() + colors.append('unset') return the_input.new_completion(colors, 2, '', quotify=False) def completion_ignore(self, the_input): @@ -464,6 +466,7 @@ class MucTab(ChatTab): """ /color Fix a color for a nick. + Use "unset" instead of a color to remove the attribution """ if args is None: return self.core.command_help('color') @@ -472,17 +475,21 @@ class MucTab(ChatTab): user = self.get_user_by_name(nick) if not user: return self.core.information(_("Unknown user: %s") % nick) - if not color in xhtml.colors: + if not color in xhtml.colors and color != 'unset': return self.core.information(_("Unknown color: %s") % color, 'Error') if user.nick == self.own_nick: return self.core.information(_("You cannot change the color of your" " own nick.", 'Error')) - user.change_color(color) - config.write_in_file('muc_colors', nick, color) - self.text_win.rebuild_everything(self._text_buffer) - self.user_win.refresh(self.users) - self.text_win.refresh() - self.input.refresh() + if color == 'unset': + if config.remove_and_save(nick, 'muc_colors'): + self.core.information(_('Color for nick %s unset') % (nick)) + else: + user.change_color(color) + config.set_and_save(nick, color, 'muc_colors') + self.text_win.rebuild_everything(self._text_buffer) + self.user_win.refresh(self.users) + self.text_win.refresh() + self.input.refresh() @command_args_parser.quoted(1) def command_version(self, args): -- cgit v1.2.3 From 0ae1ee2fbf0b3b10fbaaa12e7f340f2aedce3621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 23 Dec 2014 18:20:33 +0100 Subject: Add nick_color_aliases (default: true), to look for color of aliases --- src/tabs/muctab.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/tabs') diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 89cecca8..7264569a 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -426,7 +426,7 @@ class MucTab(ChatTab): for user in self.users: if user.nick == self.own_nick: continue - color = config.get_by_tabname(user.nick, 'muc_colors') + color = self.search_for_color(user.nick) if color != '': continue user.set_deterministic_color() @@ -444,7 +444,7 @@ class MucTab(ChatTab): # search our own user, to remove it from the list # Also remove users whose color is fixed for user in full_sorted_users: - color = config.get_by_tabname(user.nick, 'muc_colors') + color = self.search_for_color(user.nick) if user.nick == self.own_nick: sorted_users.remove(user) user.color = get_theme().COLOR_OWN_NICK @@ -1068,7 +1068,7 @@ class MucTab(ChatTab): jid = presence['muc']['jid'] typ = presence['type'] deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) - color = config.get_by_tabname(from_nick, 'muc_colors') + color = self.search_for_color(from_nick) if not self.joined: # user in the room BEFORE us. # ignore redondant presence message, see bug #1509 if (from_nick not in [user.nick for user in self.users] @@ -1670,3 +1670,19 @@ class MucTab(ChatTab): self.core.refresh_window() else: # Re-send a self-ping in a few seconds self.enable_self_ping_event() + + def search_for_color(self, nick): + """ + Search for the color of a nick in the config file. + Also, look at the colors of its possible aliases if nick_color_aliases + is set. + """ + color = config.get_by_tabname(nick, 'muc_colors') + if color != '': + return color + nick_color_aliases = config.get_by_tabname('nick_color_aliases', self.name) + if nick_color_aliases: + nick_alias = re.sub('^_*', '', nick) + nick_alias = re.sub('_*$', '', nick_alias) + color = config.get_by_tabname(nick_alias, 'muc_colors') + return color -- cgit v1.2.3 From 9da530f8541ed96fe5fa7e3ff01df5290f511633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 23 Dec 2014 23:51:04 +0100 Subject: Make it possible to change the nick of a user not in the room, and change color of its aliases --- src/tabs/muctab.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/tabs') diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 7264569a..d567e364 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -473,19 +473,27 @@ class MucTab(ChatTab): nick = args[0] color = args[1].lower() user = self.get_user_by_name(nick) - if not user: - return self.core.information(_("Unknown user: %s") % nick) if not color in xhtml.colors and color != 'unset': return self.core.information(_("Unknown color: %s") % color, 'Error') - if user.nick == self.own_nick: + if user and user.nick == self.own_nick: return self.core.information(_("You cannot change the color of your" " own nick.", 'Error')) if color == 'unset': if config.remove_and_save(nick, 'muc_colors'): self.core.information(_('Color for nick %s unset') % (nick)) else: - user.change_color(color) + if user: + user.change_color(color) config.set_and_save(nick, color, 'muc_colors') + nick_color_aliases = config.get_by_tabname('nick_color_aliases', self.name) + if nick_color_aliases: + # if any user in the room has a nick which is an alias of the + # nick, update its color + for u in self.users: + nick_alias = re.sub('^_*', '', u.nick) + nick_alias = re.sub('_*$', '', nick_alias) + if nick_alias == nick: + u.change_color(color) self.text_win.rebuild_everything(self._text_buffer) self.user_win.refresh(self.users) self.text_win.refresh() -- cgit v1.2.3