Added color names as possible arguements for /color
Did some linting fixing too. Closes #45
This commit is contained in:
parent
49e997c5ff
commit
1cfa040f7b
|
@ -3,14 +3,11 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/zorchenhimer/MovieNight/common"
|
||||
)
|
||||
|
||||
var colorRegex *regexp.Regexp = regexp.MustCompile(`^#[0-9A-Fa-f]{6}$`)
|
||||
|
||||
type CommandControl struct {
|
||||
user map[string]Command
|
||||
mod map[string]Command
|
||||
|
@ -375,14 +372,13 @@ var cmdColor = Command{
|
|||
color := ""
|
||||
name := ""
|
||||
for _, s := range args {
|
||||
if strings.HasPrefix(s, "#") {
|
||||
if common.IsValidColor(s) {
|
||||
color = s
|
||||
} else {
|
||||
name = s
|
||||
}
|
||||
}
|
||||
if color == "" {
|
||||
|
||||
fmt.Printf("[color:mod] %s missing color\n", cl.name)
|
||||
return "Missing color"
|
||||
}
|
||||
|
@ -406,7 +402,7 @@ var cmdColor = Command{
|
|||
}
|
||||
|
||||
// Change the color of the user
|
||||
if !colorRegex.MatchString(args[0]) {
|
||||
if !common.IsValidColor(args[0]) {
|
||||
return "To choose a specific color use the format <i>/color #c029ce</i>. Hex values expected."
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ func (cr *ChatRoom) Join(name, uid string) (*Client, error) {
|
|||
return nil, errors.New("connection is missing from temp connections")
|
||||
}
|
||||
|
||||
if len(name) < UsernameMinLength || len(name) > UsernameMaxLength || !common.IsValidName(name) {
|
||||
if len(name) < UsernameMinLength || len(name) > UsernameMaxLength ||
|
||||
!common.IsValidName(name) || common.IsValidColor(name) {
|
||||
return nil, UserFormatError{Name: name}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var colors = []string{
|
||||
"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure",
|
||||
"Beige", "Bisque", "Black", "BlanchedAlmond", "Blue",
|
||||
"BlueViolet", "Brown", "BurlyWood", "CadetBlue", "Chartreuse",
|
||||
"Chocolate", "Coral", "CornflowerBlue", "Cornsilk", "Crimson",
|
||||
"Cyan", "DarkBlue", "DarkCyan", "DarkGoldenRod", "DarkGray",
|
||||
"DarkGrey", "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen",
|
||||
"DarkOrange", "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen",
|
||||
"DarkSlateBlue", "DarkSlateGray", "DarkSlateGrey", "DarkTurquoise", "DarkViolet",
|
||||
"DeepPink", "DeepSkyBlue", "DimGray", "DimGrey", "DodgerBlue",
|
||||
"FireBrick", "FloralWhite", "ForestGreen", "Fuchsia", "Gainsboro",
|
||||
"GhostWhite", "Gold", "GoldenRod", "Gray", "Grey",
|
||||
"Green", "GreenYellow", "HoneyDew", "HotPink", "IndianRed",
|
||||
"Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush",
|
||||
"LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan",
|
||||
"LightGoldenRodYellow", "LightGray", "LightGrey", "LightGreen", "LightPink",
|
||||
"LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray", "LightSlateGrey",
|
||||
"LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen",
|
||||
"Magenta", "Maroon", "MediumAquaMarine", "MediumBlue", "MediumOrchid",
|
||||
"MediumPurple", "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise",
|
||||
"MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin",
|
||||
"NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab",
|
||||
"Orange", "OrangeRed", "Orchid", "PaleGoldenRod", "PaleGreen",
|
||||
"PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PeachPuff", "Peru",
|
||||
"Pink", "Plum", "PowderBlue", "Purple", "RebeccaPurple",
|
||||
"Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon",
|
||||
"SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver",
|
||||
"SkyBlue", "SlateBlue", "SlateGray", "SlateGrey", "Snow",
|
||||
"SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle",
|
||||
"Tomato", "Turquoise", "Violet", "Wheat", "White",
|
||||
"WhiteSmoke", "Yellow", "YellowGreen",
|
||||
}
|
||||
|
||||
// IsValidColor takes a string s and compares it against a list of css color names.
|
||||
// It also accepts hex codes in the form of #000 (RGB), to #00000000 (RRGGBBAA), with A
|
||||
// being the alpha value
|
||||
func IsValidColor(s string) bool {
|
||||
for _, c := range colors {
|
||||
if strings.ToLower(c) == strings.ToLower(s) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return regexp.MustCompile(`^#[0-9A-Fa-f]{6}$`).MatchString(s)
|
||||
}
|
|
@ -8,12 +8,16 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
var re_username *regexp.Regexp = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`)
|
||||
var usernameRegex *regexp.Regexp = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`)
|
||||
|
||||
// IsValidName checks that name is within the correct ranges, follows the regex defined
|
||||
// and is not a valid color name
|
||||
func IsValidName(name string) bool {
|
||||
return re_username.MatchString(name)
|
||||
return 3 <= len(name) && len(name) <= 36 &&
|
||||
usernameRegex.MatchString(name) && !IsValidColor(name)
|
||||
}
|
||||
|
||||
// RandomColor returns a hex color code
|
||||
func RandomColor() string {
|
||||
nums := []int32{}
|
||||
for i := 0; i < 6; i++ {
|
||||
|
|
|
@ -122,11 +122,12 @@ span.svmsg {
|
|||
}
|
||||
|
||||
#hidden:hover,
|
||||
#notifiyBox:hover~#hidden {
|
||||
#optionBox:hover~#hidden {
|
||||
display: unset;
|
||||
}
|
||||
|
||||
#notifiyBox {
|
||||
#optionBox,
|
||||
#notifyBox {
|
||||
color: var(--var-contrast-color);
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
|
|
|
@ -75,8 +75,8 @@ function closeChat() {
|
|||
|
||||
function join() {
|
||||
let name = $("#name").val();
|
||||
if (name.length < 3 || name.length > 36) {
|
||||
setNotifyBox("Please input a name between 3 and 36 characters");
|
||||
if (!isValidName(name)) {
|
||||
setNotifyBox("Please input a valid name");
|
||||
return;
|
||||
}
|
||||
if (!sendMessage($("#name").val())) {
|
||||
|
@ -102,8 +102,10 @@ function updateSuggestionCss(m) {
|
|||
}
|
||||
}
|
||||
|
||||
function setNotifyBox(msg = "Please hover to view options") {
|
||||
$("#notifiyBox").html(msg);
|
||||
function setNotifyBox(msg = "") {
|
||||
$("#notifyBox").html(msg);
|
||||
$("#notifyBox").hide();
|
||||
$("#notifyBox").show();
|
||||
}
|
||||
|
||||
// Button Wrapper Functions
|
||||
|
|
|
@ -43,9 +43,10 @@
|
|||
|
||||
{{ if .Chat }}
|
||||
<div id="chatwindow">
|
||||
<div id="notifyBox"></div>
|
||||
<div id="chat" style="display: none;">
|
||||
<input id="hiddenColorPicker" type="color" hidden />
|
||||
<div id="notifiyBox"></div>
|
||||
<div id="optionBox">Please hover to view options</div>
|
||||
<div id="hidden">
|
||||
<div id="chatButtons">
|
||||
<button class="button pretty-button" onclick="auth();">Auth</button>
|
||||
|
|
|
@ -259,6 +259,20 @@ func showSendError(err error) {
|
|||
}
|
||||
}
|
||||
|
||||
func isValidColor(this js.Value, v []js.Value) interface{} {
|
||||
if len(v) != 1 {
|
||||
return false
|
||||
}
|
||||
return common.IsValidColor(v[0].String())
|
||||
}
|
||||
|
||||
func isValidName(this js.Value, v []js.Value) interface{} {
|
||||
if len(v) != 1 {
|
||||
return false
|
||||
}
|
||||
return common.IsValidName(v[0].String())
|
||||
}
|
||||
|
||||
func debugValues(v []js.Value) {
|
||||
fmt.Printf("currentName %#v\n", currentName)
|
||||
fmt.Printf("names %#v\n", names)
|
||||
|
@ -268,6 +282,8 @@ func debugValues(v []js.Value) {
|
|||
func main() {
|
||||
js.Set("processMessageKey", js.FuncOf(processMessageKey))
|
||||
js.Set("sendMessage", js.FuncOf(send))
|
||||
js.Set("isValidColor", js.FuncOf(isValidColor))
|
||||
js.Set("isValidName", js.FuncOf(isValidName))
|
||||
|
||||
js.Set("recieveMessage", js.CallbackOf(recieve))
|
||||
js.Set("processMessage", js.CallbackOf(processMessage))
|
||||
|
|
Loading…
Reference in New Issue