示例#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)
	}
}
示例#2
0
// Unsubscribe the given UID from the notification list.
func unsubscribe(u config.User) bool {
	if !isSubscribed(u) {
		log.Debugf("[Posts] %[1]s attempted to unsubscribe from the notification list, but was not subscribed", u.Name)
		return false
	}
	log.Debugf("[Posts] %[1]s successfully unsubscribed from the notifcation list", u.Name)
	u.RemoveSetting(subSetting)
	config.ASave()
	return true
}
示例#3
0
// Subscribe the given UID to the notification list.
func subscribe(u config.User) bool {
	if isSubscribed(u) {
		log.Debugf("[Posts] %[1]s attempted to subscribe to the notification list, but was already subscribed", u.Name)
		return false
	}
	log.Debugf("[Posts] %[1]s successfully subscribed to the notifcation list", u.Name)
	u.SetSetting(subSetting, "true")
	config.ASave()
	return true
}