From 4e2e8bc70290b2571662d532678ac0634e537e06 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 29 May 2023 08:47:07 -0400 Subject: [PATCH] Add size option and response embed for dall-e --- functions.js | 11 ++++++++++- slash-commands/dalle.js | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/functions.js b/functions.js index 3a0ebe2..6296e14 100644 --- a/functions.js +++ b/functions.js @@ -377,6 +377,14 @@ const functions = { interaction.reply({ embeds: [ strainEmbed ]}); }, + dalle(prompt, imageUrl) { + const dalleEmbed = new Discord.MessageEmbed() + .setAuthor({ name: "NodDraw" }) + .setTimestamp() + .setImage(imageUrl) + .setFooter({ text: prompt }); + return { embeds: [dalleEmbed] }; + } }, collect: { gifName(interaction) { @@ -561,11 +569,12 @@ const functions = { resolve(response); }); }, - imagePrompt(userPrompt, userId) { + imagePrompt(userPrompt, size, userId) { return new Promise(async (resolve, reject) => { try { const response = await openai.createImage({ prompt: userPrompt, + size: size, user: userId }); resolve(response.data.data[0].url); diff --git a/slash-commands/dalle.js b/slash-commands/dalle.js index eb97f9d..ccb1ad6 100644 --- a/slash-commands/dalle.js +++ b/slash-commands/dalle.js @@ -9,13 +9,25 @@ module.exports = { o.setName("prompt") .setDescription("Prompt to send to DALL-e") .setRequired(true) - ), + ) + .addStringOption(o => + o.setName("size") + .setDescription("1024x1024, 512x512, 256x256") + .setRequired(false) + .addChoices( + { name: "1024x1024 (2¢)", value: "1024x1024" }, + { name: "512x512 (1.8¢)", value: "512x512" }, + { name: "256x256 (1.6¢)", value: "256x256" } + )), async execute(interaction) { try { await interaction.deferReply(); const userPrompt = interaction.options.getString("prompt"); - const response = await fn.openAI.imagePrompt(userPrompt); - await interaction.editReply(`${response}`); + const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512"; + + const imageUrl = await fn.openAI.imagePrompt(userPrompt, size); + const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl); + await interaction.editReply(dalleEmbed); } catch (err) { const errorId = fn.generateErrorId(); console.error(`${errorId}: ${err}`);