-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
86 lines (80 loc) · 2.22 KB
/
bot.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var twit = require('twit')
var config = require('./config.ts')
var Twitter = new twit(config)
var retweetList = 'alexhoffman617/test'
var hourInterval = 1
var minuteInterval = 0
var tweet = function(text) {
Twitter.post('statuses/update', { status: text }, function(err, data, response) {
if (err) {
console.log('There was a problem tweeting the message.', err)
}
})
}
async function searchTweets(): Promise<any> {
return new Promise(function(resolve) {
const date = new Date(new Date().setDate(new Date().getDate() - 1))
.toISOString()
.split('T')[0]
.replace('/', '-')
Twitter.get(
'search/tweets',
{
q: `list:${retweetList} since:${date} -filter:retweets cfp OR cfs OR "call for speakers" OR "call for proposals"`,
// result_type: 'recent',
lang: 'en',
// count: 1,
include_entities: false
},
function(err, data, response) {
// console.log(new Date().toISOString())
data.statuses.forEach(status => {
// console.log(
// '[' +
// status.user.name +
// '] - ' +
// status.text +
// ' **' +
// status.id_str +
// '**' +
// new Date(status.created_at).toISOString()
// )
})
resolve(data)
}
)
})
}
var retweet = function(id) {
Twitter.post('statuses/retweet', { id: id }, function(err, data, response) {
console.log(data)
})
}
async function continuousRetweet() {
console.log('run')
var foundTweets = await searchTweets()
foundTweets.statuses.filter(status => {
if (
new Date(status.created_at) >=
new Date(
new Date(new Date().setMinutes(new Date().getMinutes() - minuteInterval)).setHours(
new Date().getHours() - hourInterval
)
)
) {
retweet(status.id_str)
console.log(
'retweet!!! -- [' +
status.user.name +
'] - ' +
status.text +
' **' +
status.id_str +
'**' +
'--' +
status.created_at
)
}
})
}
setInterval(continuousRetweet, 1000 * 60 * minuteInterval + 1000 * 60 * 60 * hourInterval)