misc.color: case for multiple colornames colors with the same name

This commit is contained in:
Cynthia Foxwell 2024-07-31 21:59:57 -06:00
parent 5248ef1f75
commit 64a15df40c

View file

@ -645,7 +645,14 @@ color.callback = async function (msg, line, args, {truerandom}) {
} }
if (!color.isValid) { 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) { if (colornamesHex) {
color = tinycolor(colornamesHex); color = tinycolor(colornamesHex);
} else { } else {