twitch streaming check ok
This commit is contained in:
@@ -2,16 +2,16 @@ package background
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/module/utils"
|
||||
"strings"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/model"
|
||||
"git.trj.tw/golang/mtfosbot/module/apis/line"
|
||||
"git.trj.tw/golang/mtfosbot/module/apis/twitch"
|
||||
)
|
||||
|
||||
func getStreamStatus() {
|
||||
fmt.Println("run twitch check")
|
||||
channels, err := model.GetAllChannel()
|
||||
channels, err := model.GetAllTwitchChannel()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -22,11 +22,45 @@ func getStreamStatus() {
|
||||
|
||||
info := twitch.GetUserStreamStatus(ids)
|
||||
fmt.Printf("info len: %d\n", len(info))
|
||||
if len(info) == 0 {
|
||||
return
|
||||
}
|
||||
for _, v := range info {
|
||||
fmt.Println(utils.ToMap(v))
|
||||
for _, ch := range channels {
|
||||
if v.UserID == ch.ID {
|
||||
go checkStream(ch, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkStream(ch *model.TwitchChannel) {
|
||||
func checkStream(ch *model.TwitchChannel, info *twitch.StreamInfo) {
|
||||
if info.ID == ch.LastStream {
|
||||
return
|
||||
}
|
||||
err := ch.GetGroups()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = ch.UpdateStream(info.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
link := fmt.Sprintf("https://twitch.tv/%s", ch.Name)
|
||||
for _, v := range ch.Groups {
|
||||
if v.Notify {
|
||||
tmpl := v.Tmpl
|
||||
if len(tmpl) > 0 {
|
||||
tmpl = strings.Replace(tmpl, "{txt}", info.Title, -1)
|
||||
tmpl = strings.Replace(tmpl, "{link}", link, -1)
|
||||
} else {
|
||||
tmpl = fmt.Sprintf("%s\n%s", info.Title, link)
|
||||
}
|
||||
msg := line.TextMessage{
|
||||
Text: tmpl,
|
||||
}
|
||||
line.PushMessage(v.ID, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user