Class Component<S extends Component<S,T,B,D>, T extends ActionComponent, B, D extends ComponentDefinition<T>>

java.lang.Object
io.github.kaktushose.jdac.dispatching.reply.Component<S,T,B,D>
Type Parameters:
S - the concrete subtype of Component
T - the type of ActionComponent the ComponentDefinition represents
B - the type of builder the ActionComponent uses
D - the type of ComponentDefinition this Component represents
All Implemented Interfaces:
ActionRowChildComponent, ActionRowChildComponentUnion, Component, IComponentUnion, SectionAccessoryComponent, SectionAccessoryComponentUnion
Direct Known Subclasses:
ButtonComponent, SelectMenuComponent, UnspecificComponent

public abstract sealed class Component<S extends Component<S,T,B,D>, T extends ActionComponent, B, D extends ComponentDefinition<T>> extends Object implements ActionRowChildComponentUnion, SectionAccessoryComponentUnion permits ButtonComponent, UnspecificComponent, SelectMenuComponent<S,T,B,D>

Represents a component, namely Button, StringMenu or EntityMenu, that should be added to a reply.

Also holds the following two settings:

enabled:

to enable or disable the component

independent:

whether the component should be executed in the same Runtime as the command it is bound to or not. If true, every component interaction will create a new Runtime. Furthermore, the component cannot expire and will always get executed, even after a bot restart.

Example:

@SlashCommand("example command")
public void onCommand(CommandEvent event) {
    event.with().components(Components.of(true, false, "onButton")).reply();
}

Component type specific implementations

If using one of:

a specific implementation is returned which allows for further modification.

Example without localization

This example overrides the buttons label with "Modified Label"

@Command("example command")
public void onCommand(CommandEvent event) {
    event.with().components(Components.button("onButton")
                    .label("Modified Label"))
                .reply();
}

Example with localization

