예제 #1
0
파일: echobot.go 프로젝트: ikawaha/slackbot
// echo sample
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "usage: bot slack-bot-token\n")
		os.Exit(1)
	}

	// start a websocket-based Real Time API session
	bot, err := slackbot.New(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer bot.Close()
	fmt.Println("^C exits")

	for {
		msg, err := bot.GetMessage()
		if err != nil {
			log.Printf("receive error, %v", err)
		}
		log.Printf("bot_id: %v, msguser_id: %v, msg:%+v\n", bot.ID, msg.UserID, msg)
		if bot.ID == msg.MentionID() && msg.Type == "message" && msg.SubType == "" {
			go func(m slackbot.Message) {
				m.Text = m.TextBody()
				bot.PostMessage(m)
			}(msg)
		}
	}
}
예제 #2
0
파일: otemoto.go 프로젝트: ikawaha/otemoto
func New(token string, tt TimeTable) (*Bot, error) {
	b, err := slackbot.New(token)
	if err != nil {
		return nil, err
	}
	t := make(TimeTable, len(tt), len(tt))
	copy(t, tt)
	return &Bot{
		Bot:      b,
		schedule: t,
	}, nil
}
예제 #3
0
// haiku sample
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "usage: bot slack-bot-token\n")
		os.Exit(1)
	}

	// start a websocket-based Real Time API session
	bot, err := slackbot.New(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer bot.Close()
	fmt.Println("^C exits")

	r575 := []int{5, 7, 5}
	for {
		msg, err := bot.GetMessage()
		if err != nil {
			log.Printf("receive error, %v", err)
		}
		log.Printf("bot_id: %v, msguser_id: %v, msg:%+v\n", bot.ID, msg.UserID, msg)
		if msg.Type != "message" {
			continue
		}
		go func(m slackbot.Message) {
			t := m.TextBody()
			hs := haiku.Find(t, r575)
			if len(hs) < 1 {
				return
			}
			var tmp []string
			for _, h := range hs {
				tmp = append(tmp, fmt.Sprintf("```%v```", h))
			}
			m.Text = strings.Join(tmp, "\n")
			m.Text += " 575だ"
			time.Sleep(botResponseSleepTime)
			bot.PostMessage(m)
		}(msg)
	}
}
예제 #4
0
// dajare sample
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr, "usage: bot slack-bot-token\n")
		os.Exit(1)
	}

	// start a websocket-based Real Time API session
	bot, err := slackbot.New(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer bot.Close()
	fmt.Println("^C exits")

	for {
		msg, err := bot.GetMessage()
		if err != nil {
			log.Printf("receive error, %v", err)
		}
		log.Printf("bot_id: %v, msguser_id: %v, msg:%+v\n", bot.ID, msg.UserID, msg)
		if msg.Type != "message" || msg.SubType != "" {
			continue
		}
		go func(m slackbot.Message) {
			t := m.TextBody()
			dug, daj := dajarep.Dajarep(t)
			log.Printf("msg: %v, dajare: %+v, debug: %+v\n", t, daj, dug)
			if len(daj) < 1 {
				return
			}
			m.Text = fmt.Sprintf(responseTemplate, bot.UserName(m.UserID), t)
			time.Sleep(botResponseSleepTime)
			bot.PostMessage(m)
		}(msg)
	}
}