Added larger mash dictionary with definitions.
This commit is contained in:
parent
2f2050f595
commit
583c8cde67
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs').promises;
|
||||
|
||||
const dictionary = require('./dictionary.json');
|
||||
|
||||
async function init() {
|
||||
const validWords = Object.entries(dictionary).filter(([word]) => /^[a-zA-Z]+$/.test(word));
|
||||
|
||||
const sortedWords = validWords.reduce((acc, [rawWord, fullDefinition]) => {
|
||||
const word = rawWord.toLowerCase();
|
||||
const anagram = word.split('').sort().join('');
|
||||
const definitions = fullDefinition.split(/\d+\.\s+/).filter(Boolean).map((definition) => definition.split('.')[0].toLowerCase());
|
||||
|
||||
if (!acc[anagram.length]) {
|
||||
acc[anagram.length] = {};
|
||||
}
|
||||
|
||||
if (!acc[anagram.length][anagram]) {
|
||||
acc[anagram.length][anagram] = [];
|
||||
}
|
||||
|
||||
acc[anagram.length][anagram].push({ word, definitions });
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await fs.writeFile('./mash-words.json', JSON.stringify(sortedWords, null, 4));
|
||||
|
||||
console.log(sortedWords);
|
||||
}
|
||||
|
||||
init();
|
File diff suppressed because one or more lines are too long
809688
assets/mash-words.json
809688
assets/mash-words.json
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
username: 'Clive',
|
||||
// optional
|
||||
gender: 'male',
|
||||
countryCode: 'GB',
|
||||
birthdate: new Date(1952, 11, 10),
|
||||
avatar: 'https://i.imgur.com/IZwrjjG.png',
|
||||
},
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const packs = require('../../assets/cah-cards-full.json');
|
||||
|
||||
function start() {
|
||||
const blackCards = packs.map((pack) => pack.black).flat();
|
||||
const whiteCards = packs.map((pack) => pack.white).flat();
|
||||
|
||||
console.log(blackCards, whiteCards);
|
||||
}
|
||||
|
||||
function onCommand() {
|
||||
start();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'Cursed Cards',
|
||||
onCommand,
|
||||
};
|
|
@ -16,7 +16,7 @@ function start(length, context, attempt = 0) {
|
|||
}
|
||||
|
||||
if (mash) {
|
||||
context.sendMessage(`The mash **${mash.anagram}** was not guessed, possible answers: ${mash.answers.map((answer) => `**${answer}**`).join(', ')}`, context.room.id);
|
||||
context.sendMessage(`The mash **${mash.anagram}** was not guessed, possible answers: ${mash.answers.map((answer) => `**${answer.word}**`).join(', ')}`, context.room.id);
|
||||
context.logger.info(`Mash '${mash.anagram}' discarded`);
|
||||
|
||||
mash = null;
|
||||
|
@ -27,7 +27,7 @@ function start(length, context, attempt = 0) {
|
|||
|
||||
const anagram = key.split('').sort(() => (Math.random() > 0.5 ? 1 : -1)).join('');
|
||||
|
||||
if (answers.includes(anagram)) {
|
||||
if (answers.some((answer) => answer.word === anagram)) {
|
||||
if (attempt >= 10) {
|
||||
context.sendMessage(`Sorry, I did not find a mashable ${length}-letter word`);
|
||||
return;
|
||||
|
@ -41,7 +41,7 @@ function start(length, context, attempt = 0) {
|
|||
mash = { key, anagram, answers };
|
||||
|
||||
context.sendMessage(`Stomp stomp, here's your mash: **${mash.anagram}**`, context.room.id);
|
||||
context.logger.info(`Mash started, '${anagram}' with answers ${answers.map((answer) => `'${answer}'`).join(', ')}`);
|
||||
context.logger.info(`Mash started, '${anagram}' with answers ${answers.map((answer) => `'${answer.word}'`).join(', ')}`);
|
||||
}
|
||||
|
||||
function play(word, context) {
|
||||
|
@ -62,10 +62,12 @@ function play(word, context) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (mash.answers.includes(word)) {
|
||||
if (mash.answers.some((answer) => answer.word === word)) {
|
||||
const definition = mash.answers[0].definitions[0] ? `: *${mash.answers[0].definitions[0].slice(0, 100)}${mash.answers[0].definitions[0].length > 100 ? '...*' : '*'}` : '';
|
||||
|
||||
context.sendMessage(mash.answers.length === 1
|
||||
? `**${word}** is the right answer, @${context.user.username} now has **${context.user.points + 1} ${context.user.points === 0 ? 'point' : 'points'}**! There were no other options for **${mash.anagram}**.`
|
||||
: `**${word}** is the right answer, @${context.user.username} now has **${context.user.points + 1} ${context.user.points === 0 ? 'point' : 'points'}**! Other options for **${mash.anagram}**: ${mash.answers.filter((answer) => answer !== word).map((answer) => `**${answer}**`).join(', ')}`, context.room.id);
|
||||
? `**${word}** is the right answer${definition}, @${context.user.username} now has **${context.user.points + 1} ${context.user.points === 0 ? 'point' : 'points'}**! There were no other options for **${mash.anagram}**.`
|
||||
: `**${word}** is the right answer${definition}, @${context.user.username} now has **${context.user.points + 1} ${context.user.points === 0 ? 'point' : 'points'}**! Other options for **${mash.anagram}**: ${mash.answers.filter((answer) => answer.word !== word).map((answer) => `*${answer.word}*`).join(', ')}`, context.room.id);
|
||||
|
||||
context.logger.info(`Mash '${mash.anagram}' guessed by '${context.user.username}' with '${word}'`);
|
||||
context.setPoints(context.user, 1);
|
||||
|
|
Loading…
Reference in New Issue