diff --git a/src/main/java/cc/fascinated/bat/command/impl/fun/CatCommand.java b/src/main/java/cc/fascinated/bat/command/impl/fun/CatCommand.java new file mode 100644 index 0000000..2db32c1 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/impl/fun/CatCommand.java @@ -0,0 +1,38 @@ +package cc.fascinated.bat.command.impl.fun; + +import cc.fascinated.bat.command.BatCommand; +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.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.http.ResponseEntity; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +public class CatCommand extends BatCommand { + public CatCommand() { + super("cat", "Get a random cat image"); + } + + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { + CatImageToken[] responseEntity = WebRequest.getAsEntity("https://api.thecatapi.com/v1/images/search", CatImageToken[].class); + if (responseEntity == null || responseEntity.length == 0) { + interaction.reply("Failed to get a cat image!").queue(); + return; + } + + interaction.replyEmbeds(EmbedUtils.genericEmbed() + .setAuthor("Here's a random cat image!") + .setImage(responseEntity[0].getUrl()) + .build()).queue(); + } +} diff --git a/src/main/java/cc/fascinated/bat/command/impl/fun/DogCommand.java b/src/main/java/cc/fascinated/bat/command/impl/fun/DogCommand.java new file mode 100644 index 0000000..b6ef285 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/impl/fun/DogCommand.java @@ -0,0 +1,38 @@ +package cc.fascinated.bat.command.impl.fun; + +import cc.fascinated.bat.command.BatCommand; +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.dogceo.RandomImage; +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 +public class DogCommand extends BatCommand { + public DogCommand() { + super("dog", "Get a random dog image"); + } + + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { + RandomImage responseEntity = WebRequest.getAsEntity("https://dog.ceo/api/breeds/image/random", RandomImage.class); + if (responseEntity == null) { + interaction.reply("Failed to get a dog image!").queue(); + return; + } + + interaction.replyEmbeds(EmbedUtils.genericEmbed() + .setAuthor("Here's a random dog image!") + .setImage(responseEntity.getMessage()) + .build()).queue(); + } +} diff --git a/src/main/java/cc/fascinated/bat/model/token/dogceo/RandomImage.java b/src/main/java/cc/fascinated/bat/model/token/dogceo/RandomImage.java new file mode 100644 index 0000000..e70243a --- /dev/null +++ b/src/main/java/cc/fascinated/bat/model/token/dogceo/RandomImage.java @@ -0,0 +1,20 @@ +package cc.fascinated.bat.model.token.dogceo; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Fascinated (fascinated7) + */ +@Getter @AllArgsConstructor +public class RandomImage { + /** + * The URL of the image. + */ + private String message; + + /** + * The status of the request. + */ + private String status; +} diff --git a/src/main/java/cc/fascinated/bat/model/token/thecatapi/CatImageToken.java b/src/main/java/cc/fascinated/bat/model/token/thecatapi/CatImageToken.java new file mode 100644 index 0000000..55b5846 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/model/token/thecatapi/CatImageToken.java @@ -0,0 +1,30 @@ +package cc.fascinated.bat.model.token.thecatapi; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Fascinated (fascinated7) + */ +@Getter @AllArgsConstructor +public class CatImageToken { + /** + * The ID of the image. + */ + private String id; + + /** + * The URL of the image. + */ + private String url; + + /** + * The width of the image. + */ + private int width; + + /** + * The height of the image. + */ + private int height; +}