-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathserver.js
81 lines (59 loc) · 1.97 KB
/
server.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Setting things up. */
var path = require('path'),
fs = require("fs"),
express = require('express'),
app = express(),
Twit = require('twit'),
config = {
/* Be sure to update the .env file with your API keys. See how to get them: https://botwiki.org/tutorials/how-to-create-a-twitter-app */
twitter: {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
}
},
T = new Twit(config.twitter);
app.use(express.static('public'));
/* You can use uptimerobot.com or a similar site to hit your /BOT_ENDPOINT to wake up your app and make your Twitter bot tweet. */
app.all("/" + process.env.BOT_ENDPOINT, function (request, response) {
/* The example below tweets out "Hello world!". */
var resp = response;
/*create mytweet*/
var mytweet = "The next big thing is: ";
var X = "";
var Y = "";
fs.readFile("X.txt", 'utf8', function(err, data){
if(err) throw err;
var stringdata = data +"";
var lines = stringdata.split('\n');
X = lines[Math.floor(Math.random()*lines.length)];
fs.readFile("Y.txt", function(err, data){
if(err) throw err;
var stringdata = data + "";
var lines = stringdata.split('\n');
console.log(lines);
Y = lines[Math.floor(Math.random()*lines.length)];
mytweet += X;
mytweet += " but for ";
console.log("y is: " + Y);
mytweet += Y;
console.log("my tweet: " + mytweet);
T.post('statuses/update', {
status: mytweet
}, function(err, data, response) {
if (err){
resp.sendStatus(500);
console.log('Error!');
console.log(err);
}
else{
resp.sendStatus(200);
}
});
});
});
});
var listener = app.listen(process.env.PORT, function () {
console.log('Your bot is running on port ' + listener.address().port);
});