in src/actions/Expand.ts [126:177]
async function performExpandAction(
interaction: MessageComponentInteraction,
step: number,
count: number
) {
if (step == 0 || interaction.message.embeds.length == 0) {
return;
}
const embed = interaction.message.embeds[0];
const images = await fetchImagesFromComposite(embed.image, count).catch(
console.error
);
const index = step - 1;
if (images == null || images.length <= index) {
interaction
.reply({
ephemeral: true,
content: "Failed to process images for Expand.",
})
.catch(console.error);
return;
}
await interaction.deferReply();
const prompt = embed.description ?? "";
const uuid = interaction.user.id;
const originalImage = images[index];
const expandedImage = await expandImage(originalImage);
const finalImage = expandedImage.toPngImageBuffer();
try {
const completion = await openai.images.edit(
finalImage,
finalImage,
prompt,
EXPAND_ACTION_NUM_IMAGES,
OPENAI_API_SIZE_ARG,
"b64_json"
);
const images = imagesFromBase64Response(completion.data);
// No reroll, if user wants to reroll they can go to the original
const response = await createResponse(prompt, images, [Save, Expand]);
interaction
.followUp({ ...response, content: `Expanded for <@${uuid}>! ðŸ”` })
.catch(console.error);
} catch (e) {
const response = processOpenAIError(e as any, prompt);
interaction.followUp({ ...response }).catch(console.error);
}
}