-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
92 lines (79 loc) · 2.85 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const Discord = require('discord.js');
const fs = require('fs');
const i18n = require('i18n');
const client = new Discord.Client();
const moment = require('moment-timezone');
const config = require('config');
client.setMaxListeners(0);
const RoleDeterminer = require('./src/Helper/RoleDeterminer');
const commandList = new (require('./src/CommandContainer'));
const cache = new (require('./src/Cache'));
const dependencyGraph = {
'Discord': Discord,
'discordClient': client,
'commandPrefix': '!',
'commandList': commandList,
'https': require('https'),
'Date': Date,
'JSON': JSON,
'Cache': cache,
'child_process': require('child_process'),
'fs': fs,
'i18n': i18n,
'moment': moment,
'config': config,
'muteRepository': new (require('./src/Helper/MuteRepository')),
'writeToLog': require('./src/Helper/GenericLogger'),
'RoleDeterminer': RoleDeterminer
};
cache.initialize(dependencyGraph);
i18n.configure({
locales: config.languages.locales,
directory: __dirname + '/locales',
defaultLocale: config.languages.default,
autoReload: true,
updateFiles: true,
});
const commandFiles = fs.readdirSync('./src/Command');
for (const key in commandFiles) {
if (!commandFiles.hasOwnProperty(key)) continue;
const file = commandFiles[key];
const command = new (require(`./src/Command/${file}`));
command.initialize(dependencyGraph);
/* Add to the command container */
commandList.add(command.commandName, command);
command.commandAliases.forEach(alias => commandList.add(alias, command));
}
const utilityFiles = fs.readdirSync('./src/Utility');
for (const key in utilityFiles) {
if (!utilityFiles.hasOwnProperty(key)) continue;
const file = utilityFiles[key];
let utility = new (require(`./src/Utility/${file}`));
utility.initialize(dependencyGraph);
}
/* Main command interceptor */
client.on('message', (message) => {
/* Ignore all DMs */
if (message.channel.type === 'dm') {
return;
}
/* If the member is muted, we won't execute their commands */
if (message.member && RoleDeterminer.isMuted(message.member)) {
return;
}
/* Retrieve command and tokens */
let messageText = message.content;
if (messageText.substr(0, dependencyGraph.commandPrefix.length) !== dependencyGraph.commandPrefix) return;
let tokens = messageText.split(' ');
let commandName = tokens[0].substr(dependencyGraph.commandPrefix.length).toLowerCase();
/* Get the command executor for the provided command and execute the command */
const command = commandList.get(commandName);
if (command) {
command.execute(message, tokens, commandName);
}
});
client.on('ready', () => {
client.user.setActivity("on Shotbow");
console.log("Successfully logged in!");
});
client.login(process.env.TOKEN ? process.env.TOKEN : config.token);