-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (86 loc) · 2.78 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
const Discord = require('discord.js');
const bot_config = require('./config.json');
const config = require('./bot-config.json');
const fs = require('fs');
const winston = require('winston');
const prefix = config.prefix;
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'log.log' }),
],
format: winston.format.printf(log => `[${log.level.toUpperCase()}] - ${log.message}`),
});
// Setup
const client = new Discord.Client();
const rangi = [];
let rangiT = [];
client.login(bot_config.BOT_TOKEN);
client.on('ready', () => {
logger.log('info', 'The bot is online!');
client.guilds.cache.map(guild => {
guild.roles.cache.map(role => {
rangi.push(role.id);
});
});
rangi.push(rangi.shift());
let i = 0;
for (i = 0; i < rangi.length; i++) {
rangi[i] = [rangi[i], i];
}
rangiT = (rangi.reverse().map(obj => {
const rObj = {};
rObj[obj[0]] = obj[1];
return rObj;
}));
});
client.on('debug', m => logger.log('debug', m));
client.on('warn', m => logger.log('warn', m));
client.commands = new Discord.Collection();
const commandFolders = fs.readdirSync('./commands');
console.log(commandFolders);
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.name, command);
}
}
client.on('message', message => {
const channelIDs = config.Channel_IDS;
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (!channelIDs.includes(message.channel.id)) return;
logger.log('debug', client.commands);
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.alias && cmd.alias.includes(commandName));
if (!command) return message.reply('Brak takiej komendy!');
const member = message.member;
let xd = 0;
member._roles.map(role => {
rangiT.forEach(element => {
if (element[role] != undefined) {
xd = (xd <= element[role]) ? (element[role]) : (xd);
}
});
},
);
if ((command.lvl < 0 || command.lvl > xd) && message.author.id != message.guild.ownerID) return;
if (command.args && !args.length) {
let reply = (`Nie podałeś odpowiedniej ilości argumentów, ${message.author}!`);
if (command.usage) {
reply += `\nPoprawne użycie: \`${prefix}${command.name} ${command.usage}\``;
}
message.channel.send(reply);
return;
}
try {
console.log('1');
if (command.name == 'help') args.push(xd);
command.execute(message, args);
}
catch (error) {
console.error(error);
message.reply(`Wystąpił błąd przy użyciu ${commandName}!`);
}
});