2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* @author Marzavec ( https://github.com/marzavec )
|
|
|
|
* @summary Get help
|
|
|
|
* @version 1.0.0
|
|
|
|
* @description Outputs information about the servers current protocol
|
|
|
|
* @module help
|
|
|
|
*/
|
2018-05-13 18:33:22 +08:00
|
|
|
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
import {
|
|
|
|
CodebaseVersion,
|
|
|
|
} from '../utility/_Constants.js';
|
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* Executes when invoked by a remote client
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
* @param {Object} env - Environment object with references to core, server, socket & payload
|
2022-06-23 00:32:51 +08:00
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2020-09-17 13:44:32 +08:00
|
|
|
export async function run({
|
|
|
|
core, server, socket, payload,
|
|
|
|
}) {
|
2018-09-30 14:44:36 +08:00
|
|
|
// check for spam
|
2023-12-27 16:26:49 +08:00
|
|
|
if (server.police.frisk(socket, 2)) {
|
2018-09-30 14:44:36 +08:00
|
|
|
return server.reply({
|
2020-09-22 13:34:30 +08:00
|
|
|
cmd: 'warn', // @todo Add numeric error code as `id`
|
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.',
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
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') {
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += '# All commands:\n|Category:|Name:|\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) {
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += `|${categories[i].replace('../src/commands/', '').replace(/^\w/, (c) => c.toUpperCase())}:|`;
|
2020-09-17 13:44:32 +08:00
|
|
|
const catCommands = core.commands.all(categories[i]).sort(
|
|
|
|
(a, b) => a.info.name.localeCompare(b.info.name),
|
|
|
|
);
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += `${catCommands.map((c) => `${c.info.name}`).join(', ')}|\n`;
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
2019-11-08 06:34:38 +08:00
|
|
|
|
|
|
|
reply += '---\nFor specific help on certain commands, use either:\nText: `/help <command name>`\nAPI: `{cmd: \'help\', command: \'<command name>\'}`';
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
reply += `\n\nHackChat ${CodebaseVersion}`;
|
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') {
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += 'Unknown command';
|
2018-09-30 14:44:36 +08:00
|
|
|
} else {
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += `# ${command.info.name} command:\n| | |\n|---:|---|\n`;
|
|
|
|
reply += `|**Name:**|${command.info.name}|\n`;
|
2023-12-29 15:17:33 +08:00
|
|
|
reply += `|**Hash:**|${command.info.srcHash}|\n`;
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += `|**Aliases:**|${typeof command.info.aliases !== 'undefined' ? command.info.aliases.join(', ') : 'None'}|\n`;
|
|
|
|
reply += `|**Category:**|${command.info.category.replace('../src/commands/', '').replace(/^\w/, (c) => c.toUpperCase())}|\n`;
|
|
|
|
reply += `|**Required Parameters:**|${command.requiredData || 'None'}|\n`;
|
2020-09-17 13:44:32 +08:00
|
|
|
// eslint-disable-next-line no-useless-escape
|
2019-11-08 06:34:38 +08:00
|
|
|
reply += `|**Description:**|${command.info.description || '¯\_(ツ)_/¯'}|\n\n`;
|
|
|
|
reply += `**Usage:** ${command.info.usage || command.info.name}`;
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
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,
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
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
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* Automatically executes once after server is ready to register this modules hooks
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
* @param {Object} server - Reference to server environment object
|
2022-06-23 00:32:51 +08:00
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2019-11-07 15:35:23 +08:00
|
|
|
export function initHooks(server) {
|
2019-11-08 01:46:55 +08:00
|
|
|
server.registerHook('in', 'chat', this.helpCheck.bind(this), 28);
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* Executes every time an incoming chat command is invoked;
|
|
|
|
* hooks chat commands checking for /help
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
* @param {Object} env - Environment object with references to core, server, socket & payload
|
2022-06-23 00:32:51 +08:00
|
|
|
* @public
|
2023-12-30 15:24:12 +08:00
|
|
|
* @return {(Object|boolean|string)} Object = same/altered payload,
|
2022-06-23 00:32:51 +08:00
|
|
|
* false = suppress action,
|
|
|
|
* string = error
|
|
|
|
*/
|
2020-09-17 13:44:32 +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
|
|
|
|
2020-09-17 13:44:32 +08:00
|
|
|
this.run({
|
|
|
|
core,
|
|
|
|
server,
|
|
|
|
socket,
|
|
|
|
payload: {
|
|
|
|
cmd: input[0],
|
|
|
|
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
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* Module meta information
|
|
|
|
* @public
|
|
|
|
* @typedef {Object} help/info
|
|
|
|
* @property {string} name - Module command name
|
|
|
|
* @property {string} category - Module category name
|
|
|
|
* @property {string} description - Information about module
|
|
|
|
* @property {string} usage - Information about module usage
|
|
|
|
*/
|
2019-11-07 15:35:23 +08:00
|
|
|
export const info = {
|
2018-05-13 18:33:22 +08:00
|
|
|
name: 'help',
|
2022-06-23 00:32:51 +08:00
|
|
|
category: 'core',
|
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
|
|
|
};
|