-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtelegram-rss-bot.go
84 lines (64 loc) · 1.82 KB
/
telegram-rss-bot.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"github.com/0x111/telegram-rss-bot/chans"
"github.com/0x111/telegram-rss-bot/commands"
"github.com/0x111/telegram-rss-bot/conf"
"github.com/0x111/telegram-rss-bot/db"
"github.com/0x111/telegram-rss-bot/migrations"
"github.com/go-telegram-bot-api/telegram-bot-api"
log "github.com/sirupsen/logrus"
)
func main() {
conf.LoadConfig()
dbc := db.ConnectDB()
defer dbc.Close()
var err error
// Read config
config := conf.GetConfig()
Bot, err := tgbotapi.NewBotAPI(config.GetString("telegram_auth_key"))
if err != nil {
log.Panic(err)
}
Bot.Debug = config.GetBool("telegram_api_debug")
log.Debug("Authorized on account ", Bot.Self.UserName)
// create basic database structure
migrations.Migrate()
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
// read rss data from channels
go func() {
chans.FeedUpdates()
}()
// post rss data to channels
go func() {
chans.FeedPosts(Bot)
}()
// read feed updates from the Telegram API
updates, err := Bot.GetUpdatesChan(u)
for update := range updates {
// if the message is empty, we do not need to handle anything
if update.Message == nil {
continue
}
// allow only private conversations for the bot now
//if int64(update.Message.From.ID) != update.Message.Chat.ID {
// continue
//}
// handle add command
if update.Message.IsCommand() && update.Message.Command() == "add" {
commands.AddCommand(Bot, &update)
}
// handle delete command
if update.Message.IsCommand() && update.Message.Command() == "delete" {
commands.DeleteCommand(Bot, &update)
}
// handle list command
if update.Message.IsCommand() && update.Message.Command() == "list" {
commands.ListCommand(Bot, &update)
}
// handle list command
if update.Message.IsCommand() && update.Message.Command() == "help" {
commands.HelpCommand(Bot, &update)
}
}
}