diff --git a/model/youtube_channel.go b/model/youtube_channel.go index 4eca8c0..8d950f9 100644 --- a/model/youtube_channel.go +++ b/model/youtube_channel.go @@ -19,6 +19,18 @@ type YoutubeChannel struct { Groups []*YoutubeGroup `db:"-"` } +// GetAllYoutubeChannels - +func GetAllYoutubeChannels() (yt []*YoutubeChannel, err error) { + err = x.Select(&yt, `select * from "public"."youtube_channel"`) + return +} + +// GetYoutubeChannelsWithExpire - +func GetYoutubeChannelsWithExpire(e int64) (yt []*YoutubeChannel, err error) { + err = x.Select(&yt, `select * from "public"."youtube_channel" where "expire" = -1 or "expire" < $1`, e) + return +} + // GetYoutubeChannelWithID - func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) { err = x.Get(&yt, `select * from "public"."youtube_channel" where "id" = $1`, id) diff --git a/module/background/background.go b/module/background/background.go index 6c20684..067b5a3 100644 --- a/module/background/background.go +++ b/module/background/background.go @@ -12,5 +12,6 @@ func SetBackground() { c.AddFunc("0 * * * * *", readFacebookPage) c.AddFunc("*/20 * * * * *", getStreamStatus) c.AddFunc("*/5 * * * * *", checkOpay) + c.AddFunc("0 0 */3 * * *", checkYoutubeSubscribe) c.Start() } diff --git a/module/background/youtube.go b/module/background/youtube.go new file mode 100644 index 0000000..a41b0dd --- /dev/null +++ b/module/background/youtube.go @@ -0,0 +1,20 @@ +package background + +import ( + "time" + + "git.trj.tw/golang/mtfosbot/model" + googleapis "git.trj.tw/golang/mtfosbot/module/apis/google" +) + +func checkYoutubeSubscribe() { + e := time.Now().Unix() + (4 * 60 * 60) + yt, err := model.GetYoutubeChannelsWithExpire(e) + if err != nil || len(yt) == 0 { + return + } + + for _, v := range yt { + googleapis.SubscribeYoutube(v.ID) + } +} diff --git a/router/api/twitch.go b/router/api/twitch.go new file mode 100644 index 0000000..100e4af --- /dev/null +++ b/router/api/twitch.go @@ -0,0 +1,13 @@ +package api + +import ( + "git.trj.tw/golang/mtfosbot/model" +) + +func sessionTypeTwitch(id string) (ch []*model.TwitchChannel, err error) { + return +} + +func sessionTypeSystem() (ch []*model.TwitchChannel, err error) { + return +}