71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
const { submitImagePromptTransaction } = 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
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('imagine')
|
|
.setDescription(`Submit an image generation prompt to DALL-E`)
|
|
.addStringOption(option =>
|
|
option.setName('prompt')
|
|
.setDescription('The prompt to be sent to DALL-E')
|
|
.setRequired(true))
|
|
.addBooleanOption(option =>
|
|
option.setName('public')
|
|
.setDescription("Set this to false if you would like the message to only be visible to you. *defaults to public*")
|
|
.setRequired(false))
|
|
.addNumberOption(option =>
|
|
option.setName('images')
|
|
.setDescription('The number of images you wish to generate [1 - 10] *(defaults to 1)*')
|
|
.setRequired(false))
|
|
.addStringOption(option =>
|
|
option.setName('size')
|
|
.setDescription('The size of the images to be generated *defaults to 256px*')
|
|
.addChoices(
|
|
{ name: '1024px - 1000 tokens', value: '1024x1024' },
|
|
{ name: '512px - 900 tokens', value: '512x512' },
|
|
{ name: '256px - 800 tokens', value: '256x256' },
|
|
)
|
|
.setRequired(false)),
|
|
example: "imagine [the sinking of the titanic on acid] [4] [", // Need to figure out the tokens
|
|
isPrivileged: false,
|
|
requiresTokens: true,
|
|
defaultTokenUsage: COST_OF_COMMAND,
|
|
deferInitialReply: true,
|
|
async execute(interaction) {
|
|
const promptText = interaction.options.getString('prompt');
|
|
const images = interaction.options.getNumber('images') ?? undefined;
|
|
const size = interaction.options.getString('size') ?? undefined;
|
|
const discordAccountId = interaction.member.id;
|
|
try {
|
|
submitImagePromptTransaction(promptText, discordAccountId, images, size, interaction, this, async (err, imageResults) => {
|
|
if (err) throw err;
|
|
|
|
log.DEBUG("Image Results: ", imageResults)
|
|
|
|
const dalleEmbed = new EmmeliaEmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.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
|
|
|
|
log.DEBUG("Images in the result: ", imagesInResult);
|
|
|
|
if (imagesInResult == 1) dalleEmbed.setImage(imageResults.results.data[0].url);
|
|
|
|
await interaction.editReply({ embeds: [dalleEmbed], ephemeral: false });
|
|
});
|
|
|
|
// Needs reply code to reply to the generation
|
|
}catch(err){
|
|
log.ERROR(err)
|
|
//await interaction.reply(err.toString());
|
|
}
|
|
}
|
|
}; |