add help cmd

merge-requests/12/head
Matthew 2020-05-01 01:46:13 -04:00 committed by Bsian
parent e961beb036
commit 4cd7b0f12f
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
4 changed files with 128 additions and 1 deletions

View File

@ -4,7 +4,7 @@ clean:
@-rm -rf build
build:
tsc -p ./tsconfig.json
-tsc -p ./tsconfig.json
run:
cd build && node main

View File

@ -23,6 +23,7 @@
"dependencies": {
"axios": "^0.19.2",
"eris": "bsian03/eris#bsian",
"eris-pagination": "bsian03/eris-pagination#dev",
"moment": "^2.24.0",
"mongoose": "^5.9.9",
"signale": "^1.4.0",

View File

@ -118,6 +118,16 @@ export default class Util {
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 {
const hex = int.toString(16);
return '#000000'.substring(0, 7 - hex.length) + hex;

116
src/commands/help.ts Normal file
View File

@ -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);
}
}
}