add help cmd
parent
e961beb036
commit
4cd7b0f12f
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ clean:
|
||||||
@-rm -rf build
|
@-rm -rf build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
tsc -p ./tsconfig.json
|
-tsc -p ./tsconfig.json
|
||||||
|
|
||||||
run:
|
run:
|
||||||
cd build && node main
|
cd build && node main
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"eris": "bsian03/eris#bsian",
|
"eris": "bsian03/eris#bsian",
|
||||||
|
"eris-pagination": "bsian03/eris-pagination#dev",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"mongoose": "^5.9.9",
|
"mongoose": "^5.9.9",
|
||||||
"signale": "^1.4.0",
|
"signale": "^1.4.0",
|
||||||
|
|
|
@ -118,6 +118,16 @@ export default class Util {
|
||||||
return arrayString;
|
return arrayString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public splitFields(fields: { name: string, value: string, inline?: boolean }[]): { name: string, value: string, inline?: boolean }[][] {
|
||||||
|
let index = 0;
|
||||||
|
const array: {name: string, value: string, inline?: boolean}[][] = [[]];
|
||||||
|
while (fields.length) {
|
||||||
|
if (array[index].length >= 25) { index += 1; array[index] = []; }
|
||||||
|
array[index].push(fields[0]); fields.shift();
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public decimalToHex(int: number): string {
|
public decimalToHex(int: number): string {
|
||||||
const hex = int.toString(16);
|
const hex = int.toString(16);
|
||||||
return '#000000'.substring(0, 7 - hex.length) + hex;
|
return '#000000'.substring(0, 7 - hex.length) + hex;
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
import { createPaginationEmbed } from 'eris-pagination';
|
||||||
|
import { Message } from 'eris';
|
||||||
|
import { Client, Command, RichEmbed } from '../class';
|
||||||
|
|
||||||
|
export default class Help extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'help';
|
||||||
|
this.description = 'Information about commands.';
|
||||||
|
this.usage = 'help [command]';
|
||||||
|
this.permissions = 0;
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line consistent-return
|
||||||
|
public async run(message: Message, args: string[]) {
|
||||||
|
try {
|
||||||
|
if (args.length > 0) {
|
||||||
|
const command = this.client.commands.get(args[0].toLowerCase());
|
||||||
|
if (!command) return this.error(message.channel, 'The command you provided doesn\'t exist.');
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle(`${this.client.config.prefix}${command.name}`);
|
||||||
|
embed.addField('Description', command.description ?? '-');
|
||||||
|
embed.addField('Usage', command.usage ?? '-');
|
||||||
|
if (command.aliases.length > 0) {
|
||||||
|
embed.addField('Aliases', command.aliases.map((alias) => `${this.client.config.prefix}${alias}`).join(', '));
|
||||||
|
}
|
||||||
|
let description: string = '';
|
||||||
|
if (!command.enabled) {
|
||||||
|
description += 'This command is disabled.';
|
||||||
|
}
|
||||||
|
if (command.guildOnly) {
|
||||||
|
description += 'This command can only be ran in a guild.';
|
||||||
|
}
|
||||||
|
embed.setDescription(description);
|
||||||
|
switch (command.permissions) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
embed.addField('Permissions', 'Associates+');
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
embed.addField('Permissions', 'Core Team+');
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
embed.addField('Permissions', 'Moderators, Supervisor, & Board of Directors');
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
embed.addField('Permissions', 'Technicians, Supervisor, & Board of Directors');
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
embed.addField('Permissions', 'Moderators, Technicians, Supervisor, & Board of Directors');
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
embed.addField('Permissions', 'Supervisor+');
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
embed.addField('Permissions', 'Board of Directors');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||||
|
embed.setTimestamp();
|
||||||
|
return message.channel.createMessage({ embed });
|
||||||
|
}
|
||||||
|
const cmdList: Command[] = [];
|
||||||
|
this.client.commands.forEach((c) => cmdList.push(c));
|
||||||
|
const commands = this.client.commands.map((c) => {
|
||||||
|
const aliases = c.aliases.map((alias) => `${this.client.config.prefix}${alias}`).join(', ');
|
||||||
|
let perm: string;
|
||||||
|
switch (c.permissions) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
perm = 'Associates+';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
perm = 'Core Team+';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
perm = 'Moderators, Supervisor, & Board of Directors';
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
perm = 'Technicians, Supervisor, & Board of Directors';
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
perm = 'Moderators, Technicians, Supervisor, & Board of Directors';
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
perm = 'Supervisor+';
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
perm = 'Board of Directors';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return { name: `${this.client.config.prefix}${c.name}`, value: `**Description:** ${c.description}\n**Aliases:** ${aliases}\n**Usage:** ${c.usage}\n**Permissions:** ${perm}`, inline: false };
|
||||||
|
});
|
||||||
|
const splitCommands = this.client.util.splitFields(commands);
|
||||||
|
const cmdPages: RichEmbed[] = [];
|
||||||
|
splitCommands.forEach((splitCmd) => {
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTimestamp(); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||||
|
embed.setDescription(`Command list for ${this.client.user.username}`);
|
||||||
|
splitCmd.forEach((c) => embed.addField(c.name, c.value, c.inline));
|
||||||
|
return cmdPages.push(embed);
|
||||||
|
});
|
||||||
|
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
|
||||||
|
return createPaginationEmbed(message, cmdPages);
|
||||||
|
} catch (err) {
|
||||||
|
this.client.util.handleError(err, message, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue