From 409e71a0aab1857cd2b3efb99768155a2ced45e5 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 27 Jun 2024 21:04:21 -0500 Subject: [PATCH] Add FoxCommand --- .../bat/command/impl/fun/FoxCommand.java | 36 +++++++++++++++++++ .../model/token/randomfox/RandomFoxToken.java | 21 +++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/cc/fascinated/bat/command/impl/fun/FoxCommand.java create mode 100644 src/main/java/cc/fascinated/bat/model/token/randomfox/RandomFoxToken.java diff --git a/src/main/java/cc/fascinated/bat/command/impl/fun/FoxCommand.java b/src/main/java/cc/fascinated/bat/command/impl/fun/FoxCommand.java new file mode 100644 index 0000000..4da33d9 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/impl/fun/FoxCommand.java @@ -0,0 +1,36 @@ +package cc.fascinated.bat.command.impl.fun; + +import cc.fascinated.bat.command.BatCommand; +import cc.fascinated.bat.command.Category; +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.randomfox.RandomFoxToken; +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 Nick (okNick) + */ +@Component +@CommandInfo(name = "fox", description = "Get a random fox image", category = Category.FUN, guildOnly = false) +public class FoxCommand extends BatCommand { + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) { + RandomFoxToken responseEntity = WebRequest.getAsEntity("https://randomfox.ca/floof/", RandomFoxToken.class); + if (responseEntity == null) { + interaction.reply("Failed to get a fox image!").queue(); + return; + } + + interaction.replyEmbeds(EmbedUtils.genericEmbed() + .setAuthor("Here's a random fox image!") + .setImage(responseEntity.getImage()) + .build()).queue(); + } +} diff --git a/src/main/java/cc/fascinated/bat/model/token/randomfox/RandomFoxToken.java b/src/main/java/cc/fascinated/bat/model/token/randomfox/RandomFoxToken.java new file mode 100644 index 0000000..c59b169 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/model/token/randomfox/RandomFoxToken.java @@ -0,0 +1,21 @@ +package cc.fascinated.bat.model.token.randomfox; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Nick (okNick) + */ +@Getter +@AllArgsConstructor +public class RandomFoxToken { + /** + * The URL of the raw image. + */ + private String image; + + /** + * The link of the image + other web info. + */ + private String link; +} \ No newline at end of file