-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
57 lines (44 loc) · 1.14 KB
/
bot.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
console.log("Running!")
let Twit = require('twit')
let config = require('./config')
let T = new Twit(config)
// Selects a user stream
let stream = T.stream('user')
// When someone follows me
stream.on('follow', followed)
function followed(eventMsg) {
console.log("Following message!")
let screenName = eventMsg.source.screen_name
tweetMsg('Hi @' + screenName + ' thanks for following me!')
}
// Tweet random numbers
tweetIt()
setInterval(tweetIt, 1000 * 30)
function tweetIt() {
let r = Math.floor(Math.random() * 9999)
let tweet = {
status: 'Tweeting a random number: ' + r + '!'
}
T.post('statuses/update', tweet, tweeted)
function tweeted(err, data, response) {
if (err) {
console.log("Something wrong with the random number!")
} else {
console.log("Tweeted a number!")
}
}
}
// Tweets thank you message
function tweetMsg(txt) {
let tweet = {
status: txt
}
T.post('statuses/update', tweet, tweeted)
function tweeted(err, data, response) {
if (err) {
console.log("Something wrong with the thank you message!")
} else {
console.log("Tweeted a thank you message!")
}
}
}