From f6834db9cb0e8aec24695316819eacb4b5eec846 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 3 Jul 2024 20:19:21 +0100 Subject: [PATCH] add 8ball command --- .../bat/features/base/BaseFeature.java | 2 + .../base/commands/fun/EightBallCommand.java | 62 +++++++++++++++++++ .../cc/fascinated/bat/model/BatGuild.java | 1 - .../java/cc/fascinated/bat/model/BatUser.java | 3 - 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java diff --git a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java index 129df85..8cda4dc 100644 --- a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java +++ b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java @@ -3,6 +3,7 @@ package cc.fascinated.bat.features.base; import cc.fascinated.bat.command.Category; import cc.fascinated.bat.features.Feature; import cc.fascinated.bat.features.base.commands.botadmin.premium.PremiumAdminCommand; +import cc.fascinated.bat.features.base.commands.fun.EightBallCommand; import cc.fascinated.bat.features.base.commands.fun.image.ImageCommand; import cc.fascinated.bat.features.base.commands.general.*; import cc.fascinated.bat.features.base.commands.general.avatar.AvatarCommand; @@ -39,5 +40,6 @@ public class BaseFeature extends Feature { super.registerCommand(commandService, context.getBean(AvatarCommand.class)); super.registerCommand(commandService, context.getBean(ImageCommand.class)); super.registerCommand(commandService, context.getBean(FeatureCommand.class)); + super.registerCommand(commandService, context.getBean(EightBallCommand.class)); } } diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java new file mode 100644 index 0000000..52ea3e8 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java @@ -0,0 +1,62 @@ +package cc.fascinated.bat.features.base.commands.fun; + +import cc.fascinated.bat.command.BatCommand; +import cc.fascinated.bat.command.CommandInfo; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.model.BatGuild; +import cc.fascinated.bat.model.BatUser; +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.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +@CommandInfo(name = "8ball", description = "Ask the magic 8ball a question") +public class EightBallCommand extends BatCommand { + private final String[] responses = new String[]{ + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes, definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Reply hazy, try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + "Don't count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful" + }; + + public EightBallCommand() { + super.addOption(OptionType.STRING, "question", "The question you want to ask the 8ball", true); + } + + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { + OptionMapping questionOption = event.getOption("question"); + if (questionOption == null) { + return; + } + String question = questionOption.getAsString(); + String response = responses[(int) (Math.random() * responses.length)]; + event.replyEmbeds(EmbedUtils.successEmbed() + .setDescription("You asked: `%s`\n\n:8ball: The magic 8ball says: `%s`".formatted(question, response)) + .build()) + .queue(); + } +} diff --git a/src/main/java/cc/fascinated/bat/model/BatGuild.java b/src/main/java/cc/fascinated/bat/model/BatGuild.java index e00d483..fb40213 100644 --- a/src/main/java/cc/fascinated/bat/model/BatGuild.java +++ b/src/main/java/cc/fascinated/bat/model/BatGuild.java @@ -20,7 +20,6 @@ import net.dv8tion.jda.api.entities.Guild; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; import java.util.Date; import java.util.HashMap; diff --git a/src/main/java/cc/fascinated/bat/model/BatUser.java b/src/main/java/cc/fascinated/bat/model/BatUser.java index 5739d4b..9e9808f 100644 --- a/src/main/java/cc/fascinated/bat/model/BatUser.java +++ b/src/main/java/cc/fascinated/bat/model/BatUser.java @@ -13,10 +13,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.Setter; import net.dv8tion.jda.api.entities.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; import java.util.Date; import java.util.HashMap;