-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.js
53 lines (45 loc) · 1.28 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
var Twit = require('twit');
var wordfilter = require('wordfilter');
var T = new Twit(require('botfiles/config.js'));
var myText = require('botfiles/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();
}
}
exports.handler = function myBot(event, context) {
var textToTweet = pickTweet();
T.post('statuses/update', { status: textToTweet }, function(err, reply) {
if (err) {
console.log('error:', err);
context.fail();
}
else {
console.log('tweet:', reply);
context.succeed();
}
});
};