From 4a1528bea2ef41fbbf68bcc7cfeb71e7c8082c73 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Mar 2022 18:33:02 -0700 Subject: [PATCH] Dreidel Command --- src/main/java/moe/oko/Kiafumi/Kiafumi.java | 1 + .../oko/Kiafumi/command/DreidelCommand.java | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/main/java/moe/oko/Kiafumi/command/DreidelCommand.java diff --git a/src/main/java/moe/oko/Kiafumi/Kiafumi.java b/src/main/java/moe/oko/Kiafumi/Kiafumi.java index f7c4082..84c0eb8 100644 --- a/src/main/java/moe/oko/Kiafumi/Kiafumi.java +++ b/src/main/java/moe/oko/Kiafumi/Kiafumi.java @@ -78,6 +78,7 @@ public class Kiafumi { activeCommands.add(new SettingCommand()); activeCommands.add(new DuckCommand()); activeCommands.add(new InviteCommand()); + activeCommands.add(new DreidelCommand()); instance = this; diff --git a/src/main/java/moe/oko/Kiafumi/command/DreidelCommand.java b/src/main/java/moe/oko/Kiafumi/command/DreidelCommand.java new file mode 100644 index 0000000..dddb3b0 --- /dev/null +++ b/src/main/java/moe/oko/Kiafumi/command/DreidelCommand.java @@ -0,0 +1,81 @@ +package moe.oko.Kiafumi.command; + +import moe.oko.Kiafumi.util.CommandInfo; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; + +import java.awt.*; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +public class DreidelCommand extends CommandClass { + private boolean enabled = true; + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public String getName() { + return "Dreidel"; + } + + @Override + public void legacyCommand(String[] args, MessageReceivedEvent e, boolean prefix) { + + } + + @Override + public void newCommand(String name, SlashCommandInteractionEvent e) { + switch (name) { + case "dreidel": + e.deferReply().queue(); + List usersForRng = new ArrayList<>(); + for(OptionMapping option : e.getOptions()) { + usersForRng.add(option.getAsUser()); + } + //Done, now roll + EmbedBuilder eb = new EmbedBuilder() + .setColor(Color.PINK) + .setTitle("Rolling...") + .setDescription("*VROOOOOOOOOOOOOOOOM*") + .setFooter("Kiafumi - Maintained by oko.moe") + .setTimestamp(ZonedDateTime.now()); + e.getHook().sendMessageEmbeds(eb.build()).queue(); + Random rng = new Random(); + User pickedUser = usersForRng.get(rng.nextInt(usersForRng.size())); + EmbedBuilder eb1 = new EmbedBuilder() + .setColor(Color.PINK) + .setFooter("Kiafumi - Maintained by oko.moe") + .setTimestamp(ZonedDateTime.now()) + .setTitle("The dreidel has spoken...") + .setThumbnail(pickedUser.getAvatarUrl()) + .setDescription(pickedUser.getName() + " is the lucky winner!"); + e.getHook().editOriginalEmbeds(eb1.build()).completeAfter(5, TimeUnit.SECONDS); + } + } + + @Override + public List getCommandsAsList() { + return null; + } + + @Override + public List getSlashCommandInfo() { + List cil = new ArrayList<>(); + CommandInfo ci = new CommandInfo("dreidel", "picks a random person out of 4 values."); + ci.addOption("value1", "first value for spin", OptionType.USER, true); + ci.addOption("value2", "second value for spin", OptionType.USER, true); + ci.addOption("value3", "third value for spin", OptionType.USER, false); + ci.addOption("value4", "fourth value for spin", OptionType.USER, false); + cil.add(ci); + return cil; + } +}