v0.1.18 Expanded imageCommand functionality to include count and size
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user