Add a palette generator

and move inspiration into a subcommand
This commit is contained in:
Ninjdai1 2023-09-09 22:06:44 +02:00
parent f4a2a1f1eb
commit bb4f68a1c6
6 changed files with 154 additions and 5 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -0,0 +1,31 @@
const { SlashCommandBuilder } = require('discord.js');
const Inspiration = require('./graphismecommands/inspiration.js');
const Palette = require('./graphismecommands/palette.js')
module.exports = {
data: new SlashCommandBuilder()
.setName('graphisme')
.setDescription('Diverse commandes pour le graphisme.')
.addSubcommand(
subcommand =>
subcommand
.setName('inspiration')
.setDescription('Une citation, suggestion de couleur ou proposition de méthode.')
)
.addSubcommand(
subcommand =>
subcommand
.setName('palette')
.setDescription('Une palette harmonieuse générée aléatoirement.')
),
async execute(interaction) {
switch (interaction.options.getSubcommand()) {
case 'inspiration':
Inspiration.execute(interaction);
break;
case 'palette':
Palette.execute(interaction);
break;
}
}
};

View File

@ -1,9 +1,6 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js') const { EmbedBuilder } = require('discord.js')
module.exports = { module.exports = {
data: new SlashCommandBuilder()
.setName('inspiration')
.setDescription('Une citation, suggestion de couleur ou proposition de méthode'),
async execute(interaction){ async execute(interaction){
const randomIndex = Math.floor(Math.random() * inspirations.length); const randomIndex = Math.floor(Math.random() * inspirations.length);
const inspiration = inspirations[randomIndex]; const inspiration = inspirations[randomIndex];

View File

@ -0,0 +1,49 @@
const Canvas = require('canvas');
const { AttachmentBuilder } = require('discord.js')
module.exports = {
async execute(interaction){
await interaction.deferReply();
const palette = await generateRandomPalette();
const imageBuffer = await createPaletteImage(palette);
// Envoie l'image dans le canal où la commande a été appelée
const attachment = new AttachmentBuilder(imageBuffer, { name: 'palette.png' });
interaction.editReply({content: `Voici une proposition de palette :\n${palette.toString()}`, files: [attachment]});
}
}
// Fonction pour générer une palette de couleurs harmonieuses
async function generateRandomPalette() {
const numColors = Math.floor(Math.random() * 3) + 3; // Génère entre 3 et 5 couleurs
const palette = [];
// Générateur de couleurs harmonieuses (complémentaires)
const baseColor = Math.floor(Math.random() * 16777215); // Couleur de base aléatoire
for (let i = 0; i < numColors; i++) {
// Random variations in saturation and brightness
const hue = (baseColor + i * (360 / numColors)) % 360; // Répartition équilibrée des couleurs
const saturation = Math.random() * 40 + 50; // Random saturation between 50% and 90%
const brightness = Math.random() * 40 + 50; // Random brightness between 50% and 90%
const color = `hsl(${hue + i * (360 / numColors)}, ${saturation}%, ${brightness}%)`;
palette.push(color);
}
return palette;
}
// Fonction pour créer une image représentant la palette de couleurs
async function createPaletteImage(colors) {
const canvas = Canvas.createCanvas(200, 50);
const ctx = canvas.getContext('2d');
// Dessine les rectangles de couleur sur le canvas
for (let i = 0; i < colors.length; i++) {
ctx.fillStyle = colors[i];
ctx.fillRect(i * 40, 0, 40, 50);
}
return canvas.toBuffer(); // Convertit le canvas en un buffer d'image
}

71
package-lock.json generated
View File

@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@discordjs/rest": "^1.5.0", "@discordjs/rest": "^1.5.0",
"canvas": "^2.11.2",
"discord.js": "^14.13.0", "discord.js": "^14.13.0",
"moment-duration-format": "^2.3.2", "moment-duration-format": "^2.3.2",
"sequelize": "^6.32.1", "sequelize": "^6.32.1",
@ -424,6 +425,20 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/canvas": {
"version": "2.11.2",
"resolved": "https://registry.npmjs.org/canvas/-/canvas-2.11.2.tgz",
"integrity": "sha512-ItanGBMrmRV7Py2Z+Xhs7cT+FNt5K0vPL4p9EZ/UX/Mu7hFbkxSjKF2KVtPwX7UYWp7dRKnrTvReflgrItJbdw==",
"hasInstallScript": true,
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"nan": "^2.17.0",
"simple-get": "^3.0.3"
},
"engines": {
"node": ">=6"
}
},
"node_modules/chownr": { "node_modules/chownr": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
@ -475,6 +490,17 @@
} }
} }
}, },
"node_modules/decompress-response": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
"integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==",
"dependencies": {
"mimic-response": "^2.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/delegates": { "node_modules/delegates": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
@ -899,6 +925,17 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/mimic-response": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==",
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@ -1038,6 +1075,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}, },
"node_modules/nan": {
"version": "2.17.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz",
"integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ=="
},
"node_modules/negotiator": { "node_modules/negotiator": {
"version": "0.6.3", "version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
@ -1416,6 +1458,35 @@
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
}, },
"node_modules/simple-concat": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/simple-get": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz",
"integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==",
"dependencies": {
"decompress-response": "^4.2.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
}
},
"node_modules/smart-buffer": { "node_modules/smart-buffer": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",

View File

@ -26,6 +26,7 @@
"homepage": "https://github.com/Art-Portal/April#readme", "homepage": "https://github.com/Art-Portal/April#readme",
"dependencies": { "dependencies": {
"@discordjs/rest": "^1.5.0", "@discordjs/rest": "^1.5.0",
"canvas": "^2.11.2",
"discord.js": "^14.13.0", "discord.js": "^14.13.0",
"moment-duration-format": "^2.3.2", "moment-duration-format": "^2.3.2",
"sequelize": "^6.32.1", "sequelize": "^6.32.1",