From 5b75615b9053079a513f9ee75ecdf5c09b4e2592 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sun, 10 Mar 2019 21:26:37 -0400 Subject: [PATCH] Fixup the random color code Don't allow the user to randomize their color if it was previously changed by an mod. And don't change to a random color if an incorrect argument was given for the command. --- chatcommands.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/chatcommands.go b/chatcommands.go index 4cc4b9e..bf25d0e 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -224,17 +224,23 @@ func cmdColor(cl *Client, args []string) string { return fmt.Sprintf("Color changed for user %s to %s\n", name, color) } - // Change the color of the user - if len(args) == 0 || !colorRegex.MatchString(args[0]) { - cl.color = randomColor() - return "Random color chosen. To choose a specific color use the format /color #c029ce. Hex values expected." - } - + // Don't allow an unprivilaged user to change their color if + // it was changed by a mod if cl.IsColorForced { fmt.Printf("[color] %s tried to change a forced color\n", cl.name) return "You are not allowed to change your color." } + if len(args) == 0 { + cl.color = randomColor() + return "Random color chosen: " + cl.color + } + + // Change the color of the user + if !colorRegex.MatchString(args[0]) { + return "To choose a specific color use the format /color #c029ce. Hex values expected." + } + cl.color = args[0] fmt.Printf("[color] %s new color: %s\n", cl.name, cl.color) return "Color changed successfully."