2018-05-13 18:33:22 +08:00
|
|
|
/*
|
|
|
|
Description: Outputs the current command module list or command categories
|
|
|
|
*/
|
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module support functions
|
2019-11-07 15:35:23 +08:00
|
|
|
const { stripIndents } = require('common-tags');
|
2018-05-13 18:33:22 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module main
|
2019-11-07 15:35:23 +08:00
|
|
|
export async function run(core, server, socket, payload) {
|
2018-09-30 14:44:36 +08:00
|
|
|
// check for spam
|
2019-11-07 15:35:23 +08:00
|
|
|
if (server.police.frisk(socket.address, 2)) {
|
2018-09-30 14:44:36 +08:00
|
|
|
return server.reply({
|
|
|
|
cmd: 'warn',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
|
2018-09-30 14:44:36 +08:00
|
|
|
}, socket);
|
|
|
|
}
|
2018-06-04 15:07:24 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// verify user input
|
|
|
|
if (typeof payload.command !== 'undefined' && typeof payload.command !== 'string') {
|
2019-11-07 15:35:23 +08:00
|
|
|
return true;
|
2018-05-13 18:33:22 +08:00
|
|
|
}
|
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
let reply = '';
|
|
|
|
if (typeof payload.command === 'undefined') {
|
|
|
|
reply = stripIndents`Listing all current commands. For specific help on certain commands, use either:
|
|
|
|
Text: /help <command name>
|
|
|
|
API: {cmd: 'help', command: '<command name>'}`;
|
|
|
|
reply += '\n\n-------------------------------------\n\n';
|
2018-05-13 18:33:22 +08:00
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
const categories = core.commands.categoriesList.sort();
|
|
|
|
for (let i = 0, j = categories.length; i < j; i += 1) {
|
|
|
|
reply += `${categories[i].replace('../src/commands/', '').replace(/^\w/, (c) => c.toUpperCase())} Commands:\n`;
|
|
|
|
const catCommands = core.commands.all(categories[i]).sort((a, b) => a.info.name.localeCompare(b.info.name));
|
|
|
|
reply += ` ${catCommands.map((c) => `${c.info.name}`).join(', ')}\n\n`;
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-07 15:35:23 +08:00
|
|
|
const command = core.commands.get(payload.command);
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
if (typeof command === 'undefined') {
|
|
|
|
reply = 'Unknown command';
|
|
|
|
} else {
|
|
|
|
reply = stripIndents`Name: ${command.info.name}
|
|
|
|
Aliases: ${typeof command.info.aliases !== 'undefined' ? command.info.aliases.join(', ') : 'None'}
|
2019-11-07 15:35:23 +08:00
|
|
|
Category: ${command.info.category.replace('../src/commands/', '').replace(/^\w/, (c) => c.toUpperCase())}
|
2018-09-30 14:44:36 +08:00
|
|
|
Required Parameters: ${command.requiredData || 'None'}\n
|
|
|
|
Description: ${command.info.description || '¯\_(ツ)_/¯'}\n
|
|
|
|
Usage: ${command.info.usage || command.info.name}`;
|
|
|
|
}
|
2018-05-13 18:33:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// output reply
|
2018-05-13 18:33:22 +08:00
|
|
|
server.reply({
|
|
|
|
cmd: 'info',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: reply,
|
2018-05-13 18:33:22 +08:00
|
|
|
}, socket);
|
2019-11-07 15:35:23 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-13 18:33:22 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module hook functions
|
2019-11-07 15:35:23 +08:00
|
|
|
export function initHooks(server) {
|
2019-02-21 16:43:25 +08:00
|
|
|
server.registerHook('in', 'chat', this.helpCheck, 28);
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// hooks chat commands checking for /whisper
|
2019-11-07 15:35:23 +08:00
|
|
|
export function helpCheck(core, server, socket, payload) {
|
2018-09-30 14:44:36 +08:00
|
|
|
if (typeof payload.text !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (payload.text.startsWith('/help')) {
|
2019-11-07 15:35:23 +08:00
|
|
|
const input = payload.text.substr(1).split(' ', 2);
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
this.run(core, server, socket, {
|
|
|
|
cmd: input[0],
|
2019-11-07 15:35:23 +08:00
|
|
|
command: input[1],
|
2018-09-30 14:44:36 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
export const info = {
|
2018-05-13 18:33:22 +08:00
|
|
|
name: 'help',
|
2018-09-30 14:44:36 +08:00
|
|
|
description: 'Outputs information about the servers current protocol',
|
|
|
|
usage: `
|
|
|
|
API: { cmd: 'help', command: '<optional command name>' }
|
2019-11-07 15:35:23 +08:00
|
|
|
Text: /help <optional command name>`,
|
2018-06-04 15:07:24 +08:00
|
|
|
};
|