aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/help.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core/help.js')
-rw-r--r--server/src/commands/core/help.js47
1 files changed, 24 insertions, 23 deletions
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
index 8eccdb6..25f8844 100644
--- a/server/src/commands/core/help.js
+++ b/server/src/commands/core/help.js
@@ -3,21 +3,21 @@
*/
// module support functions
-const stripIndents = require('common-tags').stripIndents;
+const { stripIndents } = require('common-tags');
// module main
-exports.run = async (core, server, socket, payload) => {
+export async function run(core, server, socket, payload) {
// check for spam
- if (server.police.frisk(socket.remoteAddress, 2)) {
+ if (server.police.frisk(socket.address, 2)) {
return server.reply({
cmd: 'warn',
- text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.'
+ text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}
// verify user input
if (typeof payload.command !== 'undefined' && typeof payload.command !== 'string') {
- return;
+ return true;
}
let reply = '';
@@ -27,21 +27,21 @@ exports.run = async (core, server, socket, payload) => {
API: {cmd: 'help', command: '<command name>'}`;
reply += '\n\n-------------------------------------\n\n';
- let categories = core.commands.categoriesList.sort();
- for (let i = 0, j = categories.length; i < j; i++) {
- reply += `${categories[i].replace('../src/commands/', '').replace(/^\w/, c => c.toUpperCase())} Commands:\n`;
- let 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`;
+ 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`;
}
} else {
- let command = core.commands.get(payload.command);
+ const command = core.commands.get(payload.command);
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'}
- Category: ${command.info.category.replace('../src/commands/', '').replace(/^\w/, c => c.toUpperCase())}
+ Category: ${command.info.category.replace('../src/commands/', '').replace(/^\w/, (c) => c.toUpperCase())}
Required Parameters: ${command.requiredData || 'None'}\n
Description: ${command.info.description || '¯\_(ツ)_/¯'}\n
Usage: ${command.info.usage || command.info.name}`;
@@ -51,40 +51,41 @@ exports.run = async (core, server, socket, payload) => {
// output reply
server.reply({
cmd: 'info',
- text: reply
+ text: reply,
}, socket);
-};
+
+ return true;
+}
// module hook functions
-exports.initHooks = (server) => {
+export function initHooks(server) {
server.registerHook('in', 'chat', this.helpCheck, 28);
-};
+}
// hooks chat commands checking for /whisper
-exports.helpCheck = (core, server, socket, payload) => {
+export function helpCheck(core, server, socket, payload) {
if (typeof payload.text !== 'string') {
return false;
}
if (payload.text.startsWith('/help')) {
- let input = payload.text.substr(1).split(' ', 2);
+ const input = payload.text.substr(1).split(' ', 2);
this.run(core, server, socket, {
cmd: input[0],
- command: input[1]
+ command: input[1],
});
return false;
}
return payload;
-};
+}
-// module meta
-exports.info = {
+export const info = {
name: 'help',
description: 'Outputs information about the servers current protocol',
usage: `
API: { cmd: 'help', command: '<optional command name>' }
- Text: /help <optional command name>`
+ Text: /help <optional command name>`,
};