-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
52 lines (36 loc) · 1.21 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
var Twit = require("twit");
var tracery = require("tracery-grammar");
var T = new Twit(require("./secrets"));
var grammar = tracery.createGrammar(require("./grammar.json")); //loads json object with grammar from file
//stream of tweet mentions
var stream = T.stream('statuses/filter', {
track: ['@queertheorybot']
});
stream.on('tweet', function(tweet) {
var response = grammar.flatten('#question_origin#');
//ensures it is short enough for twitter
while (response.length > (140 - 2 - tweet.user.screen_name.length) {
response = grammar.flatten('#question_origin#');
};
//replies to mentions with a question
T.post('statuses/update', {
status: '@' + tweet.user.screen_name + ' ' + response,
in_reply_to_status_id: tweet.id_str
},
function (err, data, response) {
console.log(data);
});
});
function postTweet() {
//generates and posts a new tweet
var tweet = grammar.flatten('#origin#');
//ensures it is short enough for twitter
while (tweet.length > 140) {
tweet = grammar.flatten('#origin#');
};
T.post('statuses/update', { status: tweet }, function(err, data, response) {
console.log(data);
});
}
//post every 3 hours: 1000 (ms) * 60 (s) * 60 (m) * 3 (h)s
setInterval(postTweet,1000*60*60*3);