diff --git a/src/main/java/cc/fascinated/bat/command/impl/fun/image/DuckSubCommand.java b/src/main/java/cc/fascinated/bat/command/impl/fun/image/DuckSubCommand.java new file mode 100644 index 0000000..26d2121 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/impl/fun/image/DuckSubCommand.java @@ -0,0 +1,36 @@ +package cc.fascinated.bat.command.impl.fun.image; + +import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.CommandInfo; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.common.WebRequest; +import cc.fascinated.bat.model.BatGuild; +import cc.fascinated.bat.model.BatUser; +import cc.fascinated.bat.model.token.randomd.RandomDuck; +import cc.fascinated.bat.model.token.thecatapi.CatImageToken; +import lombok.NonNull; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +@CommandInfo(name = "duck", description = "Get a random duck image") +public class DuckSubCommand extends BatSubCommand { + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { + RandomDuck responseEntity = WebRequest.getAsEntity("https://random-d.uk/api/v2/random", RandomDuck.class); + if (responseEntity == null) { + interaction.reply("Failed to get a duck image!").queue(); + return; + } + + interaction.replyEmbeds(EmbedUtils.genericEmbed() + .setAuthor("Here's a random duck image!") + .setImage(responseEntity.getUrl()) + .build()).queue(); + } +} diff --git a/src/main/java/cc/fascinated/bat/command/impl/fun/image/ImageCommand.java b/src/main/java/cc/fascinated/bat/command/impl/fun/image/ImageCommand.java index d72ea26..afc60d1 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/fun/image/ImageCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/fun/image/ImageCommand.java @@ -19,5 +19,6 @@ public class ImageCommand extends BatCommand { super.addSubCommand(context.getBean(CatSubCommand.class)); super.addSubCommand(context.getBean(DogSubCommand.class)); super.addSubCommand(context.getBean(FoxSubCommand.class)); + super.addSubCommand(context.getBean(DuckSubCommand.class)); } } diff --git a/src/main/java/cc/fascinated/bat/model/token/randomd/RandomDuck.java b/src/main/java/cc/fascinated/bat/model/token/randomd/RandomDuck.java new file mode 100644 index 0000000..a5f34c7 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/model/token/randomd/RandomDuck.java @@ -0,0 +1,15 @@ +package cc.fascinated.bat.model.token.randomd; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author Fascinated (fascinated7) + */ +@Getter +public class RandomDuck { + /** + * The URL of the duck image. + */ + private String url; +}