From 9a2d14066ca3b8b30b26a80f631deee649267c90 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Sun, 14 Dec 2014 22:51:22 -0800 Subject: [PATCH] Removed dark names, dont color join mesages. --- colors.go | 13 ++++++++++++- server.go | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/colors.go b/colors.go index c0e5a0f..6bfc5ca 100644 --- a/colors.go +++ b/colors.go @@ -42,9 +42,20 @@ func DeColorString(s string) string { return s } +func randomReadableColor() int { + for { + i := rand.Intn(256) + if (16 <= i && i <= 18) || (232 <= i && i <= 237) { + // Remove the ones near black, this is kinda sadpanda. + continue + } + return i + } +} + // RandomColor256 returns a random (of 256) color func RandomColor256() string { - return fmt.Sprintf("38;05;%d", rand.Intn(256)) + return fmt.Sprintf("38;05;%d", randomReadableColor()) } // RandomColor returns a random color diff --git a/server.go b/server.go index c27a5c7..bd4230e 100644 --- a/server.go +++ b/server.go @@ -167,7 +167,7 @@ func (s *Server) Add(client *Client) { newName, err := s.proposeName(client.Name) if err != nil { - client.SysMsg("Your name '%s' is not available, renamed to '%s'. Use /nick to change it.", client.ColoredName(), ColorString(client.Color, newName)) + client.SysMsg("Your name '%s' is not available, renamed to '%s'. Use /nick to change it.", client.Name, ColorString(client.Color, newName)) } client.Rename(newName) @@ -175,7 +175,7 @@ func (s *Server) Add(client *Client) { num := len(s.clients) s.Unlock() - s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.ColoredName(), num)), client) + s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.Name, num)), client) } // Remove removes the given client from the list of clients @@ -184,7 +184,7 @@ func (s *Server) Remove(client *Client) { delete(s.clients, strings.ToLower(client.Name)) s.Unlock() - s.SysMsg("%s left.", client.ColoredName()) + s.SysMsg("%s left.", client.Name) } func (s *Server) proposeName(name string) (string, error) {