misc.color: use regex instead
This commit is contained in:
parent
1bef3d11a9
commit
f85e8c0215
1 changed files with 3 additions and 10 deletions
|
@ -630,14 +630,7 @@ searchInteraction.callback = async function (interaction) {
|
|||
};
|
||||
hf.registerCommand(searchInteraction);
|
||||
|
||||
const colornamesRaw = fs.readFileSync(resolve(__dirname, "../../data/colornames.csv"), "utf8").split("\n");
|
||||
colornamesRaw.shift();
|
||||
const colornamesMapped = colornamesRaw.map((line) => {
|
||||
const [hex, name] = line.split(",");
|
||||
|
||||
return [hex, name];
|
||||
});
|
||||
const colornames = Object.fromEntries(colornamesMapped);
|
||||
const colornamesRaw = fs.readFileSync(resolve(__dirname, "../../data/colornames.csv"), "utf8");
|
||||
|
||||
const color = new Command("color");
|
||||
color.category = CATEGORY;
|
||||
|
@ -652,7 +645,7 @@ color.callback = async function (msg, line, args, {truerandom}) {
|
|||
}
|
||||
|
||||
if (!color.isValid) {
|
||||
const colornamesHex = Object.entries(colornames).find(([hex, name]) => name.toLowerCase().localeCompare(line))[0];
|
||||
const colornamesHex = colornamesRaw.match(new RegExp(`^([0-9a-f]{6}),${line},`, "i"))?.[1];
|
||||
if (colornamesHex) {
|
||||
color = tinycolor(colornamesHex);
|
||||
} else {
|
||||
|
@ -708,7 +701,7 @@ color.callback = async function (msg, line, args, {truerandom}) {
|
|||
});
|
||||
}
|
||||
|
||||
const colornamesName = colornames[color.toHex()];
|
||||
const colornamesName = colornamesRaw.match(new RegExp(`^${color.toHex()},([^,]+?),`, "i"))?.[1];
|
||||
if (colornamesName) {
|
||||
fields.push({name: "\u200b", value: `**[colornames](https://colornames.org/) Name**\n${colornamesName}`});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue