Added multiple embed builders for multiple images
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
const { submitImagePromptTransaction } = require("../controllers/openAiController");
|
const { submitImagePromptTransaction, DALLE_COLOR } = require("../controllers/openAiController");
|
||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||||
const log = new DebugBuilder("server", "imagine");
|
const log = new DebugBuilder("server", "imagine");
|
||||||
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
||||||
|
|
||||||
const COST_OF_COMMAND = 800
|
const COST_OF_COMMAND = 800;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -45,21 +45,31 @@ module.exports = {
|
|||||||
submitImagePromptTransaction(promptText, discordAccountId, images, size, interaction, this, async (err, imageResults) => {
|
submitImagePromptTransaction(promptText, discordAccountId, images, size, interaction, this, async (err, imageResults) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
var dalleEmbeds = [];
|
||||||
log.DEBUG("Image Results: ", imageResults)
|
log.DEBUG("Image Results: ", imageResults)
|
||||||
|
// Add the information post
|
||||||
const dalleEmbed = new EmmeliaEmbedBuilder()
|
dalleEmbeds.push(new EmmeliaEmbedBuilder()
|
||||||
.setColor(0x0099FF)
|
.setColor(DALLE_COLOR)
|
||||||
.setTitle(`New Image Result`)
|
.setTitle(`New Image Result`)
|
||||||
.setDescription(`${interaction.member.user} sent the prompt: '${promptText}'`)
|
.setDescription(`${interaction.member.user} sent the prompt: '${promptText}'`)
|
||||||
.addFields({ name: 'Tokens Used', value: `${imageResults.totalTokens}`, inline: true })
|
);
|
||||||
|
// Add the images to the result
|
||||||
const imagesInResult = Array(imageResults.results.data).length
|
const imagesInResult = Array(imageResults.results).length
|
||||||
|
|
||||||
log.DEBUG("Images in the result: ", imagesInResult);
|
log.DEBUG("Images in the result: ", imagesInResult);
|
||||||
|
if (imagesInResult >= 1) {
|
||||||
if (imagesInResult != 0) dalleEmbed.setImage(imageResults.results.data[0].url);
|
for (const imageData of imageResults.results.data){
|
||||||
|
const imageUrl = imageData.url;
|
||||||
await interaction.editReply({ embeds: [dalleEmbed], ephemeral: false });
|
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
|
// Needs reply code to reply to the generation
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ const configuration = new Configuration({
|
|||||||
|
|
||||||
const openai = new OpenAIApi(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){
|
async function getImageGeneration(_prompt, { _images_to_generate = 1, _image_size = "256x256" }, callback){
|
||||||
const validImageSizes = ["256x256", "512x512", "1024x1024"];
|
const validImageSizes = ["256x256", "512x512", "1024x1024"];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user