Added multiple embed builders for multiple images

This commit is contained in:
Logan Cusano
2023-03-12 04:23:17 -04:00
parent fcf61f3958
commit cdb766520d
2 changed files with 28 additions and 14 deletions

View File

@@ -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
);
// 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

View File

@@ -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"];