diff --git a/commands/imagine.js b/commands/imagine.js index 278d508..962bde0 100644 --- a/commands/imagine.js +++ b/commands/imagine.js @@ -1,10 +1,10 @@ -const { submitImagePromptTransaction } = require("../controllers/openAiController"); +const { submitImagePromptTransaction, DALLE_COLOR } = require("../controllers/openAiController"); const { SlashCommandBuilder } = require('discord.js'); const { DebugBuilder } = require("../utilities/debugBuilder"); const log = new DebugBuilder("server", "imagine"); const { EmmeliaEmbedBuilder } = require('../libUtils'); -const COST_OF_COMMAND = 800 +const COST_OF_COMMAND = 800; module.exports = { data: new SlashCommandBuilder() @@ -45,21 +45,31 @@ module.exports = { submitImagePromptTransaction(promptText, discordAccountId, images, size, interaction, this, async (err, imageResults) => { if (err) throw err; + var dalleEmbeds = []; log.DEBUG("Image Results: ", imageResults) - - const dalleEmbed = new EmmeliaEmbedBuilder() - .setColor(0x0099FF) + // Add the information post + dalleEmbeds.push(new EmmeliaEmbedBuilder() + .setColor(DALLE_COLOR) .setTitle(`New Image Result`) - .setDescription(`${interaction.member.user} sent the prompt: '${promptText}'`) - .addFields({ name: 'Tokens Used', value: `${imageResults.totalTokens}`, inline: true }) - - const imagesInResult = Array(imageResults.results.data).length - + .setDescription(`${interaction.member.user} sent the prompt: '${promptText}'`) + ); + // Add the images to the result + const imagesInResult = Array(imageResults.results).length log.DEBUG("Images in the result: ", imagesInResult); - - if (imagesInResult != 0) dalleEmbed.setImage(imageResults.results.data[0].url); - - await interaction.editReply({ embeds: [dalleEmbed], ephemeral: false }); + if (imagesInResult >= 1) { + for (const imageData of imageResults.results.data){ + const imageUrl = imageData.url; + dalleEmbeds.push(new EmmeliaEmbedBuilder().setURL(imageUrl).setImage(imageUrl).setColor(DALLE_COLOR)); + } + } + // Add the information post + dalleEmbeds.push(new EmmeliaEmbedBuilder() + .setColor(DALLE_COLOR) + .addFields({ name: 'Tokens Used', value: `${imageResults.totalTokens}`, inline: true }) + .addFields({ name: 'Images Generated', value: `${imagesInResult}`, inline: true }) + .addFields({ name: 'Image Size Requested', value: `${imagesInResult}`, inline: true }) + ); + await interaction.editReply({ embeds: dalleEmbeds, ephemeral: false }); }); // Needs reply code to reply to the generation diff --git a/controllers/openAiController.js b/controllers/openAiController.js index 3e70ccb..f4442d4 100644 --- a/controllers/openAiController.js +++ b/controllers/openAiController.js @@ -14,6 +14,10 @@ const configuration = new Configuration({ const openai = new OpenAIApi(configuration); +// Global Vars for Other functions +exports.DALLE_COLOR = 0x34c6eb; +exports.CHATGPT_COLOR = 0x34eb9b; + async function getImageGeneration(_prompt, { _images_to_generate = 1, _image_size = "256x256" }, callback){ const validImageSizes = ["256x256", "512x512", "1024x1024"];