add recheck twitch login change

This commit is contained in:
Jay 2018-12-13 16:56:48 +08:00
parent 2f49a26fea
commit 07281f2ff1
2 changed files with 60 additions and 0 deletions

View File

@ -172,6 +172,58 @@ func GetUserDataByName(login string) (userInfo *UserInfo) {
return apiData.Data[0]
}
// GetUserDataByID -
func GetUserDataByID(id string) (userInfo *UserInfo) {
if len(id) == 0 {
return
}
qsValue := url.Values{}
qsValue.Add("id", id)
url, ok := getURL("/helix/users", qsValue.Encode())
if !ok {
return
}
reqObj := apis.RequestObj{}
reqObj.Headers = getHeaders()
reqObj.Method = "GET"
reqObj.URL = url
req, err := apis.GetRequest(reqObj)
if err != nil {
return
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
return
}
apiData := struct {
Data []*UserInfo `json:"data"`
}{}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
err = json.Unmarshal(bodyBytes, &apiData)
if err != nil {
return
}
if len(apiData.Data) == 0 {
return
}
return apiData.Data[0]
}
// StreamInfo -
type StreamInfo struct {
ID string `json:"id"`

View File

@ -50,6 +50,14 @@ func checkStream(ch *model.TwitchChannel, info *twitch.StreamInfo) {
if time.Now().Unix()-ch.Mtime.Unix() < 600 {
return
}
chData := twitch.GetUserDataByID(ch.ID)
if chData != nil {
if chData.Login != ch.Name {
ch.UpdateName(chData.Login)
}
}
link := fmt.Sprintf("https://twitch.tv/%s", ch.Name)
for _, v := range ch.Groups {
if v.Notify {