Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is a mommy response generator. It is safe for concurrent use.
func NewGenerator ¶
NewGenerator creates a new mommy response generator with a new automatically seeded random number generator.
func NewGeneratorWithRandom ¶
NewGeneratorWithRandom creates a new mommy response generator with the given random number generator.
func (*Generator) Generate ¶
func (g *Generator) Generate(response ResponseType, overrides Overrides) (string, error)
Generate generates a response from the given response type with an optional set of overrides. If a variable is present in the overrides map, then it will use that value. If a variable is not present in the overrides map, then it will use a random default value. If a variable has no default values, then it will return an error
Example ¶
random := rand.New(rand.NewSource(0)) // deterministic for example gen, _ := mommy.NewGeneratorWithRandom(mommy.DefaultResponses, random) positive, _ := gen.Generate(mommy.PositiveResponse, nil) fmt.Println("when you did a good job:") fmt.Println(positive) fmt.Println() negative, _ := gen.Generate(mommy.NegativeResponse, mommy.Overrides{ mommy.VariableMood: mommy.Thirsty, mommy.VariableAffectionateTerm: "boy", }) fmt.Println("when you did a bad job:") fmt.Println(negative) fmt.Println()
Output: when you did a good job: good girl~ mommy's so proud of you~ when you did a bad job: you need to work harder to please mommy~
func (*Generator) GenerateTo ¶ added in v0.1.1
type Mood ¶
type Mood struct { Positive []Template `json:"positive"` Negative []Template `json:"negative"` Spiciness Spiciness `json:"spiciness,omitempty"` // NSFW }
Mood contains the responses for a given mood. It is represented as a list of positive and negative responses, and optionally a spiciness level.
type Overrides ¶
type Overrides map[VariableKey]string
Overrides is a map of variable keys to values that can be used to override the default values. If a variable is not present in this map, then a random default value will be used.
type ResponseType ¶
type ResponseType string
ResponseType is the type of response that mommy will generate.
const ( PositiveResponse ResponseType = "positive" NegativeResponse ResponseType = "negative" )
type Responses ¶
type Responses struct { // Moods is a map of moods that mommy has. This map contains the responses // that mommy will use when they are in that mood. Moods map[Spiciness]Mood `json:"moods"` // Vars is a map of variables that can be used in the responses. // It is used in tandem with the template strings. Vars map[VariableKey]Variable `json:"vars"` }
Responses is the JSON representation of the responses.json file. It is used to unmarshal the responses.json file.
var DefaultResponses Responses
DefaultResponses is the default responses.json file. It is embedded into the binary.
func UnmarshalResponses ¶
UnmarshalResponses unmarshals the responses.json file.
func (Responses) WithVariable ¶
func (r Responses) WithVariable(k VariableKey, v []string) Responses
WithVariable sets a variable to a new responses object.
func (Responses) WithVariables ¶
func (r Responses) WithVariables(vars map[VariableKey][]string) Responses
WithVariables sets variables to a new responses object.
type Template ¶
type Template string
Template describes a string that contains templating variables. It expects the syntax "{variable_name}".
type Variable ¶
type Variable struct { // Spiciness is a measure of how NSFW this variable is. Spiciness Spiciness `json:"spiciness,omitempty"` // NSFW // Defaults is a list of default values for this variable. Defaults []string `json:"defaults"` // EnvKey is the environment variable key that can be used to override the // default values. This field is not used by this package. EnvKey string `json:"env_key,omitempty"` }
Variable is a variable that is used in the string templates.
type VariableKey ¶
type VariableKey string
VariableKey is the key for a response variable.
const ( // VariableMood determines the spiciness of the response. // It is any of the Spiciness constants. VariableMood VariableKey = "mood" // VariableEmote is an emoji that may be used in the response. VariableEmote VariableKey = "emote" // VariablePronoun is the possessive pronoun that mommy will use. VariablePronoun VariableKey = "pronoun" // VariableRole is the role that mommy will use, e.g. "mommy". VariableRole VariableKey = "role" // VariableAffectionateTerm is an affectionate term that mommy will use to // refer to you. VariableAffectionateTerm VariableKey = "affectionate_term" // VariableDenigratingTerm is a denigrating term that mommy will use to // refer to you. VariableDenigratingTerm VariableKey = "denigrating_term" // NSFW // VariablePart is a part of mommy's body that they will refer to. VariablePart VariableKey = "part" // NSFW )