1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

Re-add module documentation

This commit is contained in:
Neel Kamath 2018-05-13 16:03:22 +05:30
parent 1bd7906402
commit 343157350f
18 changed files with 125 additions and 16 deletions

View File

@ -16,6 +16,7 @@ The commands are to be sent through a websocket to the URL wss://hack.chat/chat-
|`morestats`||Sends back the current server's stats to the calling client.|
|`move`|`channel`|This will change the current channel to `channel`.|
|`stats`||Sends back legacy server stats to the calling client. Use `morestats` when possible.|
|`help`|`category` or `command`|Gives documentation programmatically. If `category` (the permission level, such as `mod`) is sent, a list of commands available to that permission level will be sent back (as a `string` and not an `array`). This list only includes what is unique to that category and not every command a user with that permission level could perform. If `command` (e.g., `chat`) is sent, a description of the command will be sent back.|
# `mod`

View File

@ -40,4 +40,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['trip'];
exports.info = { name: 'addmod' };
exports.info = {
name: 'addmod',
usage: 'addmod {trip}',
description: 'Adds target trip to the config as a mod and upgrades the socket type'
};

View File

@ -32,4 +32,7 @@ exports.run = async (core, server, socket, data) => {
}, socket);
};
exports.info = { name: 'listusers' };
exports.info = {
name: 'listusers',
description: 'Outputs all current channels and sockets in those channels'
};

View File

@ -28,4 +28,8 @@ exports.run = async (core, server, socket, data) => {
}, { uType: 'mod' });
};
exports.info = { name: 'reload' };
exports.info = {
name: 'reload',
description: '(Re)loads any new commands into memory, outputs errors if any'
};

View File

@ -30,4 +30,7 @@ exports.run = async (core, server, socket, data) => {
}, { uType: 'mod' });
};
exports.info = { name: 'saveconfig' };
exports.info = {
name: 'saveconfig',
description: 'Saves current config'
};

View File

@ -16,4 +16,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['text'];
exports.info = { name: 'shout' };
exports.info = {
name: 'shout',
usage: 'shout {text}',
description: 'Displays passed text to every client connected'
};

View File

@ -81,4 +81,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['nick'];
exports.info = { name: 'changenick' };
exports.info = {
name: 'changenick',
usage: 'changenick {nick}',
description: 'This will change your current connections nickname'
};

View File

@ -55,4 +55,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['text'];
exports.info = { name: 'chat' };
exports.info = {
name: 'chat',
usage: 'chat {text}',
description: 'Broadcasts passed `text` field to the calling users channel'
};

View File

@ -15,4 +15,7 @@ exports.run = async (core, server, socket, data) => {
socket.terminate();
};
exports.info = { name: 'disconnect' };
exports.info = {
name: 'disconnect',
description: 'Event handler or force disconnect (if your into that kind of thing)'
};

View File

@ -0,0 +1,49 @@
/*
Description: Outputs the current command module list or command categories
*/
const stripIndents = require('common-tags').stripIndents;
exports.run = async (core, server, socket, data) => {
// verify passed arguments
let typeDt = typeof data.type;
let catDt = typeof data.category;
let cmdDt = typeof data.command;
if (typeDt !== 'undefined' && typeDt !== 'string' ) {
return;
} else if (catDt !== 'undefined' && catDt !== 'string' ) {
return;
} else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) {
return;
}
// set default reply
let reply = stripIndents`Help usage:
Show all categories -> { cmd: 'help', type: 'categories' }
Show all commands in category -> { cmd: 'help', category: '<category name>' }
Show specific command -> { cmd: 'help', command: '<command name>' }`;
if (typeDt !== 'undefined') {
let categories = core.commands.categories().sort();
reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`;
} else if (catDt !== 'undefined') {
let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name));
reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`;
} else if (cmdDt !== 'undefined') {
let command = core.commands.get(data.command);
reply = stripIndents`
Usage: ${command.info.usage || command.info.name}
Description: ${command.info.description || '¯\_(ツ)_/¯'}`;
}
server.reply({
cmd: 'info',
text: reply
}, socket);
};
exports.info = {
name: 'help',
usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
description: 'Outputs information about the servers current protocol'
};

View File

@ -58,4 +58,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['nick'];
exports.info = { name: 'invite' };
exports.info = {
name: 'invite',
usage: 'invite {nick}',
description: 'Generates a unique (more or less) room name and passes it to two clients'
};

View File

@ -128,4 +128,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['channel', 'nick'];
exports.info = { name: 'join' };
exports.info = {
name: 'join',
usage: 'join {channel} {nick}',
description: 'Place calling socket into target channel with target nick & broadcast event to channel'
};

View File

@ -47,4 +47,7 @@ exports.run = async (core, server, socket, data) => {
core.managers.stats.increment('stats-requested');
};
exports.info = { name: 'morestats' };
exports.info = {
name: 'morestats',
description: 'Sends back current server stats to the calling client'
};

View File

@ -76,4 +76,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['channel'];
exports.info = { name: 'move' };
exports.info = {
name: 'move',
usage: 'move {channel}',
description: 'This will change the current channel to the new one provided'
};

View File

@ -26,4 +26,7 @@ exports.run = async (core, server, socket, data) => {
core.managers.stats.increment('stats-requested');
};
exports.info = { name: 'stats' };
exports.info = {
name: 'stats',
description: 'Sends back legacy server stats to the calling client'
};

View File

@ -57,4 +57,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['nick'];
exports.info = { name: 'ban' };
exports.info = {
name: 'ban',
usage: 'ban {nick}',
description: 'Disconnects the target nickname in the same channel as calling socket & adds to ratelimiter'
};

View File

@ -71,4 +71,8 @@ exports.run = async (core, server, socket, data) => {
exports.requiredData = ['nick'];
exports.info = { name: 'kick' };
exports.info = {
name: 'kick',
usage: 'kick {nick}',
description: 'Silently forces target client(s) into another channel. `nick` may be string or array of strings'
};

View File

@ -48,4 +48,8 @@ exports.run = async (core, server, socket, data) => {
core.managers.stats.decrement('users-banned');
};
exports.info = { name: 'unban' };
exports.info = {
name: 'unban',
usage: 'unban {[ip || hash]}',
description: 'Removes target ip from the ratelimiter'
};