From d0ea3f2ca6a7844afd647726fec4f14962b503da Mon Sep 17 00:00:00 2001 From: empathetic-alligator Date: Sun, 14 Dec 2014 11:04:29 -0500 Subject: [PATCH] Added comments and /shutdown command. --- client.go | 20 ++++++++++++++++++++ colors.go | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 827f436..ecf6292 100644 --- a/client.go +++ b/client.go @@ -308,6 +308,24 @@ func (c *Client) handleShell(channel ssh.Channel) { client.SysMsg("Silenced for %s by %s.", duration, c.ColoredName()) } } + case "/shutdown": + if !c.Server.IsOp(c) { + c.SysMsg("You're not an admin.") + } else { + var split []string = strings.SplitN(line, " ", 2) + var msg string + if len(split) > 1 { + msg = split[1] + } else { + msg = "" + } + // Shutdown after 5 seconds + go func() { + c.Server.Broadcast(ColorString("31", msg), nil) + time.Sleep(time.Second * 5) + c.Server.Stop() + }() + } case "/msg": /* Send a PM */ /* Make sure we have a recipient and a message */ if len(parts) < 2 { @@ -341,11 +359,13 @@ func (c *Client) handleShell(channel ssh.Channel) { c.SysMsg("Missing $THEME from: /theme $THEME") c.SysMsg("Choose either color or mono") } else { + // Sets colorMe attribute of client if parts[1] == "mono" { c.colorMe = false } else if parts[1] == "color" { c.colorMe = true } + // Rename to reset prompt c.Rename(c.Name) } diff --git a/colors.go b/colors.go index 29877d8..5f16a68 100644 --- a/colors.go +++ b/colors.go @@ -17,10 +17,11 @@ const BLINK string = "\033[5m" const INVERT string = "\033[7m" var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" } -var r *regexp.Regexp = regexp.MustCompile("\033\\[[\\d;]+m") +// For removing ANSI Escapes +var deColor *regexp.Regexp = regexp.MustCompile("\033\\[[\\d;]+m") func DeColorString(s string) string { - s = r.ReplaceAllString(s, "") + s = deColor.ReplaceAllString(s, "") return s }