diff --git a/src/events/eventLoader.ts b/src/events/eventLoader.ts index 5219423..97f3edd 100644 --- a/src/events/eventLoader.ts +++ b/src/events/eventLoader.ts @@ -1,11 +1,11 @@ -import { Client } from 'discord.js'; import { readdir } from 'fs'; import { promisify } from 'util'; import { Event } from './Event'; +import { PluginClient } from '../PluginClient'; const readDir = promisify(readdir); -export async function EventLoader(lifeguard: Client) { +export async function EventLoader(lifeguard: PluginClient) { const eventFiles = await readDir('./build/src/events'); for await (const file of eventFiles) { diff --git a/src/plugins/info/help.ts b/src/plugins/info/help.ts index d1cc34c..39317c9 100644 --- a/src/plugins/info/help.ts +++ b/src/plugins/info/help.ts @@ -1,14 +1,65 @@ import { Command } from '../Command'; +import { MessageEmbed, Collection } from 'discord.js'; +import { Plugin } from '../Plugin'; + +function convertPlugins(plugins: Collection) { + return plugins + .map((plugin, key) => ({ + name: key, + cmds: [...plugin.values()] + .filter(cmd => !cmd.options.hidden) + .map(cmd => cmd.name) + .sort((a, b) => a.localeCompare(b)), + })) + .sort((a, b) => a.name.localeCompare(b.name)); +} export const command = new Command( 'help', (lifeguard, msg, args) => { - const cmds = Array.from(lifeguard.plugins.values()) - .map(plugin => Array.from(plugin.values())) - .reduce((acc, val) => acc.concat(val), []) - .filter(cmd => !cmd.options.hidden) - .sort((a, b) => a.name.localeCompare(b.name)); - msg.channel.send(cmds.map(c => c.name).join('\n')); + if (!args.length) { + const plugins = convertPlugins(lifeguard.plugins); + + const embed = new MessageEmbed() + .setTitle('Lifeguard Help') + .setColor(0x7289da) + .setFooter( + `Executed By ${msg.author.tag}`, + msg.author.avatarURL() ?? msg.author.defaultAvatarURL + ) + .setTimestamp(); + + for (const plugin of plugins) { + embed.addField(plugin.name, plugin.cmds.join('\n')); + } + + msg.channel.send(embed); + } else { + const plugin = lifeguard.plugins.find(plugin => plugin.has(args[0])); + const cmd = plugin?.get(args[0]); + + if (cmd) { + const embed = new MessageEmbed() + .setTitle(cmd.name) + .setColor(0x7289da) + .setFooter( + `Executed By ${msg.author.tag}`, + msg.author.avatarURL() ?? msg.author.defaultAvatarURL + ) + .setTimestamp(); + + const options = Object.entries(cmd.options); + options.map(([key, val]) => { + if (key === 'usage') { + embed.addField(key, val.join('\n')); + return; + } + embed.addField(key, `${val}`); + }); + + msg.channel.send(embed); + } + } }, { level: 0,