Added DALL-E functionaity
This commit is contained in:
72
commands/imagine.js
Normal file
72
commands/imagine.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const { submitImagePromptTransaction } = require("../controllers/openAiController");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "chat");
|
||||
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
||||
|
||||
const COST_OF_COMMAND = 100
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('imagine')
|
||||
.setDescription(`Submit an image generation prompt to DALL-E, by default this command costs *${COST_OF_COMMAND}* tokens`)
|
||||
.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', value: '1024x1024' },
|
||||
{ name: '512px', value: '512x512' },
|
||||
{ name: '256px', 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, 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: `${this.defaultTokenUsage}`, inline: true })
|
||||
.setTimestamp()
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user