Dreidel Command

This commit is contained in:
unknown 2022-03-28 18:33:02 -07:00
parent af054aa580
commit 4a1528bea2
2 changed files with 82 additions and 0 deletions

View file

@ -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;

View file

@ -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<User> 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<String> getCommandsAsList() {
return null;
}
@Override
public List<CommandInfo> getSlashCommandInfo() {
List<CommandInfo> 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;
}
}