v0.1.18 Expanded imageCommand functionality to include count and size

This commit is contained in:
2023-04-16 09:40:27 -04:00
parent 7e0a2a4e64
commit 9b605a3105
2 changed files with 15 additions and 3 deletions

View File

@@ -1 +1 @@
export SIREN_VERSION=0.1.17 export SIREN_VERSION=0.1.18

View File

@@ -17,20 +17,32 @@ public class ImageCommand extends Command {
super(listener); super(listener);
slashCommandData = Commands.slash("image", "Generate an image using DALL-E") slashCommandData = Commands.slash("image", "Generate an image using DALL-E")
.addOption(OptionType.STRING, "prompt", "The prompt for image generation", true) .addOption(OptionType.STRING, "prompt", "The prompt for image generation", true)
.addOption(OptionType.INTEGER, "count", "The number of images to be generated", false); .addOption(OptionType.INTEGER, "count", "The number of images to be generated", false)
.addOption(OptionType.INTEGER, "size", "Size of the picture, either 1 (small), 2 (medium), or 3 (large)", false);
} }
//TODO Store image in database
@Override @Override
public void execute(SlashCommandInteractionEvent event) throws IOException { public void execute(SlashCommandInteractionEvent event) throws IOException {
if (event.getUser().getId().equals(listener.getSettings().getOwner())) { if (event.getUser().getId().equals(listener.getSettings().getOwner())) {
String prompt = Objects.requireNonNull(event.getOption("prompt")).getAsString(); String prompt = Objects.requireNonNull(event.getOption("prompt")).getAsString();
int count = 1; int count = 1;
OptionMapping countOption = event.getOption("count"); OptionMapping countOption = event.getOption("count");
if (countOption != null) { if (countOption != null) {
count = countOption.getAsInt(); count = countOption.getAsInt();
} }
ImageSize size = ImageSize.SMALL;
OptionMapping sizeOption = event.getOption("size");
if (sizeOption != null) {
if (sizeOption.getAsInt() == 2) {
size = ImageSize.MEDIUM;
} else if (sizeOption.getAsInt() == 3) {
size = ImageSize.LARGE;
}
}
ImageResult result = listener.getOpenAIManager().createImage(prompt, count, ImageSize.SMALL); ImageResult result = listener.getOpenAIManager().createImage(prompt, count, size);
StringBuilder responseURLS = new StringBuilder(); StringBuilder responseURLS = new StringBuilder();
result.getData().forEach(image -> responseURLS.append(image.getUrl()).append("\n")); result.getData().forEach(image -> responseURLS.append(image.getUrl()).append("\n"));
event.getHook().sendMessage(responseURLS.toString()).queue(); event.getHook().sendMessage(responseURLS.toString()).queue();