-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (41 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/mmcdole/gofeed"
"log"
"time"
)
func main() {
bot, err := tgbotapi.NewBotAPI(config.TelegramApiToken)
if err != nil {
log.Panic(err)
}
bot.Debug = config.TelegramApiDebug
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
var oldFeed *gofeed.Feed
var newFeed *gofeed.Feed
var chatIds = make(map[int64]struct{})
ticker := time.NewTicker(config.RssUpdateTimeSec * time.Second)
for {
select {
case <-ticker.C:
newFeed = parseFeed()
checkFeed(oldFeed, newFeed, chatIds, bot)
oldFeed = newFeed
case update := <-updates:
if update.Message == nil { // ignore any non-Message Updates
return
}
//if int64(update.Message.From.ID) != update.Message.Chat.ID { // allow only private conversations
// continue
//}
//if !update.Message.IsCommand() { // ignore any non-command Messages
// continue
//}
chatIds[update.Message.Chat.ID] = struct{}{}
}
}
}