-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (59 loc) · 1.86 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"github.com/go-telegram/bot"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"streamobserver/internal/adapter/restreamer"
"streamobserver/internal/adapter/telegram"
"streamobserver/internal/adapter/twitch"
"streamobserver/internal/core/domain"
"streamobserver/internal/core/service"
)
func main() {
log.Info().Str("author", "davidramiro").Msg("starting streamobserver")
log.Info().Msg("initializing telegram bot")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
log.Panic().Err(err).Msg("failed to read config")
}
if viper.GetBool("general.debug") {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
token := viper.GetString("telegram.apikey")
b, err := bot.New(token)
if err != nil {
log.Panic().Err(err).Msg("failed initializing telegram bot")
}
sender := telegram.NewTelegramSender(b)
ta := &twitch.StreamInfoProvider{}
ra := &restreamer.StreamInfoProvider{}
streamService := service.NewStreamService(ta, ra)
notificationService := service.NewNotificationService(sender, streamService)
var chats []domain.ChatConfig
err = viper.UnmarshalKey("chats", &chats)
if err != nil {
log.Panic().Err(err).Msg("failed to unmarshal config")
}
for _, chat := range chats {
for _, restreamerConfig := range chat.Streams.Restreamer {
notificationService.Register(chat.ChatID, &domain.StreamQuery{
UserID: restreamerConfig.ID,
BaseURL: restreamerConfig.BaseURL,
CustomURL: restreamerConfig.CustomURL,
Kind: domain.StreamKindRestreamer,
})
}
for _, twitchConfig := range chat.Streams.Twitch {
notificationService.Register(chat.ChatID, &domain.StreamQuery{
UserID: twitchConfig.Username,
Kind: domain.StreamKindTwitch,
})
}
}
notificationService.StartPolling(context.Background())
}