chomens-bot-js/commands/help.js

120 lines
4.9 KiB
JavaScript
Raw Normal View History

2022-08-14 05:51:45 -04:00
/* eslint-disable no-var */
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
module.exports = {
name: 'help',
alias: ['heko', 'cmds', 'commands'],
description: 'Shows the help',
usage: '[command]',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args) {
2022-11-08 09:01:38 -05:00
const generalCommands = [];
const trustedCommands = [];
const ownerCommands = [];
function component(command, color) {
return {
text: command.name + ' ',
color,
hoverEvent: {
action: 'show_text',
contents: [{
text: 'Click here to see the information for this command',
color: 'green',
}],
},
clickEvent: {
action: 'run_command',
value: `${prefix}help ${command.name}`,
},
};
};
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-07 08:08:29 -05:00
if (command.trusted !== 0) continue;
2022-11-08 09:01:38 -05:00
generalCommands.push(component(command, 'green'));
2022-08-14 05:51:45 -04:00
}
for (const command of bot.command_handler.commands) {
2022-11-07 08:08:29 -05:00
if (command.trusted !== 1) continue;
2022-11-08 09:01:38 -05:00
trustedCommands.push(component(command, 'red'));
2022-08-14 05:51:45 -04:00
}
for (const command of bot.command_handler.commands) {
2022-11-07 08:08:29 -05:00
if (command.trusted !== 2) continue;
2022-11-08 09:01:38 -05:00
ownerCommands.push(component(command, 'dark_red'));
2022-08-14 05:51:45 -04:00
}
2022-11-07 08:08:29 -05:00
if (typeof args[0] !== 'undefined') {
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-08 09:01:38 -05:00
function run() {
2022-08-14 05:51:45 -04:00
let discordSupported;
let alias = command.name;
2022-11-07 07:26:38 -05:00
if (typeof command.discordExecute === 'undefined') {
2022-08-14 05:51:45 -04:00
discordSupported = 'false';
} else {
discordSupported = 'true';
}
2022-11-07 08:08:29 -05:00
if (command.alias.toString() !== '') {
2022-08-14 05:51:45 -04:00
alias = command.alias.join(', ');
}
bot.tellraw('@a', [{text: prefix + command.name, color: 'gold'}, {text: ` (${alias})`, color: 'white'}, {text: ' - ', color: 'gray'}, {text: command.description, color: 'gray'}]);
bot.tellraw('@a', [{text: 'Trust level: ', color: 'green'}, {text: command.trusted, color: 'yellow'}]);
bot.tellraw('@a', [{text: 'Supported on Discord: ', color: 'green'}, {text: discordSupported, color: 'gold'}]);
bot.tellraw('@a', [{text: prefix + command.name, color: 'gold'}, {text: ' ' + command.usage, color: 'aqua'}]);
2022-08-14 05:51:45 -04:00
}
2022-11-08 09:01:38 -05:00
if (command.name === args[0]) run();
2022-08-14 05:51:45 -04:00
for (const alias of command.alias) {
2022-11-08 09:01:38 -05:00
if (alias === args[0]) run();
2022-08-14 05:51:45 -04:00
}
};
} else {
2022-11-08 09:01:38 -05:00
const pre = [{text: 'Commands ', color: 'gray'}, {text: '(', color: 'dark_gray'}, {text: 'Length: ', color: 'gray'}, {text: bot.command_handler.commands.length, color: 'green'}, {text: ') ', color: 'dark_gray'}, {text: '(', color: 'dark_gray'}, {text: '⬤ Public', color: 'green'}, {text: ' ⬤ Trusted', color: 'red'}, {text: ' ⬤ Owner', color: 'dark_red'}, {text: ') - ', color: 'dark_gray'}];
bot.tellraw('@a', [pre, generalCommands, trustedCommands, ownerCommands]);
2022-08-14 05:51:45 -04:00
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) {
2022-11-07 08:08:29 -05:00
if (typeof args[0] !== 'undefined') {
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-08 09:01:38 -05:00
function run() {
2022-08-14 05:51:45 -04:00
let discordSupported;
let alias = command.name;
2022-11-07 07:26:38 -05:00
if (typeof command.discordExecute === 'undefined') {
2022-08-14 05:51:45 -04:00
discordSupported = 'false';
} else {
discordSupported = 'true';
}
2022-11-07 08:08:29 -05:00
if (command.alias.toString() !== '') {
2022-08-14 05:51:45 -04:00
alias = command.alias.join(', ');
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`${prefix + command.name} (${alias}) - ${command.description}`)
.setDescription(`Trust level: ${command.trusted}` + '\n' +
`Supported: ${discordSupported}` + '\n' +
`${prefix + command.name} ${command.usage}`,
);
2022-08-14 05:51:45 -04:00
channeldc.send({embeds: [Embed]});
}
2022-10-14 04:46:41 -04:00
2022-11-08 09:01:38 -05:00
if (command.name === args[0]) run();
for (const alias of command.alias) {
2022-11-08 09:01:38 -05:00
if (alias === args[0]) run();
2022-08-14 05:51:45 -04:00
}
};
} else {
let supportedCommands = '';
let unsupportedCommands = '';
for (const command of bot.command_handler.commands) {
2022-11-07 07:26:38 -05:00
if (typeof command.discordExecute === 'undefined') continue;
2022-08-14 05:51:45 -04:00
supportedCommands += command.name + ' ';
}
for (const command of bot.command_handler.commands) {
2022-11-07 08:08:29 -05:00
if (typeof command.discordExecute !== 'undefined') continue;
2022-08-14 05:51:45 -04:00
unsupportedCommands += command.name + ' ';
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`Commands (Length: ${bot.command_handler.commands.length})`)
2022-08-14 05:51:45 -04:00
.setDescription('**Supported Commands**\n' + supportedCommands + '\n**Unsupported Commands**\n' + unsupportedCommands);
channeldc.send({embeds: [Embed]});
}
},
};