-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (46 loc) · 1.21 KB
/
index.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
var Twit = require('twit');
var wordfilter = require('wordfilter');
var T = new Twit(require('./config.js'));
var myText = require('./sample-text.js');
//a nice 'pick' function thanks to Darius Kazemi: https://github.com/dariusk
Array.prototype.pick = function() {
return this[Math.floor(Math.random()*this.length)];
};
//functions
function tweetOK(phrase) {
if (!wordfilter.blacklisted(phrase) && phrase !== undefined && phrase !== "" && tweetLengthOK(phrase)){
return true;
} else {
return false;
}
}
function tweetLengthOK(phrase) {
if (phrase.length <= 130){
return true;
} else {
return false;
}
}
function pickTweet(){
var tweetText = myText.pick();
if (tweetOK(tweetText)) {
return tweetText;
}
else {
tweetText = pickTweet();
}
}
function main(){
var textToTweet = pickTweet();
return new Promise((resolve, reject) => {
T.post('statuses/update', { status: textToTweet }, function(err, reply) {
if (err) {
reject(err)
}
else {
resolve({payload: 'yep, tweeted: '+ textToTweet});
}
});
})
};
exports.main = main;