All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.alexpado.jda.interactions.tools.InteractionUtils Maven / Gradle / Ivy

package fr.alexpado.jda.interactions.tools;

import net.dv8tion.jda.api.interactions.commands.OptionMapping;

/**
 * Class grouping all kind of utility methods
 */
public final class InteractionUtils {

    private InteractionUtils() {}

    /**
     * Extract the value from the provided {@link OptionMapping}.
     *
     * @param option
     *         The option
     *
     * @return The extracted value
     */
    public static Object extractOptionValue(OptionMapping option) {

        return switch (option.getType()) {
            case BOOLEAN -> option.getAsBoolean();
            case STRING -> option.getAsString();
            case INTEGER -> option.getAsLong();
            case CHANNEL -> option.getAsMessageChannel();
            case USER -> option.getAsUser();
            case ROLE -> option.getAsRole();
            case MENTIONABLE -> option.getAsMentionable();
            case NUMBER -> option.getAsDouble();
            case ATTACHMENT -> option.getAsAttachment();
            default -> null;
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy