forked from jsha/blocktogether
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unblock-all.js
70 lines (66 loc) · 1.72 KB
/
unblock-all.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
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
(function() {
/**
* Script to block a list of screen names using credentials for a given user id
*/
var twitterAPI = require('node-twitter-api'),
Q = require('q'),
fs = require('fs'),
util = require('./util'),
setup = require('./setup');
var twitter = setup.twitter,
logger = setup.logger,
BtUser = setup.BtUser,
TwitterUser = setup.TwitterUser,
BlockBatch = setup.BlockBatch,
Block = setup.Block;
if (process.argv.length < 3) {
logger.fatal('Usage: js unblock-all.js screen_name');
process.exit();
}
function unblock5000(user) {
return Q.ninvoke(twitter, 'blocks', 'ids', {
stringify_ids: true,
}, user.access_token,
user.access_token_secret
).then(function(results) {
var ids = results[0].ids;
logger.info('Got', ids.length, 'blocks');
if (ids.length === 0) {
return Q.resolve(false /* moreBlocks */);
} else {
return util.slowForEach(ids, 120, function(uid) {
logger.info('Unblocking', uid);
return Q.ninvoke(twitter, 'blocks', 'destroy', {
user_id: uid,
skip_status: 1
}, user.access_token, user.access_token_secret
).catch(function(err) {
logger.error(err);
});
}).thenResolve(true);
}
});
}
BtUser
.find({
where: {
screen_name: process.argv[2]
}
}).then(function(user) {
if (!user) {
logger.fatal('No user', process.argv[2]);
process.exit(1);
}
function unblockAll() {
return unblock5000(user).then(function(moreBlocks) {
if (moreBlocks) return unblockAll();
});
}
return unblockAll().then(function() {
logger.info('Done.');
})
}).catch(function(err) {
logger.error(err);
});
})();