From 206a9073f0c271ace9bfb1b4bfbc4ba3ed128de3 Mon Sep 17 00:00:00 2001 From: Steven L Date: Wed, 4 Oct 2017 13:20:01 -0400 Subject: [PATCH] Colorize /name output with selected theme (#249) * command.go: colorizing names according to theme (#205) * Adding safety check for nil and mono * Refactoring coloring into a function --- chat/command.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/chat/command.go b/chat/command.go index f6aa9bd..e84350b 100644 --- a/chat/command.go +++ b/chat/command.go @@ -173,9 +173,25 @@ func InitCommands(c *Commands) { Prefix: "/names", Help: "List users who are connected.", Handler: func(room *Room, msg message.CommandMsg) error { - // TODO: colorize - names := room.NamesPrefix("") - body := fmt.Sprintf("%d connected: %s", len(names), strings.Join(names, ", ")) + theme := msg.From().Config().Theme + + colorize := func(u *message.User) string { + return theme.ColorName(u) + } + + if theme == nil { + colorize = func(u *message.User) string { + return u.Name() + } + } + + names := room.Members.ListPrefix("") + colNames := make([]string, len(names)) + for i, uname := range names { + colNames[i] = colorize(uname.Value().(*Member).User) + } + + body := fmt.Sprintf("%d connected: %s", len(colNames), strings.Join(colNames, ", ")) room.Send(message.NewSystemMsg(body, msg.From())) return nil },