Skip to content

Commit

Permalink
move palette parts into separate field
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Nov 2, 2023
1 parent d17c40d commit aa10ad4
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/helpers/images/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function palette(origin: ImageSource) {

// avoid transparent colors
if (!a) continue;
let hex = new ColorManager({ rgb: { r, g, b } }).toHEX().value;
const hex = new ColorManager({ rgb: { r, g, b } }).toHEX().value;

if (!(hex in allColors)) allColors[hex] = { hex, opacity: [], rgb: [r, g, b], count: 0 };

Expand All @@ -68,7 +68,9 @@ export async function palette(origin: ImageSource) {
.slice(0, COLORS_TOP)
.map((el) => el.hex);

const embed = new EmbedBuilder().setTitle("Palette results").setDescription("List of colors:\n");
const embed = new EmbedBuilder()
.setTitle("Palette results")
.setDescription(`Total: ${Object.keys(allColors).length}`);

const fieldGroups: string[][][] = [];
let group: number;
Expand All @@ -93,6 +95,7 @@ export async function palette(origin: ImageSource) {
line.map((color: string) => `[\`#${color}\`](${COOLORS_URL}${color})`).join(" "),
)
.join(" ");

embed.addFields({
name: "Hex" + (fieldGroups.length > 1 ? ` part ${index + 1}` : "") + ": ",
value: groupValue,
Expand All @@ -110,25 +113,25 @@ export async function palette(origin: ImageSource) {

// create URLs
const paletteUrls: string[] = [];
let descriptionLength = embed.data.description.length;
let groupLength = 0;

for (let i = 0; i < paletteGroups.length; ++i) {
const link = `**[Palette${
paletteGroups.length > 1 ? " part " + (i + 1) : ""
}](${COOLORS_URL}${paletteGroups[i].join("-")})**`;

if (descriptionLength + link.length + 3 > 1024) break;
if (groupLength + link.length + 3 > 1024) break;

paletteUrls.push(link);
descriptionLength += link.length;
groupLength += link.length;
}

// add generate palette link && append palette to description
embed.setDescription(
`Total: ${Object.values(allColors).length}\n\n` +
embed.data.description +
paletteUrls.join(" - "),
);
// add field at top
embed.spliceFields(0, 0, {
name: "List of colors:",
value: paletteUrls.join(" - "),
inline: false,
});

// create gradient canvas for top GRADIENT_TOP colors
const bandWidth =
Expand Down

0 comments on commit aa10ad4

Please sign in to comment.