Twitch流状态显示在线.当用户离线时

Twitch stream status is showing online. while user is offline

本文关键字:用户 离线 在线 状态 显示 Twitch      更新时间:2023-09-26

我在NODE JS中编写了一个bot,它将持续监控twitch用户,当一些用户在线时,它将发送消息给"group me"应用程序,该用户在线。它工作得很好。我的问题是,有时它发送的消息,用户是在线的,但实际上用户是离线的。知道怎么解决这个问题吗?

见截图

var users = ["Statelinejay", "Ad_914", "Houssam06" ];
var messages = ["notsent", "notsent", "notsent" ];
var Client = require('node-rest-client').Client;
var client = new Client();
var express = require('express');
var request = require('request');
var app = express();
app.set('port', (process.env.PORT || 5000));
function theCall(index) {
    console.log('Processing ' + users[index]);
    client.get('https://api.twitch.tv/kraken/streams/' + users[index] + '?client_id=xxxxxxxxxxxxxxxxxxxxxxx', function (data, response) {
        if (data["stream"] === null) {
            messages[index] = 'notsent';
            console.log(users[index] + 'is offline');
        } else 
            //// Start of sending message
            var myJSONObject = {
                "bot_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "text": " https://www.twitch.tv/" + users[index]
            };
            if (messages[index] === 'notsent') {
                request.post({
                        url: " https://api.groupme.com/v3/bots/post",
                        method: "POST",
                        json: true, // <--Very important!!!
                        body: myJSONObject
                    },
                    function (error, response, body) {
                        console.log(error);
                    }
                );
                messages[index] = 'sent';
                console.log('message sent');
            }
            //// End of sending message
            console.log(users[index] + '  is online') ;
        }
        theCall((++index % users.length));
    });
	
	
	 
	
}
app.listen(app.get('port'), function() {
  console.log('Node app is running on port', app.get('port'));
  theCall(0);
});
 

你确定数据["流"]总是空每当流是离线的?它可以没有定义吗?你能不能试试

if (!data["stream"])

代替

if (data["stream"] === null)

?

如果这不起作用,你可以console.log你的数据和响应变量的假在线流,并更新问题吗?