From 64a15df40cc3c70ff5b37f10b59b14c885e551c6 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 31 Jul 2024 21:59:57 -0600 Subject: [PATCH] misc.color: case for multiple colornames colors with the same name --- src/modules/misc.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/misc.js b/src/modules/misc.js index 3c55508..e55554f 100644 --- a/src/modules/misc.js +++ b/src/modules/misc.js @@ -645,7 +645,14 @@ color.callback = async function (msg, line, args, {truerandom}) { } if (!color.isValid) { - const colornamesHex = colornamesRaw.match(new RegExp(`^([0-9a-f]{6}),${line},`, "im"))?.[1]; + const search = `^([0-9a-f]{6}),${line},`; + const colornamesMatches = colornamesRaw.match(new RegExp(search, "img")); + if (colornamesMatches.length > 1) { + const hexes = colornamesMatches.map((m) => m.split(",")[0]); + return `Got ${colornamesMatches.length} matches for \`${safeString(line)}\`\n- ${hexes.join("\n- ")}`; + } + + const colornamesHex = colornamesRaw.match(new RegExp(search, "im"))?.[1]; if (colornamesHex) { color = tinycolor(colornamesHex); } else {