コード例 #1
1
ファイル: util.go プロジェクト: tulir293/ranssibot
// Loop is an infinite loop that checks for new Ranssi posts
func Loop(bot *telebot.Bot, noNotifAtInit bool) {
	for {
		readNow := config.GetConfig().LastReadPost + 1

		node := getPost(readNow)
		if node != nil {
			topic := strings.TrimSpace(node.FirstChild.FirstChild.Data)

			log.Infof("[Posts] New post detected: %s (ID %d)", topic, readNow)

			if !noNotifAtInit {
				config.GetUsersWithSettingAndRun(func(u config.User) {
					bot.SendMessage(u, lang.Translatef(u, "posts.new", topic, readNow), util.Markdown)
				}, subSetting)
			}

			config.GetConfig().LastReadPost = readNow
			config.ASave()
			updateNews()
			time.Sleep(5 * time.Second)
			continue
		}
		noNotifAtInit = false
		time.Sleep(1 * time.Minute)
	}
}
コード例 #2
0
ファイル: ranssibot.go プロジェクト: tulir293/ranssibot
func onoffspam(msg string) {
	sendMsg := func(user config.User) {
		bot.SendMessage(user, msg, util.Markdown)
	}
	if *debug {
		config.GetUsersWithSettingAndRun(sendMsg, onoffspamSetting, onoffValueDebugOnly, onoffValueBoth)
	} else {
		config.GetUsersWithSettingAndRun(sendMsg, onoffspamSetting, onoffValueNormalOnly, onoffValueBoth)
	}
}