Compare commits

...

2 Commits

Author SHA1 Message Date
Niels Simenon 48003e4d34 1.19.8 2022-11-02 01:20:21 +01:00
Niels Simenon 09d069dec1 Help module can give game-specific help. 2022-11-02 01:20:19 +01:00
3 changed files with 32 additions and 4 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.19.7", "version": "1.19.8",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.19.7", "version": "1.19.8",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"bhttp": "^1.2.8", "bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.19.7", "version": "1.19.8",
"description": "Game host for SChat 2-powered chat sites", "description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js", "main": "src/app.js",
"scripts": { "scripts": {

View File

@ -3,13 +3,41 @@
const config = require('config'); const config = require('config');
const { version } = require('../../package.json'); const { version } = require('../../package.json');
const style = require('../utils/style');
function capitalize(string) {
if (typeof string !== 'string') {
return string;
}
return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
}
function onCommand(args, context) { function onCommand(args, context) {
if (context.subcommand) {
const game = context.games[context.subcommand];
if (game?.help) {
context.sendMessage(`${style.bold(`${capitalize(game.name || game.key)}:`)} ${game.help}`, context.room.id, { styleCommands: true });
return;
}
if (game) {
context.sendMessage(`No help available for '${capitalize(game.name || game.key)}'.`, context.room.id, { styleCommands: true });
return;
}
context.sendMessage(`No game '${capitalize(context.subcommand)}' known.`, context.room.id, { styleCommands: true });
return;
}
const commandsByGame = Object.entries(context.games) const commandsByGame = Object.entries(context.games)
.filter(([command, game]) => !command.includes('-') && !game.restricted) .filter(([command, game]) => !command.includes('-') && !game.restricted)
.reduce((acc, [command, game]) => ({ ...acc, [game.name]: [...(acc[game.name] || []), command] }), {}); .reduce((acc, [command, game]) => ({ ...acc, [game.name]: [...(acc[game.name] || []), command] }), {});
const commands = Object.entries(commandsByGame) const commands = Object.entries(commandsByGame)
.map(([gameName, gameCommands]) => `${gameName.slice(0, 1).toUpperCase()}${gameName.slice(1)}: ${gameCommands.map((command) => `${config.prefix}${command}`).join(', ')}`) .map(([gameName, gameCommands]) => `${capitalize(gameName)}: ${gameCommands.map((command) => `${config.prefix}${command}`).join(', ')}`)
.join(' | '); .join(' | ');
context.sendMessage(`${commands}`, context.room.id, { styleCommands: true }); context.sendMessage(`${commands}`, context.room.id, { styleCommands: true });