Added mash dictionary and resolve as direct commands, preventing using resolve on current mash.

This commit is contained in:
ThePendulum 2022-10-20 02:16:03 +02:00
parent dc8830feea
commit 6831330e35
1 changed files with 15 additions and 5 deletions

View File

@ -7,6 +7,9 @@ const words = require('../../assets/mash-words.json');
const mashes = new Map();
const defineCommands = ['define', 'dict', 'dictionary'];
const resolveCommands = ['solve', 'resolve', 'lookup'];
function getWordKey(word) {
return word.split('').sort().join('');
}
@ -97,8 +100,14 @@ function resolve(word, context) {
return;
}
const anagram = getWordKey(word);
const answers = words[word.length]?.[anagram];
const anagramKey = getWordKey(word);
const answers = words[word.length]?.[anagramKey];
if (mashes.get(context.room.id)?.key === anagramKey) {
context.sendMessage(`Nice try, ${config.usernamePrefix}${context.user.username}. Starting a new mash will cancel the current one, and reveal the answer.`, context.room.id);
return;
}
if (answers?.length > 1 && answers.some((answer) => answer.word === word)) {
context.sendMessage(`${style.bold(word)} is a valid word in itself, and has the following anagrams, ${config.usernamePrefix}${context.user.username}: ${answers.filter((answer) => answer.word !== word).map((answer) => style.italic(answer.word)).join(', ')}`, context.room.id);
@ -129,7 +138,7 @@ function define(word, context) {
const answer = answers?.find((answerX) => answerX.word === word);
if (answer && answer.definitions?.length > 0) {
context.sendMessage(`${word} can be defined as follows, ${config.usernamePrefix}${context.user.username}: ${style.italic(answer.definitions[0])}`, context.room.id);
context.sendMessage(`${style.bold(word)} can be defined as follows, ${config.usernamePrefix}${context.user.username}: ${style.italic(answer.definitions[0])}`, context.room.id);
return;
}
@ -162,12 +171,12 @@ function onCommand(args, context) {
const word = args[0];
const length = Number(word);
if (['solve', 'resolve', 'lookup'].includes(context.subcommand)) {
if (resolveCommands.includes(context.command) || resolveCommands.includes(context.subcommand)) {
resolve(word, context);
return;
}
if (['define', 'dict', 'dictionary'].includes(context.subcommand)) {
if (defineCommands.includes(context.command) || defineCommands.includes(context.subcommand)) {
define(word, context);
return;
}
@ -205,6 +214,7 @@ function onMessage(message, context) {
module.exports = {
name: 'Mash',
commands: ['mash', ...defineCommands, ...resolveCommands],
onCommand,
onMessage,
};