Re-implement help message
This commit is contained in:
parent
8f9acdb455
commit
ec8b165c96
|
@ -1,6 +1,7 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
const Discord = require("discord.js");
|
||||||
const ParentPackageJSON = require("../package.json");
|
const ParentPackageJSON = require("../package.json");
|
||||||
const CoreUtil = require("./Util.js");
|
const InternalConfig = require("./internal-config.json");
|
||||||
|
|
||||||
/**@param param*/
|
/**@param param*/
|
||||||
function handleMessage(client, message, commands, guildData) {
|
function handleMessage(client, message, commands, guildData) {
|
||||||
|
@ -14,7 +15,7 @@ function handleMessage(client, message, commands, guildData) {
|
||||||
command = commands[Object.keys(commands).find(x => commands[x].name.toLowerCase() === (split[1] || "").toLowerCase())];
|
command = commands[Object.keys(commands).find(x => commands[x].name.toLowerCase() === (split[1] || "").toLowerCase())];
|
||||||
|
|
||||||
if (!command)
|
if (!command)
|
||||||
handleInternalCommand(message, split);
|
handleInternalCommand(message, split, commands, isMemberAdmin);
|
||||||
else if (params.length < command.expectedParamCount)
|
else if (params.length < command.expectedParamCount)
|
||||||
message.reply(`Incorrect syntax!\n**Expected:** *${botName} ${command.syntax}*\n**Need help?** *${botName} help*`);
|
message.reply(`Incorrect syntax!\n**Expected:** *${botName} ${command.syntax}*\n**Need help?** *${botName} help*`);
|
||||||
else if (isMemberAdmin || !command.admin)
|
else if (isMemberAdmin || !command.admin)
|
||||||
|
@ -31,15 +32,44 @@ function handleMessage(client, message, commands, guildData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**@param param*/
|
/**@param param*/
|
||||||
function handleInternalCommand(message, split) {
|
function handleInternalCommand(message, split, commands, isMemberAdmin) {
|
||||||
if (split[1].toLowerCase() === "version")
|
if (split[1].toLowerCase() === "version")
|
||||||
message.reply(`${ParentPackageJSON.name} v${ParentPackageJSON.version}`);
|
message.reply(`${ParentPackageJSON.name} v${ParentPackageJSON.version}`);
|
||||||
else if (split[1].toLowerCase() === "help")
|
else if (split[1].toLowerCase() === "help") {
|
||||||
message.reply(createHelpEmbed());
|
const helpCommands = [...Object.keys(commands).map(x => commands[x])];
|
||||||
|
helpCommands.push({
|
||||||
|
name: "version",
|
||||||
|
description: "Return version number",
|
||||||
|
syntax: "version"
|
||||||
|
});
|
||||||
|
helpCommands.push({
|
||||||
|
name: "help",
|
||||||
|
description: "View help",
|
||||||
|
syntax: "help"
|
||||||
|
});
|
||||||
|
message.reply(createHelpEmbed(ParentPackageJSON.name, helpCommands, isMemberAdmin));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createHelpEmbed() {
|
/**
|
||||||
return "not yet implemented";
|
* Create a help embed for available commands
|
||||||
|
* @param {string} name name of the bot
|
||||||
|
* @param {*[]} commands commands array
|
||||||
|
* @param {boolean} userIsAdmin whether the user is admin
|
||||||
|
*/
|
||||||
|
function createHelpEmbed(name, commands, userIsAdmin) {
|
||||||
|
const commandsArr = Object.keys(commands).map(x => commands[x]).filter(x => userIsAdmin || !x.admin);
|
||||||
|
|
||||||
|
const embed = new Discord.RichEmbed().setTitle(`__Help__ for ${(ParentPackageJSON.name + "").replace("discord-bot-", "")}`);
|
||||||
|
|
||||||
|
commandsArr.forEach(command => {
|
||||||
|
embed.addField(command.name, `${command.description}\n**Usage:** *${name} ${command.syntax}*${userIsAdmin && command.admin ? "\n***Admin only***" : ""}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
embed.addField("__Need more help?__", `[Visit my website](${InternalConfig.website}) or [Join my Discord](${InternalConfig.discordInvite})`, true);
|
||||||
|
|
||||||
|
return { embed };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = handleMessage;
|
module.exports = handleMessage;
|
Loading…
Reference in a new issue