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.
This commit is contained in:
Zorchenhimer 2019-03-10 21:26:37 -04:00
parent 61643f579a
commit 5b75615b90

View File

@ -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 <i>/color #c029ce</i>. 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 <i>/color #c029ce</i>. Hex values expected."
}
cl.color = args[0]
fmt.Printf("[color] %s new color: %s\n", cl.name, cl.color)
return "Color changed successfully."