コード例 #1
0
ファイル: config.go プロジェクト: aichaos/rivescript-go
// UTF8 creates a default configuration with UTF-8 mode enabled.
//
// - Strict: true
// - Depth: 50
// - UTF8: true
func UTF8() *Config {
	return &Config{
		Strict:         true,
		Depth:          50,
		UTF8:           true,
		SessionManager: memory.New(),
	}
}
コード例 #2
0
func TestMemorySession(t *testing.T) {
	bot := NewTestWithConfig(t, &config.Config{
		SessionManager: memory.New(),
	})
	bot.extend(commonSessionTest)
	bot.reply("My name is Aiden", "Nice to meet you, Aiden.")
	bot.reply("What did I just say?", "You just said: my name is aiden")
	bot.reply("Who am I?", "Aren't you Aiden?")
	bot.reply("What did you just say?", "I just said: Aren't you Aiden?")
	bot.reply("I hate you!", "How mean!")
	bot.reply("My name is Bob", "Nope, I'm mad at you.")
}
コード例 #3
0
ファイル: rivescript.go プロジェクト: aichaos/rivescript-go
func New(cfg *config.Config) *RiveScript {
	rs := new(RiveScript)
	if cfg == nil {
		cfg = config.Basic()
	}

	if cfg.SessionManager == nil {
		rs.say("No SessionManager config: using default MemoryStore")
		cfg.SessionManager = memory.New()
	}

	if cfg.Depth <= 0 {
		rs.say("No depth config: using default 50")
		cfg.Depth = 50
	}

	rs.Debug = cfg.Debug
	rs.Strict = cfg.Strict
	rs.UTF8 = cfg.UTF8
	rs.Depth = cfg.Depth
	rs.sessions = cfg.SessionManager

	rs.UnicodePunctuation = regexp.MustCompile(`[.,!?;:]`)

	// Initialize helpers.
	rs.parser = parser.New(parser.ParserConfig{
		Strict:  rs.Strict,
		UTF8:    rs.UTF8,
		OnDebug: rs.say,
		OnWarn:  rs.warnSyntax,
	})

	// Initialize all the data structures.
	rs.global = map[string]string{}
	rs.var_ = map[string]string{}
	rs.sub = map[string]string{}
	rs.person = map[string]string{}
	rs.array = map[string][]string{}
	rs.includes = map[string]map[string]bool{}
	rs.inherits = map[string]map[string]bool{}
	rs.objlangs = map[string]string{}
	rs.handlers = map[string]macro.MacroInterface{}
	rs.subroutines = map[string]Subroutine{}
	rs.topics = map[string]*astTopic{}
	rs.thats = map[string]*thatTopic{}
	rs.sorted = new(sortBuffer)

	return rs
}