Less beeps!

This commit is contained in:
Andrey Petrov 2014-12-13 11:13:06 -08:00
parent fa224c8935
commit cd50bf5caa

View File

@ -16,6 +16,9 @@ import (
const MAX_NAME_LENGTH = 32 const MAX_NAME_LENGTH = 32
const HISTORY_LEN = 20 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_.-]") var RE_STRIP_TEXT = regexp.MustCompile("[^0-9A-Za-z_.-]")
type Clients map[string]*Client type Clients map[string]*Client
@ -78,7 +81,6 @@ func (s *Server) Len() int {
return len(s.clients) return len(s.clients)
} }
const SYSTEM_MESSAGE_FORMAT string = "\033[1;3;90m"
func (s *Server) SysMsg(msg string, args ...interface{}) { 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)
} }
@ -92,8 +94,8 @@ func (s *Server) Broadcast(msg string, except *Client) {
continue continue
} }
/* Add an ascii BEL to ding clients when they're mentioned */ /* Add an ascii BEL to ding clients when they're mentioned */
if strings.Contains(msg, client.Name) { if strings.HasPrefix(msg, fmt.Sprintf("%s:", client.Name)) {
client.Msg <- msg + "\007" client.Msg <- msg + BEEP
} else { } else {
client.Msg <- msg 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") return fmt.Errorf("no client with that nick")
} }
/* Send the message */ /* 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) logger.Debugf("PM from %v to %v: %v", sender.Name, nick, message)
return nil return nil
} }