Class GuildConfigurator<D extends GuildConfigData<D>>

  • Type Parameters:
    D - the type of database entity backing this configurator

    public class GuildConfigurator<D extends GuildConfigData<D>>
    extends Object
    Allows to view and edit configuration for a guild. This high-level class is backed by a lower-level database entity, and the configuration entries represent an abstracted way to view or edit a specific field of that entity.

    This class is thread-safe: getting the data after having modified it via the different entries will always give the most up-to-date result, even if data is being modified by concurrent threads.

    • Method Detail

      • getName

        public String getName()
        Gets the name of this configurator.
        Returns:
        a String
      • getDescription

        public String getDescription()
        Gets the description of this configurator.
        Returns:
        a String
      • getConfigEntries

        public Collection<ConfigEntry<?>> getConfigEntries()
        Gets a collection of configuration entries containied in this configurator.
        Returns:
        a collection of configuration entries
      • getConfigEntry

        public ConfigEntry<?> getConfigEntry​(String key)
        Gets the configuration entry corresponding to the given key
        Parameters:
        key - the key of the entry to get
        Returns:
        the entry
        Throws:
        IllegalArgumentException - if the key does not match any entry
      • saveConfig

        public reactor.core.publisher.Mono<Void> saveConfig​(Database database)
        Saves in the given database the data object reflecting all modifications performed through the entries of this configurator.
        Parameters:
        database - the database where to save data
        Returns:
        a Mono completing when saving to database is successful
      • resetConfig

        public reactor.core.publisher.Mono<D> resetConfig​(Database database)
        Resets the configuration to its default value and saves the data with the default values in the given database.
        Parameters:
        database - the database where to save the reset data
        Returns:
        a Mono emitting the data after reset
      • getGuildId

        public discord4j.rest.util.Snowflake getGuildId()
        Gets the ID of the guild this configurator is atttached to.
        Returns:
        the guild ID
      • builder

        public static <D extends GuildConfigData<D>> GuildConfigurator.Builder<D> builder​(String name,
                                                                                          D initialData,
                                                                                          Class<? extends GuildConfigDao<D>> daoType)
        Creates a new configurator builder with the given name and initial data.
        Type Parameters:
        D - the type of the data object
        Parameters:
        name - the name of the configurator to build
        initialData - the data to initialize the configurator
        daoType - a daoType class compatible with the data object type
        Returns:
        a new builder