misc.color: i hate my own command parser

This commit is contained in:
Cynthia Foxwell 2024-07-31 22:19:06 -06:00
parent c53c545c48
commit b5250cc573

View file

@ -636,16 +636,17 @@ const color = new Command("color");
color.category = CATEGORY; color.category = CATEGORY;
color.helpText = "Show information on a color or get a random color"; color.helpText = "Show information on a color or get a random color";
color.callback = async function (msg, line, args, {truerandom, first}) { color.callback = async function (msg, line, args, {truerandom, first}) {
let color = tinycolor(line), const query = args.join(" ");
let color = tinycolor(query),
random = false; random = false;
if (!line || line == "") { if (!query || query == "") {
color = truerandom ? tinycolor(Math.floor(Math.random() * 0xffffff)) : randomColor(); color = truerandom ? tinycolor(Math.floor(Math.random() * 0xffffff)) : randomColor();
random = true; random = true;
} }
if (!color.isValid) { if (!color.isValid) {
const search = `^([0-9a-f]{6}),${line},`; const search = `^([0-9a-f]{6}),${query},`;
if (!first) { if (!first) {
const colornamesMatches = colornamesRaw.match(new RegExp(search, "img")); const colornamesMatches = colornamesRaw.match(new RegExp(search, "img"));
if (colornamesMatches.length > 1) { if (colornamesMatches.length > 1) {
@ -662,7 +663,7 @@ color.callback = async function (msg, line, args, {truerandom, first}) {
text: `Picked #${random} for embed color \u2022 Use \`--first\` or the \`first\` option to bypass this`, text: `Picked #${random} for embed color \u2022 Use \`--first\` or the \`first\` option to bypass this`,
}, },
fields: [ fields: [
{name: `Got ${colornamesMatches.length} matches for \`${safeString(line)}\``, value: left, inline: true}, {name: `Got ${colornamesMatches.length} matches for \`${safeString(query)}\``, value: left, inline: true},
{name: "\u200b", value: right, inline: true}, {name: "\u200b", value: right, inline: true},
], ],
}, },