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/user.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/user.py') diff --git a/src/user.py b/src/user.py index 8b4ad94b..b1796bc3 100644 --- a/src/user.py +++ b/src/user.py @@ -13,9 +13,13 @@ An user is a MUC participant, not a roster contact (see contact.py) from random import choice from datetime import timedelta, datetime from hashlib import md5 +import xhtml from theming import get_theme +import logging +log = logging.getLogger(__name__) + ROLE_DICT = { '':0, 'none':0, @@ -28,14 +32,17 @@ class User(object): """ keep trace of an user in a Room """ - def __init__(self, nick, affiliation, show, status, role, jid, deterministic=True): + def __init__(self, nick, affiliation, show, status, role, jid, deterministic=True, color=''): self.last_talked = datetime(1, 1, 1) # The oldest possible time self.update(affiliation, show, status, role) self.change_nick(nick) - if deterministic: - self.set_deterministic_color() + if color != '': + self.change_color(color, deterministic) else: - self.color = choice(get_theme().LIST_COLOR_NICKNAMES) + if deterministic: + self.set_deterministic_color() + else: + self.color = choice(get_theme().LIST_COLOR_NICKNAMES) self.jid = jid self.chatstate = None @@ -56,6 +63,17 @@ class User(object): def change_nick(self, nick): self.nick = nick + def change_color(self, color_name, deterministic=False): + color = xhtml.colors.get(color_name) + if color == None: + log.error('Unknown color "%s"' % color_name) + if deterministic: + self.set_deterministic_color() + else: + self.color = choice(get_theme().LIST_COLOR_NICKNAMES) + else: + self.color = (color, -1) + def set_last_talked(self, time): """ time: datetime object -- cgit v1.2.3