diff --git a/bun.lockb b/bun.lockb index ec684ef..0624747 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/commands/misc/graphisme.js b/commands/misc/graphisme.js new file mode 100644 index 0000000..a6ee48c --- /dev/null +++ b/commands/misc/graphisme.js @@ -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; + } + } +}; \ No newline at end of file diff --git a/commands/misc/inspiration.js b/commands/misc/graphismecommands/inspiration.js similarity index 92% rename from commands/misc/inspiration.js rename to commands/misc/graphismecommands/inspiration.js index 8c68b68..9686ff0 100644 --- a/commands/misc/inspiration.js +++ b/commands/misc/graphismecommands/inspiration.js @@ -1,9 +1,6 @@ -const { SlashCommandBuilder, EmbedBuilder } = require('discord.js') +const { EmbedBuilder } = require('discord.js') module.exports = { - data: new SlashCommandBuilder() - .setName('inspiration') - .setDescription('Une citation, suggestion de couleur ou proposition de méthode'), async execute(interaction){ const randomIndex = Math.floor(Math.random() * inspirations.length); const inspiration = inspirations[randomIndex]; diff --git a/commands/misc/graphismecommands/palette.js b/commands/misc/graphismecommands/palette.js new file mode 100644 index 0000000..1dfd99e --- /dev/null +++ b/commands/misc/graphismecommands/palette.js @@ -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 +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 75e0075..843512f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@discordjs/rest": "^1.5.0", + "canvas": "^2.11.2", "discord.js": "^14.13.0", "moment-duration-format": "^2.3.2", "sequelize": "^6.32.1", @@ -424,6 +425,20 @@ "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": { "version": "2.0.0", "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": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -899,6 +925,17 @@ "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": { "version": "3.1.2", "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", "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": { "version": "0.6.3", "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", "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": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", diff --git a/package.json b/package.json index 78862ca..cdd172b 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "homepage": "https://github.com/Art-Portal/April#readme", "dependencies": { "@discordjs/rest": "^1.5.0", + "canvas": "^2.11.2", "discord.js": "^14.13.0", "moment-duration-format": "^2.3.2", "sequelize": "^6.32.1", @@ -37,4 +38,4 @@ "peerDependencies": { "typescript": "^5.0.0" } -} \ No newline at end of file +}