This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore.js
66 lines (62 loc) · 2.41 KB
/
core.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
const Discord = require("discord.js");
const fs = require('fs');
const client = new Discord.Client({
disableEveryone:true,
disabledEvents: ['TYPING_START','CHANNEL_PINS_UPDATE','USER_NOTE_UPDATE','RELATIONSHIP_ADD','RELATIONSHIP_REMOVE'],
messageCacheLifetime:86400,
messageSweepInterval:600,
messageCacheMaxSize:100
});
if(!fs.existsSync('./db/config.json')) {
throw new Error('./db/config.json is missing! Exiting...');
}else{
client.config = require('./db/config.json');
if(!client.config.discord_token) throw 'Discord token is missing. Exiting';
}
fs.readFile('./db/guild.watch','utf-8',(err,data) => {
if(!err) client.guild = data.split(",")[0]
})
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir('./events/', (err, files) => {
if (err) console.error(err);
console.log(`[core/loader] Loading ${files.length} events.`);
files.forEach(file => {
if(file.split(".").slice(-1)[0] !== "js") return; //has to be .js file *cough* folder that doesnt exist *cough*
const eventName = file.split(".")[0];
try {
const event = require(`./events/${file}`);
if(!event || typeof event !== 'function') {
return console.warn(`[core/loader] \x1b[33mWarning: ${file} is not setup correctly!\x1b[0m`);
}
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
}catch(err) {
console.error(`[core/loader] \x1b[31mEvent ${file} had an error:\n ${err.message}\x1b[0m`);
}
});
});
fs.readdir('./commands/', (err, files) => {
if (err) console.error(err);
console.log(`[core/loader] Loading ${files.length} commands.`);
files.forEach(f => {
fs.stat(`./commands/${f}`, (err, stat) => {
if(f.split(".").slice(-1)[0] !== "js") return;
if(f.startsWith("_")) return;
try {
let props = require(`./commands/${f}`);
if(!props.help || !props.config) return console.warn(`[core/loader] \x1b[33mWarning: ${f} has no config or help value. \x1b[0m`);
props.help.description = props.help.description||'[No description provided]'
if(props.init) props.init(client);
props.help.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
});
client.commands.set(props.help.name, props);
}catch(err) {
console.error(`[core/loader] \x1b[31mCommand ${f} had an error:\n ${err.message}\x1b[0m`);
}
});
});
});
/* end of loading */
client.login(client.config.discord_token);