Colorize the nicks when printing out messages.
This commit is contained in:
parent
97dbda95a7
commit
92b35dfd8c
2 changed files with 28 additions and 8 deletions
|
@ -24,12 +24,12 @@ from matrix.globals import W, OPTIONS
|
|||
from matrix.plugin_options import RedactType
|
||||
|
||||
from matrix.colors import Formatted
|
||||
from matrix.utils import (strip_matrix_server, color_for_tags, date_from_age,
|
||||
sender_to_nick_and_color, add_event_tags, sanitize_id,
|
||||
sanitize_age, sanitize_text, shorten_sender,
|
||||
add_user_to_nicklist, get_prefix_for_level,
|
||||
from matrix.utils import (
|
||||
strip_matrix_server, color_for_tags, date_from_age,
|
||||
sender_to_nick_and_color, add_event_tags, sanitize_id, sanitize_age,
|
||||
sanitize_text, shorten_sender, add_user_to_nicklist, get_prefix_for_level,
|
||||
sanitize_power_level, string_strikethrough,
|
||||
line_pointer_and_tags_from_event)
|
||||
line_pointer_and_tags_from_event, sender_to_prefix_and_color)
|
||||
|
||||
PowerLevel = namedtuple('PowerLevel', ['user', 'level'])
|
||||
|
||||
|
@ -273,7 +273,17 @@ class RoomMessageEvent(RoomEvent):
|
|||
|
||||
tags_string = ",".join(event_tags)
|
||||
|
||||
data = "{author}\t{msg}".format(author=nick, msg=message)
|
||||
prefix, prefix_color = sender_to_prefix_and_color(room, self.sender)
|
||||
|
||||
prefix_string = "{}{}{}".format(
|
||||
W.color(prefix_color), prefix, W.color("reset"))
|
||||
|
||||
data = "{prefix}{color}{author}{ncolor}\t{msg}".format(
|
||||
prefix=prefix_string,
|
||||
color=W.color(color_name),
|
||||
author=nick,
|
||||
ncolor=W.color("reset"),
|
||||
msg=message)
|
||||
|
||||
date = date_from_age(self.age)
|
||||
W.prnt_date_tags(buff, date, tags_string, data)
|
||||
|
|
|
@ -130,6 +130,16 @@ def shorten_sender(sender):
|
|||
return strip_matrix_server(sender)[1:]
|
||||
|
||||
|
||||
def sender_to_prefix_and_color(room, sender):
|
||||
if sender in room.users:
|
||||
user = room.users[sender]
|
||||
prefix = user.prefix
|
||||
prefix_color = get_prefix_color(prefix)
|
||||
return prefix, prefix_color
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
def sender_to_nick_and_color(room, sender):
|
||||
nick = sender
|
||||
nick_color_name = "default"
|
||||
|
@ -139,7 +149,7 @@ def sender_to_nick_and_color(room, sender):
|
|||
nick = (user.display_name if user.display_name else user.name)
|
||||
nick_color_name = user.nick_color
|
||||
else:
|
||||
nick = shorten_sender(sender)
|
||||
nick = sender
|
||||
nick_color_name = W.info_get("nick_color_name", nick)
|
||||
|
||||
return (nick, nick_color_name)
|
||||
|
|
Loading…
Add table
Reference in a new issue