forked from devilesk/dota-ihl-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.56 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
require('dotenv').config({ path: process.env.NODE_ENV ? `.env.${process.env.NODE_ENV}` : '.env' });
const logger = require('./lib/logger');
const cache = require('./lib/cache');
const checkEnvironmentVariables = require('./lib/util/checkEnvironmentVariables');
const CommandDispatcher = require('discord.js-commando/src/dispatcher');
if (process.env.NODE_ENV !== 'production') {
// monkey patch shouldHandleMessage to handle other bot messages for testing
CommandDispatcher.prototype.shouldHandleMessage = function shouldHandleMessage(message, oldMessage) {
// Ignore partial messages
if (message.partial) return false;
if (message.author.id === this.client.user.id) return false;
// Ignore messages from users that the bot is already waiting for input from
if (this._awaiting.has(message.author.id + message.channel.id)) return false;
// Make sure the edit actually changed the message content
if (oldMessage && message.content === oldMessage.content) return false;
return true;
};
}
checkEnvironmentVariables([
'DB_NAME',
'DB_USERNAME',
'DB_PASSWORD',
'STEAM_API_KEY',
'TOKEN',
'OWNER_DISCORD_ID',
]);
const run = async () => {
await cache.connect();
const IHLManager = require('./lib/ihlManager');
const ihlManager = new IHLManager.IHLManager(process.env);
const client = IHLManager.createClient(process.env);
ihlManager.init(client);
};
run();
process.on('SIGTERM', () => {
logger.info('SIGTERM signal received. Shutting down...');
process.exit(0);
});