2020-01-13 22:38:12 +00:00
|
|
|
import { Command } from '../Command';
|
2020-01-25 17:02:34 +00:00
|
|
|
import { MessageEmbed, Collection, GuildMember, Guild } from 'discord.js';
|
2020-01-14 04:42:02 +00:00
|
|
|
import { Plugin } from '../Plugin';
|
2020-01-25 17:02:34 +00:00
|
|
|
import { calcUserLevel } from '../../assertions/userLevel';
|
|
|
|
import { defaultEmbed } from '../../util/DefaultEmbed';
|
2020-01-14 04:42:02 +00:00
|
|
|
|
2020-01-25 17:02:34 +00:00
|
|
|
function convertPlugins(
|
|
|
|
plugins: Collection<string, Plugin>,
|
|
|
|
member: GuildMember,
|
|
|
|
guild: Guild
|
|
|
|
) {
|
2020-01-14 04:42:02 +00:00
|
|
|
return plugins
|
|
|
|
.map((plugin, key) => ({
|
|
|
|
name: key,
|
|
|
|
cmds: [...plugin.values()]
|
|
|
|
.filter(cmd => !cmd.options.hidden)
|
2020-01-25 17:02:34 +00:00
|
|
|
.filter(cmd => calcUserLevel(member, guild) >= cmd.options.level)
|
2020-01-14 04:42:02 +00:00
|
|
|
.map(cmd => cmd.name)
|
|
|
|
.sort((a, b) => a.localeCompare(b)),
|
|
|
|
}))
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
}
|
2020-01-13 22:38:12 +00:00
|
|
|
|
|
|
|
export const command = new Command(
|
|
|
|
'help',
|
|
|
|
(lifeguard, msg, args) => {
|
2020-01-14 04:42:02 +00:00
|
|
|
if (!args.length) {
|
2020-01-25 17:02:34 +00:00
|
|
|
const plugins = convertPlugins(
|
|
|
|
lifeguard.plugins,
|
|
|
|
msg.member as GuildMember,
|
|
|
|
msg.guild as Guild
|
|
|
|
);
|
2020-01-14 04:42:02 +00:00
|
|
|
|
2020-01-25 17:02:34 +00:00
|
|
|
const embed = defaultEmbed()
|
2020-01-14 04:42:02 +00:00
|
|
|
.setTitle('Lifeguard Help')
|
|
|
|
.setFooter(
|
|
|
|
`Executed By ${msg.author.tag}`,
|
|
|
|
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
2020-01-25 17:02:34 +00:00
|
|
|
);
|
2020-01-14 04:42:02 +00:00
|
|
|
|
|
|
|
for (const plugin of plugins) {
|
2020-01-25 17:02:34 +00:00
|
|
|
// console.log(plugin)
|
|
|
|
// embed.addField(plugin.name, plugin.cmds.join('\n'));
|
|
|
|
if (plugin.cmds.length > 0) {
|
|
|
|
embed.addField(plugin.name, plugin.cmds.join('\n'));
|
|
|
|
}
|
2020-01-14 04:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg.channel.send(embed);
|
|
|
|
} else {
|
|
|
|
const plugin = lifeguard.plugins.find(plugin => plugin.has(args[0]));
|
|
|
|
const cmd = plugin?.get(args[0]);
|
|
|
|
|
|
|
|
if (cmd) {
|
2020-01-25 17:02:34 +00:00
|
|
|
const embed = defaultEmbed()
|
2020-01-14 04:42:02 +00:00
|
|
|
.setTitle(cmd.name)
|
|
|
|
.setFooter(
|
|
|
|
`Executed By ${msg.author.tag}`,
|
|
|
|
msg.author.avatarURL() ?? msg.author.defaultAvatarURL
|
2020-01-25 17:02:34 +00:00
|
|
|
);
|
2020-01-14 04:42:02 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 22:38:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
level: 0,
|
|
|
|
usage: ['help', 'help [name]'],
|
|
|
|
}
|
|
|
|
);
|