-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclient.js
More file actions
66 lines (54 loc) · 2.31 KB
/
client.js
File metadata and controls
66 lines (54 loc) · 2.31 KB
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
const Discord = require('discord.js');
const util = require('apex-util');
const { isAdmin } = require('./botUtils.js');
const msg = require('./locale/messages.json');
// If language is blank, set default language to en
if (process.env.LANGUAGE === '') process.env.LANGUAGE = 'en';
const lang = process.env.LANGUAGE;
// If production server, set default debug mode to production setting
if (process.env.NODE_ENV === 'production' && !process.env.DEBUG_MODE) process.env.DEBUG_MODE = 0;
const client = new Discord.Client();
// Pre-load controllers
const controllers = require('./controllers')();
// Alert when ready
client.on('ready', () => {
util.log('Bot Online and Ready', 0);
});
// Listen for messages
client.on('message', (message) => {
// Check for ! prefix on message to ensure it is a command
if (message.content.charAt(0) === '!') {
util.log('Command message received', message.content, 0);
// Build basic help string
let helpString = msg.help.msg[lang];
// Process message against every controller
Object.keys(controllers).forEach((key) => {
// Instantiate the controller
const controllerInstance = new controllers[key](message);
util.log('Controller instance', controllerInstance, 5);
// Runs commands after constructor is called
controllerInstance.run();
// Loop through commands if help command and add to string
if (message.content.toLowerCase() === '!help') {
Object.keys(controllerInstance.commands).forEach((commandKey) => {
const commandInstance = controllerInstance.commands[commandKey];
// Check if command should be shown in help menu
if (commandInstance.showWithHelp) {
if (commandInstance.adminOnly && isAdmin(message.member)) {
helpString += `\n\n \`${commandInstance.example}\` **- Admin Only** \n\t ${commandInstance.description}`;
} else if (commandInstance.adminOnly && !isAdmin(message.member)) {
helpString += '';
} else {
helpString += `\n\n \`${commandInstance.example}\` \n\t ${commandInstance.description}`;
}
}
});
}
});
// If help command called, display string
if (message.content.toLowerCase() === '!help') {
message.reply(helpString);
}
}
});
client.login(process.env.TOKEN);