From 3fe4cb4292aa9c30db9d0d05c78fb36bf866ba51 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Mon, 15 Nov 2021 23:57:16 +0100 Subject: [PATCH] Added hints to wordmash. --- src/games/mash.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/games/mash.js b/src/games/mash.js index c681312..7b40095 100644 --- a/src/games/mash.js +++ b/src/games/mash.js @@ -129,6 +129,25 @@ function define(word, context) { context.sendMessage(`No definition available for **${word}**, @${context.user.username}`, context.room.id); } +function hint(context) { + if (!mash) { + context.sendMessage(`There is no mash going on right now, @${context.user.username}. Start one with ${config.prefix}mash {length}`, context.room.id); + return; + } + + if (mash.anagram.length <= 3) { + context.sendMessage(`The mash **${mash.anagram}** is too short for a hint, @${context.user.username}.`, context.room.id); + return; + } + + if (mash.anagram.length === 4) { + context.sendMessage(`Hints for **${mash.anagram}**, @${context.user.username}: ${mash.answers.map((answer) => `**${answer.word.slice(0, 1)} ${'_ '.repeat(answer.word.length - 1).trim()}**`).join(', ')}`, context.room.id); + return; + } + + context.sendMessage(`Hints for **${mash.anagram}**, @${context.user.username}: ${mash.answers.map((answer) => `**${answer.word.slice(0, 1)} ${'_ '.repeat(answer.word.length - 2)}${answer.word.slice(-1)}**`).join(', ')}`, context.room.id); +} + function onCommand(args, context) { const word = args[0]; const length = Number(word); @@ -143,6 +162,11 @@ function onCommand(args, context) { return; } + if (['hint'].includes(context.subcommand)) { + hint(context); + return; + } + if (!Number.isNaN(length)) { start(length, context); return;