func signals(bot *victor.Robot) *victor.Robot { sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt) go func() { <-sigs bot.Stop() }() return bot }
func dialogueHandler(robot victor.Robot) { robot.HandleFunc(robot.Direct("(.+)"), func(s victor.State) { d := docomo.NewClient(os.Getenv("DOCOMO_DIALOGUE_API_KEY")) dialogue := docomo.DialogueRequest{ Utt: &s.Params()[0], } get, _ := d.Dialogue.Get(dialogue, true) s.Chat().Send(s.Message().ChannelID(), get.Utt) }) }
func Defaults(robot victor.Robot) { robot.HandleFunc(robot.Direct("ping"), func(s victor.State) { s.Chat().Send(s.Message().ChannelID(), "pong!") }) robot.HandleFunc(robot.Direct("roll(\\s(\\d+))?"), func(s victor.State) { defer recover() bound := 100 val := s.Params()[1] if val != "" { var err error bound, err = strconv.Atoi(val) if err != nil { return } } rand.Seed(time.Now().UTC().UnixNano()) random := rand.Intn(bound) msg := fmt.Sprintf("%s rolled a %d of %d", s.Message().UserName(), random, bound) s.Chat().Send(s.Message().ChannelID(), msg) }) }