bots

package
v1.0.1-0...-6dc1f34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 10 Imported by: 0

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

func NewBotPool(size int) *BotPool

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) Close

func (p *BotPool) Close()

Close kills all running bot instances

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.

func (*BotPool) Resize

func (p *BotPool) Resize(n int)

Resize changes the count of bot instances The size can be any positiv number including zero. Decreasing the size can take a while, because only bot instances that are not currently working can be destroyed.

func (*BotPool) Wait

func (p *BotPool) Wait()

Wait locks thread until all bots are done

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL