woomy/src/commands/help.js

174 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-01-25 10:02:43 +00:00
exports.run = (client, message, args, level) => {
2020-03-09 01:11:33 +00:00
embed = new Discord.MessageEmbed();
2020-01-25 10:02:43 +00:00
embed.setColor(client.embedColour(message));
var ran = false;
var output = "";
2020-03-10 01:20:28 +00:00
var commands = 0;
2020-01-25 10:02:43 +00:00
var prefix;
var currentCategory;
if(message.guild) {
prefix = message.settings.prefix;
} else {
prefix = client.config.defaultSettings.prefix;
};
if(!args[0]) {
2020-03-26 04:31:32 +00:00
embed.setTitle(`Command list`);
2020-01-25 10:02:43 +00:00
embed.setDescription(`For more information on a specific command use \`${prefix}help <command>\`\nFor the full command list use \`${prefix}help all\`\n`);
const myCommands = message.guild ? client.commands.filter(
cmd => client.levelCache[cmd.conf.permLevel] <= level
) : client.commands.filter(
cmd => client.levelCache[cmd.conf.permLevel] <= level && cmd.conf.guildOnly !== true
);
const commandNames = myCommands.keyArray();
const longest = commandNames.reduce(
(long, str) => Math.max(long, str.length),
0
);
const sorted = myCommands.array().sort(
(p, c) => p.help.category > c.help.category ? 1 : p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1
);
sorted.forEach( c => {
2020-03-26 04:31:32 +00:00
const cat = c.help.category;
2020-01-25 10:02:43 +00:00
if (currentCategory !== cat) {
if(ran == true) {
2020-03-19 10:37:34 +00:00
embed.addField(currentCategory + ` [${commands}]`, output)
2020-01-25 10:02:43 +00:00
output = "";
2020-03-10 01:20:28 +00:00
commands = 0;
2020-01-25 10:02:43 +00:00
}
currentCategory = cat;
ran = true
}
2020-03-26 04:31:32 +00:00
output += `\`${c.help.name}\` `;
2020-03-10 01:20:28 +00:00
commands = commands + 1;
2020-01-25 10:02:43 +00:00
});
2020-03-19 10:37:34 +00:00
embed.addField(currentCategory + ` [${commands}]`, output);
2020-01-25 10:02:43 +00:00
embed.addField(
"Invite me",
2020-05-04 20:04:40 +00:00
"[Click here](https://discord.com/oauth2/authorize?client_id=435961704145485835&permissions=8&scope=bot) to add me to your server",
2020-01-25 10:02:43 +00:00
true
);
embed.addField(
"Support",
"[Click here](https://discord.gg/HCF8mdv) if bot broke",
true
);
message.channel.send(embed);
return;
};
if(args[0].toLowerCase() == "all") {
2020-03-26 04:31:32 +00:00
embed.setTitle(`Command list`);
2020-01-25 10:02:43 +00:00
embed.setDescription(`For more information on a specific command use \`${prefix}help <command>\`\nFor the full command list use \`${prefix}help all\`\n`);
const myCommands = client.commands
const commandNames = myCommands.keyArray();
const longest = commandNames.reduce(
(long, str) => Math.max(long, str.length),
0
);
const sorted = myCommands.array().sort(
(p, c) => p.help.category > c.help.category ? 1 : p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1
);
sorted.forEach( c => {
2020-03-26 04:31:32 +00:00
const cat = c.help.category;
2020-01-25 10:02:43 +00:00
if (currentCategory !== cat) {
if(ran == true) {
2020-03-19 10:37:34 +00:00
embed.addField(currentCategory + ` [${commands}]`, output)
2020-01-25 10:02:43 +00:00
output = "";
2020-03-10 01:20:28 +00:00
commands = 0;
2020-01-25 10:02:43 +00:00
}
currentCategory = cat;
ran = true
}
2020-03-26 04:31:32 +00:00
output += `\`${c.help.name}\` `;
2020-03-10 01:20:28 +00:00
commands = commands + 1;
2020-01-25 10:02:43 +00:00
});
2020-03-26 04:31:32 +00:00
2020-03-19 10:37:34 +00:00
embed.addField(currentCategory + ` [${commands}]`, output);
2020-01-25 10:02:43 +00:00
embed.addField(
"Invite me",
2020-05-04 20:04:40 +00:00
"[Click here](https://discord.com/oauth2/authorize?client_id=435961704145485835&permissions=8&scope=bot) to add me to your server",
2020-01-25 10:02:43 +00:00
true
);
embed.addField(
"Support",
"[Click here](https://discord.gg/HCF8mdv) if bot broke",
true
);
message.channel.send(embed);
return;
};
if(args[0]) {
let command = args.shift().toLowerCase();
let cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command));
if(!client.commands.has(command)) {
return message.channel.send("<:error:466995152976871434> That command doesn't exist!")
};
command = client.commands.get(command);
var requiredPerms = "";
if(cmd.conf.requiredPerms.length > 0 ) {
requiredPerms = "`" + cmd.conf.requiredPerms.join("`, `") + "`";
} else {
requiredPerms = "None";
};
var aliases = "";
if(cmd.conf.aliases.length > 0 ) {
aliases = "`" + cmd.conf.aliases.join("`, `") + "`";
} else {
aliases = "None";
};
embed.setTitle(prefix + command.help.name);
embed.setDescription(
2020-03-09 01:11:33 +00:00
`• **Description:** ${command.help.description}\n• **Usage:** ${prefix + command.help.usage}\n• **Permission Level:** ${cmd.conf.permLevel} \n• **Guild Only:** ${cmd.conf.guildOnly}\n• **Aliases:** ${aliases}\n• **Required perms:** ${requiredPerms}`
2020-01-25 10:02:43 +00:00
);
embed.setFooter("Arguments in [] are required, <> are optional.");
message.channel.send(embed);
return;
};
};
exports.conf = {
enabled: true,
guildOnly: false,
aliases: ["h", "cmds"],
permLevel: "User",
requiredPerms: ["EMBED_LINKS"]
};
exports.help = {
name: "help",
category: "Utility",
description:
"Displays all the commands you are able to use.",
usage: "help <command> **OR** help all"
};