Ejemplo n.º 1
1
// 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)
	}
}
Ejemplo n.º 2
0
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)
	}
}