我在一个项目中工作,我有一个twitter机器人,在它的帐户中回复每条推文。
下面是我的代码:
var replybot = function() {
//The word that we are going to search in tweets
var word = 'hello';
//Variables to store the twitter user id and screen name to make a reply
var id_str, screen_name;
console.log('Bot started looking for the word ' + word + '.');
stream.on('tweet', tweetEvent );
function tweetEvent(tweet) {
var info_text = tweet.text;
if (info_text.indexOf(word) > -1) {
console.log(tweet.text); //Displays the tweet with the word
//We store the twitter id and the user screen name to make a reply
id_str = tweet.id_str;
screen_name = tweet.user.screen_name;
console.log('need do it once');
//Now we are going to reply the tweet
Twitter.post('statuses/update', {in_reply_to_status_id: id_str,
status: '@' + screen_name + ' I think you mean "goodbye"'},
function(error, tweet, response){
if(error) {
console.log(' Error');
}
else{
console.log('. Success!!!');
} // Tweet body
});
}
}
console.log('done');
}
replybot();
// 'reply' a tweet in every 25 minutes
setInterval(replybot, 1500000);我正在使用这个代码库:https://github.com/ttezel/twit。
但我有一个问题:当我运行上面的代码时,机器人在一条tweet上回复了这么多次,我不知道为什么。虽然我已经为这个函数设置了间隔。
我是node的新手,任何帮助都是很棒的!谢谢
发布于 2017-03-14 01:41:47
哦,很抱歉,我在这里永远有一个循环:
函数(错误、推文、响应)
不应该是tweet arg
https://stackoverflow.com/questions/42769591
复制相似问题