示例#1
0
func main() {
	ignoreUsers := []string{}
	var connector ihr.Connector
	if env.DEBUG == true {
		connector = console.NewConsoleConnector()
	} else {
		token := os.Getenv("SLACK_TOKEN")
		if token == "" {
			log.Fatal("not set SLACK_TOKEN")
		}
		connector = slack.NewSlackConnector(token, "")
	}

	ameshImageGenerator := amesh.NewAmeshImageGenerator()
	robot := ihr.NewBot(connector, BotName, ignoreUsers)
	robot.Command(
		"help",
		"これ",
		func(msg ihr.Event) {
			msg.Say(robot.ShowHelp())
		},
	)
	robot.Command(
		"amesh",
		"アメッシュの画像を生成する",
		func(msg ihr.Event) {
			targetDate := time.Now().Add(time.Duration(-1) * time.Minute).Truncate(5 * time.Minute).Format("200601021504")
			imgPath := ameshImageGenerator.Generate(targetDate)

			msg.Say(imgPath)
		},
	)
	robot.Start()
}
示例#2
0
文件: imghr.go 项目: f110/go-imghr
func main() {
	token := os.Getenv("SLACK_TOKEN")
	if env.DEBUG == false {
		if token == "" {
			log.Fatal("not set SLACK_TOKEN")
		}
	}
	log.Print("init")
	ignoreUsers := []string{}

	ameshImageGenerator := amesh.NewAmeshImageGenerator()
	jmaImageGenerator := jma.NewJmaImageGenerator()
	lastNeteroTime := time.Now().Add(time.Duration(-13) * time.Hour)
	lastGenichiroTime := time.Now().Add(time.Duration(-1) * time.Hour)

	var connector ihr.Connector
	if env.DEBUG == true {
		connector = console.NewConsoleConnector()
	} else {
		connector = slack.NewSlackConnector(token, ProfileIcon)
	}

	robot := ihr.NewBot(connector, BotName, ignoreUsers)
	robot.Command(
		"help",
		"これ",
		func(msg ihr.Event) {
			msg.Say(robot.ShowHelp())
		},
	)
	robot.Command(
		"version",
		"show version",
		func(msg ihr.Event) {
			msg.Say("version: " + Version)
		},
	)
	robot.Command(
		"ping",
		"ピンポン",
		func(msg ihr.Event) {
			msg.Say("pong")
		},
	)
	robot.Command(
		"amesh",
		"アメッシュの画像を生成する",
		func(msg ihr.Event) {
			targetDate := time.Now().Add(time.Duration(-1) * time.Minute).Truncate(5 * time.Minute).Format("200601021504")
			imgPath := ameshImageGenerator.Generate(targetDate)

			msg.Say(imgPath)
		},
	)
	robot.Command(
		"jma",
		"高解像度ナウキャストの画像を生成する",
		func(msg ihr.Event) {
			targetDate := time.Now().UTC().Add(time.Duration(-5) * time.Minute).Truncate(5 * time.Minute).Format("200601021504")
			imgPath := jmaImageGenerator.Generate(targetDate)

			msg.Say(imgPath)
		},
	)
	robot.Command(
		"gif",
		"ランダムにアニメーションgifを表示する",
		func(msg ihr.Event) {
			msg.Say(giphy.Random())
		},
	)
	robot.Command(
		"ip",
		"show global ip address",
		func(msg ihr.Event) {
			res, err := http.Get("http://dyn.value-domain.com/cgi-bin/dyn.fcg?ip")
			if err != nil {
				msg.Say("sorry")
				return
			}
			buf, err := ioutil.ReadAll(res.Body)
			if err != nil {
				msg.Say("sorry 2")
				return
			}
			defer res.Body.Close()
			msg.Say(string(buf[:len(buf)]))
		},
	)
	robot.CommandWithArgv(
		"img",
		"画像検索",
		func(msg ihr.Event) {
			msg.Say(imageSearch(msg.Argv))
		},
	)
	robot.CommandWithArgv(
		"ihr",
		"ihrの画像検索",
		func(msg ihr.Event) {
			words := []string{"aww cat", "柴犬", "豆柴", "aww dog", "aww shiba"}
			msg.Say(imageSearch(words[rand.Intn(len(words))]))
		},
	)
	robot.CommandWithArgv(
		"wikipedia",
		"wikipedia検索",
		func(msg ihr.Event) {
			summary, err := wikipedia.GetSummary(msg.Argv)
			if err != nil {
				msg.Say("ページがないよ")
			} else {
				msg.Say(summary + "\n" + wikipedia.GenerateJaWikipediaURL(msg.Argv))
			}
		},
	)
	robot.CommandWithArgv(
		"gif",
		"アニメーションGif検索",
		func(msg ihr.Event) {
			url := giphy.Search(msg.Argv)
			if url == "" {
				msg.Say("( ˘ω˘ )スヤァ")
			} else {
				msg.Say(url)
			}
		},
	)

	robot.Hear("(?i)(hanakin|花金|金曜|ファナキン|tgif)", func(msg ihr.Event) {
		if time.Now().Weekday() != time.Friday {
			return
		}

		msg.Say("花金だーワッショーイ!テンションAGEAGEマック")
	})
	robot.Hear("\\An\\z", func(msg ihr.Event) {
		msg.Say(imageSearch("長澤まさみ"))
	})
	robot.Hear("\\Ak\\z", func(msg ihr.Event) {
		msg.Say(imageSearch("木村文乃"))
	})
	robot.Hear("\\Aa\\z", func(msg ihr.Event) {
		msg.Say(imageSearch("有村架純"))
	})
	robot.Hear("\\Af\\z", func(msg ihr.Event) {
		msg.Say(imageSearch("Ferrari 458 Italia"))
	})
	robot.Hear("\\Ap\\z", func(msg ihr.Event) {
		msg.Say(imageSearch("Porsche 991 GT3 RS"))
	})
	robot.Appearance(IhrID, func(msg ihr.Event) {
		if time.Now().Sub(lastNeteroTime) < 12*time.Hour {
			return
		}
		if 14 > time.Now().Hour() || time.Now().Hour() > 17 {
			return
		}
		lastNeteroTime = time.Now()
		msg.Say("I H R は 寝 て ろ ! !")
	})
	robot.Appearance(GenichiroID, func(msg ihr.Event) {
		if time.Now().Sub(lastGenichiroTime) < 1*time.Hour {
			return
		}
		if 10 > time.Now().Hour() || time.Now().Hour() > 17 {
			return
		}
		lastGenichiroTime = time.Now()
		messages := []string{":ihr: < tintinro は働け!", ":ihr: < 進捗どうですか?", ":ihr: < バックログはちゃんと消化したか?"}
		msg.Say(messages[rand.Intn(len(messages))])
	})

	robot.Start()
}