Merge pull request #18 from Kealper/master

Make highlights stand out, re-fix empty message check, make colors seed only get set once
This commit is contained in:
Andrey Petrov 2014-12-13 15:38:02 -08:00
commit f25bbe9581
4 changed files with 16 additions and 7 deletions

View File

@ -341,7 +341,7 @@ func (c *Client) handleShell(channel ssh.Channel) {
c.Msg <- fmt.Sprintf("-> Rate limiting in effect.") c.Msg <- fmt.Sprintf("-> Rate limiting in effect.")
continue continue
} }
if c.IsSilenced() || len(msg) > 1000 || len(msg) == 0 { if c.IsSilenced() || len(msg) > 1000 || len(line) < 1 {
c.SysMsg("Message rejected.") c.SysMsg("Message rejected.")
continue continue
} }

3
cmd.go
View File

@ -36,6 +36,9 @@ func main() {
return return
} }
// Initialize seed for random colors
RandomColorInit()
// Figure out the log level // Figure out the log level
numVerbose := len(options.Verbose) numVerbose := len(options.Verbose)
if numVerbose > len(logLevels) { if numVerbose > len(logLevels) {

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"math/rand" "math/rand"
"time" "time"
) )
const RESET string = "\033[0m" const RESET string = "\033[0m"
@ -18,12 +18,10 @@ const INVERT string = "\033[7m"
var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" } var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" }
func RandomColor256() string { func RandomColor256() string {
rand.Seed(time.Now().UTC().UnixNano())
return fmt.Sprintf("38;05;%d", rand.Intn(256)) return fmt.Sprintf("38;05;%d", rand.Intn(256))
} }
func RandomColor() string { func RandomColor() string {
rand.Seed(time.Now().UTC().UnixNano())
return colors[rand.Intn(len(colors))] return colors[rand.Intn(len(colors))]
} }
@ -31,6 +29,10 @@ func ColorString(color string, msg string) string {
return BOLD + "\033[" + color + "m" + msg + RESET return BOLD + "\033[" + color + "m" + msg + RESET
} }
func RandomColorInit() {
rand.Seed(time.Now().UTC().UnixNano())
}
// Horrible hack to "continue" the previous string color and format // Horrible hack to "continue" the previous string color and format
// after a RESET has been encountered. // after a RESET has been encountered.
// This is not HTML where you can just do a </style> to resume your previous formatting! // This is not HTML where you can just do a </style> to resume your previous formatting!

View File

@ -91,9 +91,13 @@ func (s *Server) Broadcast(msg string, except *Client) {
continue continue
} }
if client.beepMe && strings.Contains(msg, client.Name) { if strings.Contains(msg, client.Name) {
/* Add an ascii BEL to ding clients when they're mentioned */ // Turn message red if client's name is mentioned, and send BEL if they have enabled beeping
client.Send(msg + BEEP) tmpMsg := strings.Split(msg, RESET)
if client.beepMe {
tmpMsg[0] += BEEP
}
client.Send(strings.Join(tmpMsg, RESET + BOLD + "\033[31m") + RESET)
} else { } else {
client.Send(msg) client.Send(msg)
} }