this is currently a complete mess

This commit is contained in:
Emily 2020-10-17 16:01:05 +11:00
parent a7f43998ad
commit e877a50740

View file

@ -10,20 +10,24 @@ module.exports = class {
async run (message) { async run (message) {
if (message.author.bot) return; if (message.author.bot) return;
const userPrefix = await this.client.db.getUserKey(message.author.id, 'prefix'); let data = {};
const userBlacklisted = await this.client.db.getUserKey(message.author.id, 'blacklisted'); data.user = await this.client.db.getUser(message.author.id);
const prefixes = [userPrefix]; const prefixes = [data.user.prefix];
if (message.guild) prefixes.push(await this.client.db.getGuildKey(message.guild.id, 'prefix')); if (message.guild) {
data.guild = await this.client.db.getGuild(message.guild.id);
// data.member = await this.client.db.getMember(message.guild.id, message.author.id);
prefixes.push(data.guild.prefix);
}
prefixes.push(`<@${this.client.user.id}> `, `<@!${this.client.user.id}> `) prefixes.push(`<@${this.client.user.id}> `, `<@!${this.client.user.id}> `);
let prefix; let prefix;
for (const thisPrefix of prefixes) { for (const thisPrefix of prefixes) {
if (message.content.startsWith(thisPrefix)) prefix = thisPrefix; if (message.content.startsWith(thisPrefix)) prefix = thisPrefix;
}; }
if (message.content.indexOf(prefix) !== 0) return; if (message.content.indexOf(prefix) !== 0) return;
@ -31,15 +35,10 @@ module.exports = class {
message.prefix = '@Woomy '; message.prefix = '@Woomy ';
} else { } else {
message.prefix = prefix; message.prefix = prefix;
}; }
// Naughty users can't run commands! // Naughty users can't run commands!
if (message.guild) { /* TO-DO: CREATE BLACKLIST */
const check = await this.client.db.getMemberKey(message.guild.id, message.author.id, 'blacklisted')
if (check === true) { return };
};
if (userBlacklisted) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g); const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
@ -53,9 +52,9 @@ module.exports = class {
if (message.guild) { if (message.guild) {
if (!message.channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) { if (!message.channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) {
try { try {
return message.author.send(`I don't have permission to speak in \`#${message.channel.name}\`, Please ask a moderator to give me the send messages permission!`) return message.author.send(`I don't have permission to speak in \`#${message.channel.name}\`, Please ask a moderator to give me the send messages permission!`);
} catch (err) {}; } catch (err) {} //eslint-disable-line no-empty
}; }
/* NEED A WAY TO STORE ARRAYS IN A HASH /* NEED A WAY TO STORE ARRAYS IN A HASH
if (data.guild.disabledCommands.includes(cmd.help.name)) { if (data.guild.disabledCommands.includes(cmd.help.name)) {
@ -70,19 +69,19 @@ module.exports = class {
}; };
}; };
*/ */
}; }
if (cmd && cmd.conf.enabled === false) { if (cmd && cmd.conf.enabled === false) {
return message.channel.send('This command has been disabled by my developers.'); return message.channel.send('This command has been disabled by my developers.');
}; }
if (cmd && cmd.conf.devOnly && this.client.functions.isDeveloper(message.author.id) !== true) { if (cmd && cmd.conf.devOnly && this.client.functions.isDeveloper(message.author.id) !== true) {
return message.channel.send("devs only!"); return message.channel.send('devs only!');
}; }
if (cmd && !message.guild && cmd.conf.guildOnly === true) { if (cmd && !message.guild && cmd.conf.guildOnly === true) {
return message.channel.send("This command is unavailable via private message. Please run this command in a guild."); return message.channel.send('This command is unavailable via private message. Please run this command in a guild.');
}; }
// Permission handler, for both Woomy and the user // Permission handler, for both Woomy and the user
if (message.guild) { if (message.guild) {
@ -94,21 +93,21 @@ module.exports = class {
}); });
if (missingUserPerms.length > 0) { if (missingUserPerms.length > 0) {
missingUserPerms = '`' + (missingUserPerms.join('`, `')) + '`' missingUserPerms = '`' + (missingUserPerms.join('`, `')) + '`';
return message.channel.send(`You don't have sufficient permissions to run this command! Missing: ${missingUserPerms}`); return message.channel.send(`You don't have sufficient permissions to run this command! Missing: ${missingUserPerms}`);
}; }
// Bot // Bot
let missingBotPerms = new Array(); let missingBotPerms = [];
cmd.conf.botPerms.forEach((p) => { cmd.conf.botPerms.forEach((p) => {
if (!message.channel.permissionsFor(message.guild.member(this.client.user)).has(p)) missingBotPerms.push(p); if (!message.channel.permissionsFor(message.guild.member(this.client.user)).has(p)) missingBotPerms.push(p);
}); });
if (missingBotPerms.length > 0) { if (missingBotPerms.length > 0) {
missingBotPerms = '`' + (missingBotPerms.join('`, `')) + '`' missingBotPerms = '`' + (missingBotPerms.join('`, `')) + '`';
return message.channel.send(`I can't run this command because I'm missing these permissions: ${missingBotPerms}`); return message.channel.send(`I can't run this command because I'm missing these permissions: ${missingBotPerms}`);
}; }
} }
// Cooldown // Cooldown
@ -124,16 +123,16 @@ module.exports = class {
setTimeout(() => { setTimeout(() => {
this.client.cooldowns.get(cmd.help.name).delete(message.author.id); this.client.cooldowns.get(cmd.help.name).delete(message.author.id);
}, this.client.commands.get(cmd.help.name).conf.cooldown); }, this.client.commands.get(cmd.help.name).conf.cooldown);
}; }
message.flags = []; message.flags = [];
while (args[0] &&args[0][0] === "-") { while (args[0] &&args[0][0] === '-') {
message.flags.push(args.shift().slice(1)); message.flags.push(args.shift().slice(1));
} }
cmd.run(message, args); cmd.run(message, args);
this.client.logger.cmd(`Command ran: ${message.content}`); this.client.logger.cmd(`Command ran: ${message.content}`);
// TODO: Command caching if it"s worth it // TODO: Command caching if it's worth it
} }
}; };