Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotAnswer ¶
type BotAnswer struct {
Text string `json:"text"`
Pattern *int `json:"pattern,omitempty"` // can be null
Mood float64 `json:"mood"`
Affection float64 `json:"affection"`
}
BotAnswer is the answer returned by the bot instance
type BotPool ¶
type BotPool struct {
// contains filtered or unexported fields
}
BotPool manages a pool of running instances of the bot python script. In order to generate the bot answers faster for multiple users, any incoming request is forwarded to a free bot instance. For every incoming request a task is generated and executed by the next free instance. The Number of bot instances can be resized to allow dynamic load balancing.
func NewBotPool ¶
NewBotPool creates a new pool with a given amount of bot instances The task buffer size is 128. This means the pool can have up to 128 tasks in the que.
func (*BotPool) HandleRequest ¶
func (p *BotPool) HandleRequest(data MessageData) BotAnswer
HandleRequest takes incoming requests and makes the task work off by the next free bot instance. The function always returns a answer with text. If an error occures errorBotAnswer(...) is returned.
type MessageData ¶
type MessageData struct {
Text string `json:"text"`
PreviousPattern *int `json:"previous_pattern,omitempty"` // can be null
Mood float64 `json:"mood"`
Affection float64 `json:"affection"`
Gender db.Gender `json:"bot_gender"`
Name string `json:"bot_name"`
Birthdate int64 `json:"bot_birthdate"` // Unix timestamp
FavoriteColor string `json:"bot_favorite_color"`
FatherName string `json:"father_name"`
FatherAge int `json:"father_age"`
MotherName string `json:"mother_name"`
MotherAge int `json:"mother_age"`
}
MessageData is used so send all needed information to the bot instance