Added definitions to wordmash hints, listening broadly for wordmash answers.
This commit is contained in:
parent
a0c35bd613
commit
d98c4c12fa
|
@ -48,32 +48,34 @@ function start(length, context, attempt = 0) {
|
||||||
context.logger.info(`Mash started, '${anagram}' with answers ${answers.map((answer) => `'${answer.word}'`).join(', ')}`);
|
context.logger.info(`Mash started, '${anagram}' with answers ${answers.map((answer) => `'${answer.word}'`).join(', ')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function play(rawWord, context) {
|
function play(rawWord, context, shouted) {
|
||||||
const word = rawWord.toLowerCase();
|
const word = rawWord.toLowerCase();
|
||||||
|
|
||||||
if (word.length !== mash.key.length) {
|
|
||||||
context.sendMessage(`Your answer needs to be ${mash.key.length} letters, @${context.user.username}`, context.room.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = getWordKey(word);
|
const key = getWordKey(word);
|
||||||
|
const answer = mash.answers.find((answerX) => answerX.word === word);
|
||||||
|
|
||||||
if (key !== mash.key) {
|
if (!shouted) {
|
||||||
context.sendMessage(`You are not using the letters in **${mash.anagram}**, @${context.user.username}`, context.room.id);
|
if (word.length !== mash.key.length) {
|
||||||
return;
|
context.sendMessage(`Your answer needs to be ${mash.key.length} letters, @${context.user.username}`, context.room.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key !== mash.key) {
|
||||||
|
context.sendMessage(`You are not using the letters in **${mash.anagram}**, @${context.user.username}`, context.room.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (word === mash.anagram) {
|
||||||
|
context.sendMessage(`@${context.user.username}... :expressionless:`, context.room.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (word === mash.anagram) {
|
if (answer) {
|
||||||
context.sendMessage(`@${context.user.username}... :expressionless:`, context.room.id);
|
const definition = answer.definitions[0] ? `: *${answer.definitions[0].slice(0, 100)}${mash.answers[0].definitions[0].length > 100 ? '...*' : '*'}` : '';
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
context.sendMessage(mash.answers.length === 1
|
||||||
? `**${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'}**! 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);
|
: `**${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((answerX) => answerX.word !== word).map((answerX) => `*${answerX.word}*`).join(', ')}`, context.room.id);
|
||||||
|
|
||||||
context.logger.info(`Mash '${mash.anagram}' guessed by '${context.user.username}' with '${word}'`);
|
context.logger.info(`Mash '${mash.anagram}' guessed by '${context.user.username}' with '${word}'`);
|
||||||
context.setPoints(context.user, 1);
|
context.setPoints(context.user, 1);
|
||||||
|
@ -141,11 +143,11 @@ function hint(context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mash.anagram.length === 4) {
|
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);
|
context.sendMessage(`Hints for **${mash.anagram}**, @${context.user.username}: ${mash.answers.map((answer) => `**${answer.word.slice(0, 1)} ${'_ '.repeat(answer.word.length - 1).trim()}** (${answer.definitions[0]})`).join(', ')}`, context.room.id);
|
||||||
return;
|
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);
|
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)}** (${answer.definitions[0]})`).join(', ')}`, context.room.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCommand(args, context) {
|
function onCommand(args, context) {
|
||||||
|
@ -185,7 +187,14 @@ function onCommand(args, context) {
|
||||||
play(args[0], context);
|
play(args[0], context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onMessage(message, context) {
|
||||||
|
if (mash && context.user.id !== config.user.id) {
|
||||||
|
play(message.body, context, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Mash',
|
name: 'Mash',
|
||||||
onCommand,
|
onCommand,
|
||||||
|
onMessage,
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,7 +69,7 @@ async function playRound(context, round = 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.stopped) {
|
if (game.stopped) {
|
||||||
context.sendMessage(`The game was stopped by ${game.stopped.username}. The answer to the last question was: **${question.answer}**`, context.room.id);
|
context.sendMessage(`The game was stopped by @${game.stopped.username}. The answer to the last question was: **${question.answer}**`, context.room.id);
|
||||||
game = null;
|
game = null;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue