add youtube background

This commit is contained in:
Jay 2018-09-17 14:30:49 +08:00
parent e8db6fdab5
commit cfc1e43192
4 changed files with 46 additions and 0 deletions

View File

@ -19,6 +19,18 @@ type YoutubeChannel struct {
Groups []*YoutubeGroup `db:"-"` 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 - // GetYoutubeChannelWithID -
func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) { func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) {
err = x.Get(&yt, `select * from "public"."youtube_channel" where "id" = $1`, id) err = x.Get(&yt, `select * from "public"."youtube_channel" where "id" = $1`, id)

View File

@ -12,5 +12,6 @@ func SetBackground() {
c.AddFunc("0 * * * * *", readFacebookPage) c.AddFunc("0 * * * * *", readFacebookPage)
c.AddFunc("*/20 * * * * *", getStreamStatus) c.AddFunc("*/20 * * * * *", getStreamStatus)
c.AddFunc("*/5 * * * * *", checkOpay) c.AddFunc("*/5 * * * * *", checkOpay)
c.AddFunc("0 0 */3 * * *", checkYoutubeSubscribe)
c.Start() c.Start()
} }

View File

@ -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)
}
}

13
router/api/twitch.go Normal file
View File

@ -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
}