-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (55 loc) · 1.67 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
56
57
58
59
60
61
62
63
64
65
66
67
68
const Discord = require('discord.js');
const http = require('http');
const logger = require('winston');
const { responseFactory } = require('./factories/responseFactory');
const { token, dbURI } = require('./config.json');
const { initMongoose } = require('./utils/mongooseUtil');
const { GET } = require('./utils/xhrUtil')
// connect mongo
initMongoose(process.env.dbURI || dbURI);
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
const bot = new Discord.Client();
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
// user, userID, channelID, message, evt
bot.on('message', async function (req) {
if (req.author.id === bot.user.id) {
return;
}
const {
author,
content: message,
channel,
} = req;
const response = await responseFactory({
message,
channelId: channel.id,
userId: author.id
});
if (response) {
channel.send(response);
}
});
bot.login(token || process.env.DISCORD)
// HACK to keep FREE Heroku serve online
// heroku crashing if we are not listening to its port // if instance stay idle for more than 20 mins it goes off
http.createServer(function (req, res) {
res.end(); //end the response
}).listen(process.env.PORT || 3002);
async function wakeUp() {
await GET({
url: "https://safe-stream-53824.herokuapp.com"
});
console.log("WAKE UP DYNO");
return setTimeout(wakeUp, 1200000);
}
setTimeout(wakeUp, 1200000);