-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (64 loc) · 2.23 KB
/
main.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
const Discord = require("discord.js");
const { resolve, basename } = require('path');
const fs = require('fs');
const config = require("./config.json")
const startTime = Date.now()
class kartoffel extends Discord.Client {
constructor(prefix, options={}) {
super(options);
this.prefix = prefix;
this.embed = require("./embed");
this.commands = new Map();
this.categories = new Map();
load();
this.login(config.bot.token);
DBInit();
}
}
const client = new kartoffel(config.bot.prefix);
async function getFiles(dir) {
const subdirs = await fs.readdirSync(dir);
const files = await Promise.all(subdirs.map(async (subdir) => {
const res = resolve(dir, subdir);
return (await fs.statSync(res)).isDirectory() ? getFiles(res) : res;
}));
return files.reduce((a, f) => a.concat(f), []);
}
async function load() {
let commandList = await getFiles("commands")
let commandCateg = await fs.readdirSync("commands")
for (i = 0; i < commandList.length; i++) {
let item = commandList[i];
commandCateg.forEach(categ => {
if(!client.categories.get(categ)) client.categories.set(categ, categ)
})
if (item.match(/\.js$/)) {
delete require.cache[require.resolve(`${item}`)];
var commandcategory
commandCateg.forEach(categ => {
if(item.includes(categ)) commandcategory = categ
})
client.commands.set(basename(item).slice(0, -3), [require(`${item}`), commandcategory]);
}
}
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
console.log(client.commands);
}
// Spin up Sequelize and connect to MySQL
// Author: InterXellar (Filip M.)
function DBInit() {
let db = require('./util/DBImpl');
db.SequelizeInit();
}
exports.startUpTime = function() {
return this.startTime
}