Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SlashCommandOptionType NUMBER. #852

Merged
merged 2 commits into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,7 +31,16 @@ default boolean isSubcommandOrGroup() {
}

/**
* Gets the string representation of this option value.
* Gets the string representation value of this option.
*
* <p>This will always be present unless the option is a subcommand or subcommand group.
*
* @return The string representation value of this option.
*/
Optional<String> getStringRepresentationValue();

/**
* Gets the string value of this option.
*
* <p>If this option does not have a string value or the option itself is a subcommand or group,
* the optional will be empty.
Expand Down Expand Up @@ -115,6 +124,19 @@ default boolean isSubcommandOrGroup() {
*/
Optional<Mentionable> getMentionableValue();

/**
* Gets the mentionable value of this option.
* Note: This method only respects cached users if the ID of the Mentionable belongs to a user. To fetch the user
* from Discord if the user is not cached,
* use {@link SlashCommandInteractionOption#requestMentionableValue()}.
*
* <p>If this option does not have a mentionable value or the option itself is a subcommand or group,
* the optional will be empty.
*
* @return The mentionable value of this option.
*/
Optional<Double> getNumberValue();

/**
* Gets the mentionable value of this option.
*
Expand Down
Expand Up @@ -36,6 +36,15 @@ default Optional<SlashCommandInteractionOption> getFirstOption() {
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getFirstOptionStringRepresentationValue() {
return getFirstOption().flatMap(SlashCommandInteractionOption::getStringRepresentationValue);
}

/**
* Gets the string value of the first option (if present).
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getFirstOptionStringValue() {
return getFirstOption().flatMap(SlashCommandInteractionOption::getStringValue);
}
Expand Down Expand Up @@ -117,6 +126,15 @@ default Optional<CompletableFuture<Mentionable>> requestFirstOptionMentionableVa
return getFirstOption().flatMap(SlashCommandInteractionOption::requestFirstOptionMentionableValue);
}

/**
* Gets the double value of the first option (if present).
*
* @return An Optional with the double value of such an option if it exists; an empty Optional otherwise
*/
default Optional<Double> getFirstOptionNumberValue() {
return getFirstOption().flatMap(SlashCommandInteractionOption::getNumberValue);
}

/**
* Get the second option, if present. Useful if you're working with a command that has two options.
*
Expand All @@ -131,6 +149,15 @@ default Optional<SlashCommandInteractionOption> getSecondOption() {
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getSecondOptionStringRepresentationValue() {
return getSecondOption().flatMap(SlashCommandInteractionOption::getStringRepresentationValue);
}

/**
* Gets the string value of the second option (if present).
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getSecondOptionStringValue() {
return getSecondOption().flatMap(SlashCommandInteractionOption::getStringValue);
}
Expand Down Expand Up @@ -212,6 +239,15 @@ default Optional<CompletableFuture<Mentionable>> requestSecondOptionMentionableV
return getSecondOption().flatMap(SlashCommandInteractionOption::requestSecondOptionMentionableValue);
}

/**
* Gets the double value of the second option (if present).
*
* @return An Optional with the double value of such an option if it exists; an empty Optional otherwise
*/
default Optional<Double> getSecondOptionNumberValue() {
return getSecondOption().flatMap(SlashCommandInteractionOption::getNumberValue);
}

/**
* Get the third option, if present. Useful if you're working with a command that has up to 3 options.
*
Expand All @@ -226,6 +262,15 @@ default Optional<SlashCommandInteractionOption> getThirdOption() {
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getThirdOptionStringRepresentationValue() {
return getThirdOption().flatMap(SlashCommandInteractionOption::getStringRepresentationValue);
}

/**
* Gets the string of the third option (if present).
*
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getThirdOptionStringValue() {
return getThirdOption().flatMap(SlashCommandInteractionOption::getStringValue);
}
Expand Down Expand Up @@ -307,6 +352,15 @@ default Optional<CompletableFuture<Mentionable>> requestThirdOptionMentionableVa
return getThirdOption().flatMap(SlashCommandInteractionOption::requestThirdOptionMentionableValue);
}

/**
* Gets the double value of the third option (if present).
*
* @return An Optional with the double value of such an option if it exists; an empty Optional otherwise
*/
default Optional<Double> getThirdOptionNumberValue() {
return getThirdOption().flatMap(SlashCommandInteractionOption::getNumberValue);
}

/**
* Get an option having the specified name.
*
Expand All @@ -320,6 +374,16 @@ default Optional<SlashCommandInteractionOption> getOptionByName(String name) {
.findAny();
}

/**
* Gets the string representation value of an option having the specified name.
*
* @param name The name of the option to search for.
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getOptionStringRepresentationValueByName(String name) {
return getOptionByName(name).flatMap(SlashCommandInteractionOption::getStringRepresentationValue);
}

/**
* Gets the string value of an option having the specified name.
*
Expand Down Expand Up @@ -415,6 +479,16 @@ default Optional<CompletableFuture<Mentionable>> requestOptionMentionableValueBy
return getOptionByName(name).flatMap(SlashCommandInteractionOption::requestFirstOptionMentionableValue);
}

/**
* Gets the double value of an option having the specified name.
*
* @param name The name of the option to search for.
* @return An Optional with the double value of such an option if it exists; an empty Optional otherwise
*/
default Optional<Double> getOptionNumberValueByName(String name) {
return getOptionByName(name).flatMap(SlashCommandInteractionOption::getNumberValue);
}

/**
* Gets the option at the specified index, if present.
*
Expand All @@ -428,6 +502,16 @@ default Optional<SlashCommandInteractionOption> getOptionByIndex(int index) {
.findFirst();
}

/**
* Gets the string representation value of an option at the specified index.
*
* @param index The index of the option to search for.
* @return An Optional with the string value of such an option if it exists; an empty Optional otherwise
*/
default Optional<String> getOptionStringRepresentationValueByIndex(int index) {
return getOptionByIndex(index).flatMap(SlashCommandInteractionOption::getStringRepresentationValue);
}

/**
* Gets the string value of an option at the specified index.
*
Expand Down Expand Up @@ -522,4 +606,14 @@ default Optional<Mentionable> getOptionMentionableValueByIndex(int index) {
default Optional<CompletableFuture<Mentionable>> requestOptionMentionableValueByIndex(int index) {
return getOptionByIndex(index).flatMap(SlashCommandInteractionOption::requestFirstOptionMentionableValue);
}

/**
* Gets the double value of an option at the specified index.
*
* @param index The index of the option to search for.
* @return An Optional with the double value of such an option if it exists; an empty Optional otherwise
*/
default Optional<Double> getOptionNumberValueByIndex(int index) {
return getOptionByIndex(index).flatMap(SlashCommandInteractionOption::getNumberValue);
}
}
Expand Up @@ -11,6 +11,7 @@ public enum SlashCommandOptionType {
CHANNEL(7),
ROLE(8),
MENTIONABLE(9),
NUMBER(10),
UNKNOWN(-1);

private final int value;
Expand Down