2020-07-25 08:15:26 +00:00
|
|
|
import Command from "../core/command";
|
|
|
|
import {CommonLibrary} from "../core/lib";
|
2020-07-26 01:14:11 +00:00
|
|
|
import {loadCommands, categories} from "../core/command";
|
2020-07-25 08:15:26 +00:00
|
|
|
|
|
|
|
const types = ["user", "number", "any"];
|
|
|
|
|
|
|
|
export default new Command({
|
|
|
|
description: "Lists all commands. If a command is specified, their arguments are listed as well.",
|
|
|
|
usage: "([command, [subcommand/type], ...])",
|
|
|
|
async run($: CommonLibrary): Promise<any>
|
|
|
|
{
|
2020-07-25 23:32:49 +00:00
|
|
|
const commands = await loadCommands();
|
2020-07-26 01:14:11 +00:00
|
|
|
let output = `Legend: \`<type>\`, \`[list/of/subcommands]\`, \`(optional)\`, \`(<optional type>)\`, \`([optional/list/...])\``;
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2020-07-26 01:14:11 +00:00
|
|
|
for(const [category, headers] of categories)
|
|
|
|
{
|
|
|
|
output += `\n\n===[ ${category} ]===`;
|
|
|
|
|
|
|
|
for(const header of headers)
|
|
|
|
{
|
|
|
|
if(header !== "test")
|
|
|
|
{
|
|
|
|
const command = commands.get(header);
|
|
|
|
|
|
|
|
if(!command)
|
|
|
|
return $.warn(`Command "${header}" of category "${category}" unexpectedly doesn't exist!`);
|
|
|
|
|
|
|
|
output += `\n- \`${header}\`: ${command.description}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2020-07-26 01:14:11 +00:00
|
|
|
$.channel.send(output, {split: true});
|
2020-07-25 08:15:26 +00:00
|
|
|
},
|
|
|
|
any: new Command({
|
|
|
|
async run($: CommonLibrary): Promise<any>
|
|
|
|
{
|
2020-07-25 23:32:49 +00:00
|
|
|
const commands = await loadCommands();
|
2020-07-25 08:15:26 +00:00
|
|
|
let header = $.args.shift();
|
|
|
|
let command = commands.get(header);
|
|
|
|
|
|
|
|
if(!command || header === "test")
|
2020-07-26 02:35:53 +00:00
|
|
|
return $.channel.send(`No command found by the name \`${header}\`!`);
|
|
|
|
|
|
|
|
let usage = command.usage;
|
|
|
|
let invalid = false;
|
|
|
|
|
|
|
|
for(const param of $.args)
|
2020-07-25 08:15:26 +00:00
|
|
|
{
|
2020-07-26 02:35:53 +00:00
|
|
|
const type = command.resolve(param);
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2020-07-26 02:35:53 +00:00
|
|
|
switch(type)
|
2020-07-25 08:15:26 +00:00
|
|
|
{
|
2020-07-26 02:35:53 +00:00
|
|
|
case Command.TYPES.SUBCOMMAND: header += ` ${param}`; break;
|
|
|
|
case Command.TYPES.USER: header += " <user>" ; break;
|
|
|
|
case Command.TYPES.NUMBER: header += " <number>" ; break;
|
|
|
|
case Command.TYPES.ANY: header += " <any>" ; break;
|
|
|
|
default: header += ` ${param}`; break;
|
2020-07-25 08:15:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 02:35:53 +00:00
|
|
|
if(type === Command.TYPES.NONE)
|
|
|
|
{
|
|
|
|
invalid = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2020-07-26 02:35:53 +00:00
|
|
|
command = command.get(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(invalid)
|
|
|
|
return $.channel.send(`No command found by the name \`${header}\`!`);
|
|
|
|
|
|
|
|
let append = "";
|
|
|
|
|
|
|
|
if(usage === "")
|
|
|
|
{
|
|
|
|
const list: string[] = [];
|
2020-07-25 08:15:26 +00:00
|
|
|
|
2020-07-26 02:35:53 +00:00
|
|
|
for(const subtag in command.subcommands)
|
2020-07-25 08:15:26 +00:00
|
|
|
{
|
2020-07-26 02:35:53 +00:00
|
|
|
const subcmd = command.subcommands[subtag];
|
|
|
|
const customUsage = subcmd.usage ? ` ${subcmd.usage}` : "";
|
|
|
|
list.push(`- \`${header} ${subtag}${customUsage}\` - ${subcmd.description}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(const type of types)
|
|
|
|
{
|
|
|
|
if(command[type])
|
2020-07-25 08:15:26 +00:00
|
|
|
{
|
2020-07-26 02:35:53 +00:00
|
|
|
const cmd = command[type];
|
|
|
|
const customUsage = cmd.usage ? ` ${cmd.usage}` : "";
|
|
|
|
list.push(`- \`${header} <${type}>${customUsage}\` - ${cmd.description}`);
|
2020-07-25 08:15:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 02:35:53 +00:00
|
|
|
append = "Usages:" + (list.length > 0 ? `\n${list.join('\n')}` : " None.");
|
2020-07-25 08:15:26 +00:00
|
|
|
}
|
2020-07-26 02:35:53 +00:00
|
|
|
else
|
|
|
|
append = `Usage: \`${header} ${usage}\``;
|
|
|
|
|
|
|
|
$.channel.send(`Command: \`${header}\`\nDescription: ${command.description}\n${append}`, {split: true});
|
2020-07-25 08:15:26 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|