-
Notifications
You must be signed in to change notification settings - Fork 5
/
flooder.js
58 lines (49 loc) · 1.69 KB
/
flooder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('fs');
exports.run = (client, reply_to_status_id, statuses) => {
var p = Promise.resolve({ id_str: reply_to_status_id });
statuses.forEach((status) => {
p = p.then((tweet) => {
var in_reply_to_status_id = tweet.id_str;
if (status.media) {
return updateMedia(client, status)
.then((media) => {
return updateStatus(this, client, status, media.media_id_string, in_reply_to_status_id);
});
} else {
return updateStatus(this, client, status, null, in_reply_to_status_id);
}
}).catch((error) => {
if (Array.isArray(error)) {
error.forEach(e => console.log(`Error detail - code: ${e.code} msg: ${e.message}`));
} else {
console.error(`An error occurred, please clean and retry. Details: ${error}`);
}
process.exit(1);
});
});
};
exports.dumpStatus = (status) => {
if (status.media && status.text) {
console.log(`Updating status(DT): ${status.text}`);
console.log(`Updating status(DM): ${status.media}`);
} else if (status.media) {
console.log(`Updating status(OM): ${status.media}`);
} else {
console.log(`Updating status(OT): ${status.text}`);
}
};
const updateStatus = (that, client, status, media_ids, in_reply_to_status_id) => {
that.dumpStatus(status);
return client.post('statuses/update',
{
status: status.text,
media_ids: media_ids,
in_reply_to_status_id: in_reply_to_status_id
});
};
const updateMedia = (client, status) => {
var data = fs.readFileSync(status.media);
console.log(`Uploading the media file ${status.media}`);
// Post the media file
return client.post('media/upload', { media: data });
};