io.github.chikyukido.nyaapplet.commands.NyaImageCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of NyaApplet Show documentation
Show all versions of NyaApplet Show documentation
An applet that can send in anime pics from different sources.
package io.github.chikyukido.nyaapplet.commands;
import io.github.chikyukido.appletmanager.commands.SlashGroupCommand;
import io.github.chikyukido.nyaapplet.manager.NyaManager;
import lombok.RequiredArgsConstructor;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.awt.*;
/**
* @author Chikyu Kido
*/
@Component
@RequiredArgsConstructor
public class NyaImageCommand implements SlashGroupCommand {
private final NyaManager nyaManager;
@Value("${nya.embed.color:#556B2F}")
private String embedColor;
@Override
public void execute(SlashCommandInteractionEvent event) {
String type = event.getOption("type") == null ? "neko" : event.getOption("type").getAsString();
boolean nsfw = event.getOption("nsfw") != null && event.getOption("nsfw").getAsBoolean();
boolean ephemeral = event.getOption("ephemeral") != null && event.getOption("ephemeral").getAsBoolean();
String url = nyaManager.getImageUrl(type, nsfw);
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(Color.decode(embedColor));
builder.setTitle("Type: " + type + " Nsfw: " + nsfw);
if (url != null) builder.setImage(url);
else builder.setDescription("No image found");
builder.setFooter("Requested by " + event.getUser().getName(), event.getUser().getAvatarUrl());
event.replyEmbeds(builder.build()).setEphemeral(ephemeral).queue();
}
@Override
public SubcommandData getCommandData() {
return new SubcommandData("img", "Get a random anime image")
.addOption(OptionType.BOOLEAN, "nsfw", "if the image should be nsfw", false)
.addOption(OptionType.STRING, "type", "the type of the image", false, true)
.addOption(OptionType.BOOLEAN, "ephemeral", "Whether only you should see the picture", false);
}
}