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 missing methods to get the actual component #850

Merged
merged 1 commit into from Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,4 +1,26 @@
package org.javacord.api.entity.message.component;

public interface HighLevelComponent extends Component {
import org.javacord.api.util.Specializable;
import java.util.Optional;

public interface HighLevelComponent extends Component, Specializable<HighLevelComponent> {

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isActionRow() {
return getType() == ComponentType.ACTION_ROW;
}

/**
* Gets the component as an ActionRow if it's of that type.
*
* @return The ActionRow.
*/
default Optional<ActionRow> asActionRow() {
return isActionRow() ? Optional.of((ActionRow) this) : Optional.empty();
}

}
@@ -1,4 +1,44 @@
package org.javacord.api.entity.message.component;

public interface LowLevelComponent extends Component {
import org.javacord.api.util.Specializable;
import java.util.Optional;

public interface LowLevelComponent extends Component, Specializable<LowLevelComponent> {

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isButton() {
return getType() == ComponentType.BUTTON;
}

/**
* Gets the component as a Button if it's of that type.
*
* @return The Button.
*/
default Optional<Button> asButton() {
return isButton() ? Optional.of((Button) this) : Optional.empty();
}

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isSelectMenu() {
return getType() == ComponentType.SELECT_MENU;
}

/**
* Gets the component as a SelectMenu if it's of that type.
*
* @return The SelectMenu.
*/
default Optional<SelectMenu> asSelectMenu() {
return isSelectMenu() ? Optional.of((SelectMenu) this) : Optional.empty();
}

}