예제 #1
0
파일: main.go 프로젝트: kvangork/victor
func main() {
	bot, err := victor.New("shell", "bot")

	if err != nil {
		fmt.Println(err)
	}

	bot.Respond("hello|hi|howdy", func(m victor.Message) {
		m.Room().Say(fmt.Sprintf("Hello, %s", m.User().Name()))
	})

	signals(bot).Run()
}
예제 #2
0
func main() {
	bot = victor.New(victor.Config{
		Name:        "victor",
		ChatAdapter: "shell",
	})

	dialogueHandler(bot)
	go bot.Run()

	http.HandleFunc("/say", sayHandler)
	go http.ListenAndServe(":9000", nil)

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt)
	<-sigs

	bot.Stop()
}
예제 #3
0
파일: main.go 프로젝트: rhencke/victor
func main() {
	bot := victor.New(victor.Config{
		Name:         "victor",
		ChatAdapter:  "shell",
		StoreAdapter: "memory",
		HTTPAddr:     ":8000",
	})

	bot.HandleCommandFunc("hello|hi|howdy", func(s victor.State) {
		s.Chat().Send(s.Message().ChannelID(), fmt.Sprintf("Hello, %s", s.Message().UserName()))
	})

	go bot.Run()

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt)
	<-sigs

	bot.Stop()
}
예제 #4
0
// should set environment variable
// SLACK_CHANNEL_TIMELINE_ID=hogehoge
// SLACK_TOKEN=xoxp-...
func main() {
	token := os.Getenv("SLACK_TOKEN")
	if token == "" {
		log.Fatalln("SLACK_TOKEN is required")
	}
	tid := os.Getenv("SLACK_CHANNEL_TIMELINE_ID")
	if tid == "" {
		log.Fatalln("SLACK_CHANNEL_TIMELINE_ID is required")
	}

	ss := slackRealtime.NewConfig(token)

	config := victor.Config{
		Name:          "victor",
		ChatAdapter:   "slackRealtime",
		StoreAdapter:  "memory",
		HTTPAddr:      ":8000",
		AdapterConfig: ss,
	}
	bot := victor.New(config)

	bot.HandleCommandFunc(".*", func(s victor.State) {
		log.Printf("%v\n", s)
		if strings.HasPrefix(s.Message().ChannelName(), "_") {
			s.Chat().Send(tid, fmt.Sprintf("%s: %s", s.Message().UserName(), s.Message().Text()))
		}
	})

	go bot.Run()

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt)
	<-sigs

	bot.Stop()
}