@Bundle("example")
@Command("example command")
public void onCommand(CommandEvent event, User user) {
    event.with().components(Components.button("onButton")
                    .label("label", I18n.entry("name", user.getName())))
                .reply();
}
See Also:
  • Field Details

    • uniqueId

      protected @Nullable Integer uniqueId
  • Constructor Details

    • Component

      protected Component(String method, @Nullable Class<?> origin, Entry[] placeholder)
  • Method Details

    • enabled

      public static Component<?,?,?,?> enabled(String component, Entry... placeholder)
      Adds an enabled, runtime-bound Component to the reply.
      Parameters:
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • disabled

      public static Component<?,?,?,?> disabled(String component, Entry... placeholder)
      Adds disabled, runtime-bound Components to the reply.
      Parameters:
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • independent

      public static Component<?,?,?,?> independent(String component, Entry... placeholder)

      Adds an enabled, runtime-independent Component to the reply.

      Every component interaction will create a new Runtime. Furthermore, the component cannot expire and will always get executed, even after a bot restart.

      Parameters:
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • enabled

      public static Component<?,?,?,?> enabled(Class<?> origin, String component, Entry... placeholder)
      Adds an enabled Component to the reply that is defined in a different class. This Component will always be runtime-independent.
      Parameters:
      origin - the Class the component is defined in
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • disabled

      public static Component<?,?,?,?> disabled(Class<?> origin, String component, Entry... placeholder)
      Adds a disabled Component to the reply that is defined in a different class. This Component will always be runtime-independent.
      Parameters:
      origin - the Class the component is defined in
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • of

      public static Component<?,?,?,?> of(boolean enabled, boolean independent, String component, Entry... placeholder)
      Adds a Component with the passed configuration to the reply.
      Parameters:
      enabled - whether the Component should be enabled or disabled
      independent - whether the Component should be runtime-bound or independent
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • of

      public static Component<?,?,?,?> of(boolean enabled, Class<?> origin, String component, Entry... placeholder)
      Adds a Component with the passed configuration to the reply.
      Parameters:
      enabled - whether the Component should be enabled or disabled
      origin - the Class the component is defined in
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • of

      public static Component<?,?,?,?> of(boolean enabled, boolean independent, Class<?> origin, String component, Entry... placeholder)
      Adds a Component with the passed configuration to the reply.
      Parameters:
      enabled - whether the Component should be enabled or disabled
      independent - whether the Component should be runtime-bound or independent
      origin - the Class the component is defined in
      component - the name of the method that represents the component
      placeholder - the placeholders to use to perform message resolution
    • button

      public static ButtonComponent button(String component, Entry... placeholder)
      Adds a ButtonComponent to the reply.
      Parameters:
      component - the name of the method that represents the button
      placeholder - the placeholders to use to perform message resolution
    • button

      public static ButtonComponent button(@Nullable Class<?> origin, String component, Entry... placeholder)
      Adds a ButtonComponent to the reply.
      Parameters:
      origin - the Class the component is defined in
      component - the name of the method that represents the button
      placeholder - the placeholders to use to perform message resolution
    • entitySelect

      public static EntitySelectMenuComponent entitySelect(String component, Entry... placeholder)
      Adds an EntitySelectMenuComponent to the reply.
      Parameters:
      component - the name of the method that represents the entity select menu
      placeholder - the placeholders to use to perform message resolution
    • entitySelect

      public static EntitySelectMenuComponent entitySelect(@Nullable Class<?> origin, String component, Entry... placeholder)
      Adds an EntitySelectMenuComponent to the reply.
      Parameters:
      origin - the Class the menu is defined in
      component - the name of the method that represents the entity select menu
      placeholder - the placeholders to use to perform message resolution
    • stringSelect

      public static StringSelectComponent stringSelect(String component, Entry... placeholder)
      Adds a StringSelectComponent to the reply.
      Parameters:
      component - the name of the method that represents the string select menu
      placeholder - the placeholders to use to perform message resolution
    • stringSelect

      public static StringSelectComponent stringSelect(@Nullable Class<?> origin, String component, Entry... placeholder)
      Adds a StringSelectComponent to the reply.
      Parameters:
      origin - the Class the component is defined in
      component - the name of the method that represents the string select menu
      placeholder - the placeholders to use to perform message resolution
    • row

      public static ActionRow row(String... components)

      Creates an ActionRow from the passed components.

      As with other methods of the class, the components are referenced by passing the name of the method(s) that represent the action component(s). The components will always be enabled and runtime-bound.

      This is equivalent to:

      ActionRow.of(Component.button("myButton"), Component.button("anotherButton"));
      
      Parameters:
      components - the name of the methods that represent the action components
      Returns:
      an ActionRow containing the provided components
    • enabled

      public S enabled(boolean enabled)
      Parameters:
      enabled - whether the component should be enabled
      See Also:
    • independent

      public S independent(boolean independent)
      Parameters:
      independent - whether the Component should be runtime-bound or independent
    • modify

      public S modify(Function<B,B> callback)
      Parameters:
      callback - a Function that allows to modify the resulting jda object. The passed function will be called after all modifications except localization are made by jda-commands, shortly before the component is localized and then registered in the message
    • getUniqueId

      public int getUniqueId()
      Specified by:
      getUniqueId in interface Component
    • withUniqueId

      public S withUniqueId(int uniqueId)
      Specified by:
      withUniqueId in interface ActionRowChildComponent
      Specified by:
      withUniqueId in interface ActionRowChildComponentUnion
      Specified by:
      withUniqueId in interface Component
      Specified by:
      withUniqueId in interface IComponentUnion
      Specified by:
      withUniqueId in interface SectionAccessoryComponent
      Specified by:
      withUniqueId in interface SectionAccessoryComponentUnion
    • asButton

      public Button asButton()
      Specified by:
      asButton in interface ActionRowChildComponentUnion
      Specified by:
      asButton in interface SectionAccessoryComponentUnion
    • asStringSelectMenu

      public StringSelectMenu asStringSelectMenu()
      Specified by:
      asStringSelectMenu in interface ActionRowChildComponentUnion
    • asEntitySelectMenu

      public EntitySelectMenu asEntitySelectMenu()
      Specified by:
      asEntitySelectMenu in interface ActionRowChildComponentUnion
    • asThumbnail

      public Thumbnail asThumbnail()
      Specified by:
      asThumbnail in interface SectionAccessoryComponentUnion
    • enabled

      protected boolean enabled()
    • independent

      protected boolean independent()
    • name

      protected String name()
    • origin

      protected Optional<Class<?>> origin()
    • callback

      protected Function<B,B> callback()
    • placeholder

      protected Entry[] placeholder()
    • self

      protected S self()
    • definitionClass

      protected abstract Class<D> definitionClass()
    • build

      protected abstract D build(D definition)