-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3559f11
commit 017a3ac
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/com/beanbeanjuice/command/fun/ChooseRandom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.beanbeanjuice.command.fun; | ||
|
||
import com.beanbeanjuice.utility.command.CommandCategory; | ||
import com.beanbeanjuice.utility.command.ICommand; | ||
import com.beanbeanjuice.utility.helper.Helper; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* An {@link ICommand} used to choose a random variable. | ||
* | ||
* @author beanbeanjuice | ||
*/ | ||
public class ChooseRandom implements ICommand { | ||
|
||
@Override | ||
public void handle(@NotNull SlashCommandInteractionEvent event) { | ||
String[] variables = Helper.removeCommaSpace(event.getOption("choices").getAsString()); // Will not be null. | ||
|
||
int randomNum = Helper.getRandomNumber(0, variables.length); | ||
String chosenVariable = variables[randomNum]; | ||
|
||
StringBuilder messageBuilder = new StringBuilder(); | ||
messageBuilder.append("Options: ```"); | ||
|
||
for (int i = 0; i < variables.length; i++) { | ||
messageBuilder.append(variables[i]); | ||
|
||
if (i != variables.length - 1) messageBuilder.append(", "); | ||
} | ||
|
||
messageBuilder.append("```\n\n🎲 (").append(randomNum + 1).append("/").append(variables.length).append("): ") | ||
.append("**").append(chosenVariable).append("**"); | ||
|
||
event.getHook().sendMessageEmbeds( | ||
Helper.successEmbed( | ||
"Random Variable Chooser", | ||
messageBuilder.toString() | ||
) | ||
).queue(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Choose a random variable!"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String exampleUsage() { | ||
return "`/choose-random bacon,lettuce,pineapple`"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ArrayList<OptionData> getOptions() { | ||
ArrayList<OptionData> options = new ArrayList<>(); | ||
options.add(new OptionData(OptionType.STRING, "choices", "The random variables to choose from, separated by commas.", true)); | ||
return options; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CommandCategory getCategoryType() { | ||
return CommandCategory.FUN; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Boolean allowDM() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters