Add invert command & stop deferReply()

java-rewrite
Hammy 3 years ago
parent 699b8d69dd
commit 6b6cc315d7

@ -2,24 +2,56 @@ package me.goudham.bot.command.info.avatar;
import io.micronaut.context.annotation.Executable;
import jakarta.inject.Inject;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.imageio.ImageIO;
import me.goudham.command.annotation.Option;
import me.goudham.command.annotation.SlashCommand;
import me.goudham.command.annotation.SubCommand;
import me.goudham.service.EmbedService;
import me.goudham.service.ImageService;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
@SlashCommand(name = "avatar", description = "Display your avatar", isVisible = true, subCommandGroups = { "cool" })
public class Avatar {
private final EmbedService embedService;
private final ImageService imageService;
@Inject
public Avatar(EmbedService embedService) {
public Avatar(EmbedService embedService, ImageService imageService) {
this.embedService = embedService;
this.imageService = imageService;
}
@Executable
@SubCommand(
name = "invert",
description = "Display your or another member's avatar with a negative filter applied",
options = {
@Option(
optionType = OptionType.USER,
name = "member",
description = "A member within the server",
isRequired = false
)
}
)
public void invertCommand(SlashCommandEvent slashCommandEvent) throws IOException {
OptionMapping optionalUser = slashCommandEvent.getOption("member");
User user = optionalUser == null ? slashCommandEvent.getUser() : optionalUser.getAsUser();
BufferedImage inputImage = ImageIO.read(new URL(user.getEffectiveAvatarUrl()));
imageService.invertImage(inputImage);
InputStream byteArrayInputStream = new ByteArrayInputStream(imageService.toByteArray(inputImage, "png"));
slashCommandEvent.reply("**" + user.getName() + "'s Avatar\nFilter Applied -> Negative**").addFile(byteArrayInputStream, "invert.png").queue();
}
@Executable
@ -35,8 +67,15 @@ public class Avatar {
)
}
)
public void grayscaleCommand(SlashCommandEvent slashCommandEvent) {
public void grayscaleCommand(SlashCommandEvent slashCommandEvent) throws IOException {
OptionMapping optionalUser = slashCommandEvent.getOption("member");
User user = optionalUser == null ? slashCommandEvent.getUser() : optionalUser.getAsUser();
BufferedImage inputImage = ImageIO.read(new URL(user.getEffectiveAvatarUrl()));
BufferedImage grayscaleImage = imageService.toGrayscaleImage(inputImage);
InputStream byteArrayInputStream = new ByteArrayInputStream(imageService.toByteArray(grayscaleImage, "png"));
slashCommandEvent.reply("**" + user.getName() + "'s Avatar\nFilter Applied -> Grayscale**").addFile(byteArrayInputStream, "grayscale.png").queue();
}
@Executable
@ -53,9 +92,6 @@ public class Avatar {
}
)
public void defaultCommand(SlashCommandEvent slashCommandEvent) {
slashCommandEvent.deferReply(false).queue();
InteractionHook hook = slashCommandEvent.getHook();
OptionMapping optionalUser = slashCommandEvent.getOption("member");
User user = optionalUser == null ? slashCommandEvent.getUser() : optionalUser.getAsUser();
@ -64,6 +100,6 @@ public class Avatar {
.setImage(user.getEffectiveAvatarUrl() + "?size=4096")
.build();
hook.sendMessageEmbeds(avatarEmbed).queue();
slashCommandEvent.replyEmbeds(avatarEmbed).queue();
}
}

Loading…
Cancel
Save