-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (67 loc) · 2.44 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
const Discord = require("discord.js");
const client = new Discord.Client();
const settings = require('./settings.json');
const chalk = require('chalk');
const fs = require('fs');
const moment = require('moment');
const mongoose = require('mongoose')
const customisation = require('./customisation.json');
require('./util/eventLoader')(client);
const log = message => {
console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);
};
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir('./commands/', (err, files) => {
if (err) console.error(err);
log(`Loading a total of ${files.length} commands.`);
files.forEach(f => {
let props = require(`./commands/${f}`);
log(`Command Loaded! ${props.help.name}`);
client.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
});
});
});
//command reload
client.reload = command => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(`./commands/${command}`)];
let cmd = require(`./commands/${command}`);
client.commands.delete(command);
client.aliases.forEach((cmd, alias) => {
if (cmd === command) client.aliases.delete(alias);
});
client.commands.set(command, cmd);
cmd.conf.aliases.forEach(alias => {
client.aliases.set(alias, cmd.help.name);
});
resolve();
} catch (e){
reject(e);
}
});
};
mongoose.connect('mongodb://localhost:27017/DiscordDB', { useNewUrlParser: true, useUnifiedTopology: true }, err => {
if (err) return console.error(err);
console.log(chalk.bgGreen.black('Connected to MongoDB database!'));
});
//client command elevation(permLevel)
client.elevation = message => {
if (message.channel.type === 'dm') return;
let permlvl = 0;
if (message.member.hasPermission("MANAGE_MESSAGES")) permlvl = 1;
if (message.member.hasPermission("BAN_MEMBERS")) permlvl = 2;
if (message.member.hasPermission("MANAGE_GUILD")) permlvl = 3;
if (message.member.id === message.guild.ownerID) permlvl = 4;
if (message.author.id === settings.ownerid) permlvl = 5;
return permlvl;
};
//ping log
//var regToken = /[\w\d]{24}\.[\w\d]{6}\.[\w\d-_]{27}/g;
//client.on('debug', e => {
// console.log(e.replace(regToken, 'that was redacted'));
//});
client.login(settings.token);