-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
47 lines (39 loc) · 1.32 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
const BidiBot = require('./BidiBot');
const config = require('./config');
const http = require('http');
const herokuUrl = process.env.HEROKU_URL;
// Create and start listening on server.
http.createServer((req,res) =>{
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('This is a relay server');
}).listen(process.env.PORT || 8080);
// Ping server to keep alive.
setInterval(() => {
console.log('ping sent to server for keep alive');
http.get(`http://${ herokuUrl }.herokuapp.com`);
}, 100000);
// Config options
const slackKey = process.env.SLACK_KEY || config.slackKey,
slackName = process.env.SLACK_NAME || config.slackName,
slackChannel = process.env.SLACK_CHANNEL || config.slackChannel,
twitchName = process.env.TWITCH_NAME || config.twitchName,
twitchKey = process.env.TWITCH_KEY || config.twitchKey,
twitchChannel = process.env.TWITCH_CHANNEL || config.twitchChannel;
// Create BidiBot object
const bidiBot = new BidiBot({
slackKey,
slackName,
slackChannel,
twitchName,
twitchKey,
twitchChannel
});
// Start the bot.
bidiBot.start();
process.on('SIGTERM', () => {
console.log('Received SIGTERM, shutting down');
process.nextTick(() => process.exit());
});
process.on('exit', (code) => {
console.error('Process is about to exit with code ',code);
});