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
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 permits ButtonComponent, UnspecificComponent, SelectMenuComponent<S,T,B,D>

Represents a component, namely Button, StringSelectMenu or EntitySelectMenu, 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:
  • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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 localization, see [I18n#localize(Locale, String, Entry...) ]
    • 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
    • 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)