-
Notifications
You must be signed in to change notification settings - Fork 0
/
TweetDeleter.js
41 lines (37 loc) · 1.12 KB
/
TweetDeleter.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
module.exports = class TweetDeleter {
constructor(twitterClient, maxTweetAge, keybaseTweetId) {
this.twitterClient = twitterClient
this.maxTweetAge = maxTweetAge
this.keybaseTweetId = keybaseTweetId
}
run() {
return this.twitterClient.get('statuses/user_timeline', {
count: 200
})
.then(({data: tweets}) => {
let deleteRequests = tweets
.filter(tweet => {
return new Date() - new Date(tweet.created_at) > this.maxTweetAge
})
.filter(tweet => {
return tweet.id_str !== this.keybaseTweetId
})
.map(tweet => {
return new Promise((resolve, reject) => {
this.twitterClient.post('statuses/destroy/:id', {
id: tweet.id_str
})
.then(({data: deletedTweet}) => {
console.log(`Deleted tweet #${deletedTweet.id_str}: "${deletedTweet.text}"`)
resolve(deletedTweet)
})
.catch(err => {
console.log(err)
reject(err)
})
})
})
return Promise.all(deleteRequests)
})
}
}