Interface DatabaseInputFunction<D>

  • All Superinterfaces:
    BiFunction<String,​Long,​reactor.core.publisher.Mono<D>>

    public interface DatabaseInputFunction<D>
    extends BiFunction<String,​Long,​reactor.core.publisher.Mono<D>>
    Function that determines the value to save to the database after reading the user input as String.
    • Method Detail

      • withInputCheck

        default DatabaseInputFunction<D> withInputCheck​(Predicate<String> inputCheck,
                                                        String errorMessage)
        Adds a check on the user input before this function is executed. If the check is not fulfilled, the Mono returned will emit IllegalArgumentException instead of the produced value.
        Parameters:
        inputCheck - the predicate to check the input
        errorMessage - the error message that the IllegalArgumentException should carry
        Returns:
        a database input function identical to this one if the check passes, or turns it into an error otherwise
      • withValueCheck

        default DatabaseInputFunction<D> withValueCheck​(Predicate<D> valueCheck,
                                                        String errorMessage)
        Adds a check on the value produced by this function, after the user input was process by this function. If the check is not fulfilled, the Mono returned will emit IllegalArgumentException instead of the produced value.
        Parameters:
        valueCheck - the predicate to check the input
        errorMessage - the error message that the IllegalArgumentException should carry
        Returns:
        a database input function identical to this one if the check passes, or turns it into an error otherwise
      • asIs

        static DatabaseInputFunction<String> asIs()
        Forwards the input value to the database as is, without any modification or check.
        Returns:
        a database input function
      • of

        static <D> DatabaseInputFunction<D> of​(BiFunction<String,​Long,​reactor.core.publisher.Mono<D>> function)
        Encapsulates a regular BiFunction into an instance of DatabaseInputFunction.
        Type Parameters:
        D - the target database type
        Parameters:
        function - the function to encapsulate
        Returns:
        a database input function wrapping the given function
      • to

        static <D> DatabaseInputFunction<D> to​(Function<? super String,​D> converter)
        Converts the input using the supplied conversion function.
        Type Parameters:
        D - the target database type
        Parameters:
        converter - the conversion function
        Returns:
        a database input function transforming the output to a target type
      • toRoleId

        static DatabaseInputFunction<Long> toRoleId​(Bot bot)
        Converts the input into a role and forwards its ID to the database. If no role is found, an IllegalArgumentException is thrown.
        Parameters:
        bot - the bot instance to use in order to fetch roles
        Returns:
        a database input function transforming the output to a role ID
      • toUserId

        static DatabaseInputFunction<Long> toUserId​(Bot bot)
        Converts the input into a user and forwards its ID to the database. If no user is found, an IllegalArgumentException is thrown.
        Parameters:
        bot - the bot instance to use in order to fetch users
        Returns:
        a database input function transforming the output to a user ID
      • toChannelId

        static DatabaseInputFunction<Long> toChannelId​(Bot bot,
                                                       Class<? extends discord4j.core.object.entity.channel.GuildChannel> channelType)
        Converts the input into a channel and forwards its ID to the database. If no channel is found, an IllegalArgumentException is thrown.
        Parameters:
        bot - the bot instance to use in order to fetch channels
        channelType - the accepted type of channel
        Returns:
        a database input function transforming the output to a channel ID