0
我已经在NODE JS中编写了一个bot,它将持续监控抽搐用户,当某些用户上线时,它会发送消息给用户在线的“group me”应用。 它工作正常。我的问题是,有时它发送消息,该用户在线但实际上用户处于脱机状态。 关于如何解决这个问题的任何想法?Twitch流状态显示在线。当用户离线
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));
});
\t
\t
\t
\t
}
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
theCall(0);
});
是的,当用户离线时它将为空。数据变量不同 –