From cd50bf5caae1fc1a61692174f5f7d0bb97d7eb57 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Sat, 13 Dec 2014 11:13:06 -0800 Subject: [PATCH] Less beeps! --- server.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 25483c0..4ff328d 100644 --- a/server.go +++ b/server.go @@ -16,6 +16,9 @@ import ( const MAX_NAME_LENGTH = 32 const HISTORY_LEN = 20 +const SYSTEM_MESSAGE_FORMAT string = "\033[1;3;90m" +const BEEP string = "\007" + var RE_STRIP_TEXT = regexp.MustCompile("[^0-9A-Za-z_.-]") type Clients map[string]*Client @@ -78,9 +81,8 @@ func (s *Server) Len() int { return len(s.clients) } -const SYSTEM_MESSAGE_FORMAT string = "\033[1;3;90m" func (s *Server) SysMsg(msg string, args ...interface{}) { - s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, " * " + fmt.Sprintf(msg, args...)), nil) + s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, " * "+fmt.Sprintf(msg, args...)), nil) } func (s *Server) Broadcast(msg string, except *Client) { @@ -92,8 +94,8 @@ func (s *Server) Broadcast(msg string, except *Client) { continue } /* Add an ascii BEL to ding clients when they're mentioned */ - if strings.Contains(msg, client.Name) { - client.Msg <- msg + "\007" + if strings.HasPrefix(msg, fmt.Sprintf("%s:", client.Name)) { + client.Msg <- msg + BEEP } else { client.Msg <- msg } @@ -108,7 +110,7 @@ func (s *Server) Privmsg(nick, message string, sender *Client) error { return fmt.Errorf("no client with that nick") } /* Send the message */ - target.Msg <- fmt.Sprintf("\007[PM from %v] %v", sender.Name, message) + target.Msg <- fmt.Sprintf(BEEP+"[PM from %v] %v", sender.Name, message) logger.Debugf("PM from %v to %v: %v", sender.Name, nick, message) return nil } @@ -131,7 +133,7 @@ func (s *Server) Add(client *Client) { s.clients[client.Name] = client num := len(s.clients) s.lock.Unlock() - + s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.ColoredName(), num)), client) }