From cfc1e4319252bb1ab0f2d5748598ee79838a266c Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 17 Sep 2018 14:30:49 +0800 Subject: [PATCH] add youtube background --- model/youtube_channel.go | 12 ++++++++++++ module/background/background.go | 1 + module/background/youtube.go | 20 ++++++++++++++++++++ router/api/twitch.go | 13 +++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 module/background/youtube.go create mode 100644 router/api/twitch.go 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 +}