【发布时间】:2017-07-19 06:40:51
【问题描述】:
所以目前推特机器人是;
var fs = require('fs'),
path = require('path'),
Twit = require('twit'),
config = require(path.join(__dirname, 'config.js'));
var T = new Twit(config);
function pick_random_countermagic(){
var countermagic = [
'Force-of-Will.jpg',
'Cryptic-Commad.jpg',
'Counterspell.jpg',
];
return countermagic[Math.floor(Math.random() * countermagic.length)];
}
function upload_random_image(){
console.log('Opening an image...');
var image_path = path.join(__dirname, '/countermagic/' + pick_random_countermagic()),
b64content = fs.readFileSync(image_path, { encoding: 'base64' });
console.log('Uploading an image...');
T.post('media/upload', { media_data: b64content }, function (err, data, response) {
if (err){
console.log('ERROR');
console.log(err);
}
else{
console.log('Uploaded an image!');
T.post('statuses/update', {
media_ids: new Array(data.media_id_string)
},
function(err, data, response) {
if (err){
console.log('Error!');
console.log(err);
}
else{
console.log('Posted an image!');
}
}
);
}
});
}
setInterval(
upload_random_image,
10000
);
它目前所做的一切都是随机发布一张图片,这正是我想要的,但我希望它在该机器人发布推文时,或者当机器人正在积极回复机器人已发布但我的机器人尚未回复的所有推文......如果你知道我的意思。
这是我第一次制作 twitter 机器人,从技术上讲,这是我第一次真正使用 javascript 和 node.js。所以,是的,我只是迷路了。所以是的,任何帮助都会非常有帮助。
【问题讨论】:
标签: javascript node.js twitter