Compare commits
14 Commits
857f1816f0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59dd7c793a | ||
|
|
a9f733227c | ||
|
|
19feb9a55f | ||
|
|
df3c682ff6 | ||
|
|
aca9a4b597 | ||
|
|
e4055ad99c | ||
|
|
5dcb928c35 | ||
|
|
8c7995340e | ||
|
|
84025d6a8b | ||
|
|
84b158cf21 | ||
|
|
7531a69904 | ||
|
|
c402628161 | ||
|
|
e9df99bdcb | ||
|
|
a0f1914ce6 |
@@ -15,6 +15,6 @@
|
||||
"no-console": 0,
|
||||
"indent": ["error", "tab"],
|
||||
"no-tabs": 0,
|
||||
"max-len": [2, {"code": 400, "tabWidth": 4, "ignoreUrls": true}]
|
||||
"max-len": 0
|
||||
}
|
||||
}
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,5 @@ config/*
|
||||
*.config.js
|
||||
!ecosystem.config.js
|
||||
*.sqlite
|
||||
points*.json
|
||||
points/*
|
||||
assets/mash-words.json
|
||||
|
||||
@@ -137,6 +137,7 @@ module.exports = {
|
||||
wordle: {
|
||||
minLength: 3,
|
||||
length: 5,
|
||||
bonusDictionaryThreshold: 1000, // minimum dictionary size to assign bonus points, prevent people from scoring full bonus points from 1-word dictionaries
|
||||
mode: 'easy',
|
||||
},
|
||||
numbers: {
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.30.1",
|
||||
"version": "1.30.8",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "schat2-clive",
|
||||
"version": "1.30.1",
|
||||
"version": "1.30.8",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^8.3.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.30.1",
|
||||
"version": "1.30.8",
|
||||
"description": "Game host for SChat 2-powered chat sites",
|
||||
"main": "src/app.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -35,7 +35,7 @@ function start(length, context, attempt = 0) {
|
||||
|
||||
if (answers.some((answer) => answer.word === anagram)) {
|
||||
if (attempt >= 10) {
|
||||
context.sendMessage(`Sorry, I did not find a mashable ${length}-letter word`);
|
||||
context.sendMessage(`Sorry, I did not find a mashable ${length}-letter word`, context.room.id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ function play(rawWord, context, shouted) {
|
||||
}
|
||||
|
||||
if (answer) {
|
||||
const definition = answer.definitions[0] ? `: ${style.italic(`${answer.definitions[0].slice(0, 100)}${mash.answers[0].definitions[0].length > 100 ? '...' : ''}`)}` : '';
|
||||
const definition = answer.definitions[0]
|
||||
? `: ${style.italic(`${answer.definitions[0].slice(0, 100)}${answer.definitions[0].length > 100 ? '...' : ''}`)}`
|
||||
: '';
|
||||
|
||||
context.sendMessage(mash.answers.length === 1
|
||||
? `${style.bold(style.yellow(word))} is the right answer${definition}, ${style.bold(style.cyan(`${config.usernamePrefix}${context.user.username}`))} now has ${style.bold(`${context.user.points + 1} ${context.user.points === 0 ? 'point' : 'points'}`)}! There were no other options for ${style.bold(mash.anagram)}.`
|
||||
@@ -153,6 +155,10 @@ function define(word, context) {
|
||||
}
|
||||
|
||||
function sanitizeDefinition(definition, answers) {
|
||||
if (!definition) {
|
||||
return 'No definition';
|
||||
}
|
||||
|
||||
return definition.replaceAll(/\w+/g, (word) => {
|
||||
if (answers.some((answer) => answer.word.includes(word))) {
|
||||
return '*'.repeat(word.length);
|
||||
|
||||
@@ -185,11 +185,16 @@ function play(guess, context) {
|
||||
wordle.guesses = wordle.guesses.concat([[context.user.username, upperGuess]]);
|
||||
|
||||
if (upperGuess === wordle.word) {
|
||||
const points = Math.max((wordle.word.length + 1) - wordle.guesses.length, 1);
|
||||
const assignBonusPoints = wordle.wordList.length > config.wordle.bonusDictionaryThreshold;
|
||||
const points = assignBonusPoints
|
||||
? Math.max((wordle.word.length + 1) - wordle.guesses.length, 1)
|
||||
: 1;
|
||||
|
||||
const definition = wordle.definitions[0] ? `: ${style.italic(`${wordle.definitions[0].slice(0, 100)}${wordle.definitions[0].length > 100 ? '...' : ''}`)}` : '';
|
||||
|
||||
context.setPoints(context.user, points);
|
||||
context.sendMessage(`${getBoard(check, false, context)} is correct in ${wordle.guesses.length} guesses! ${style.bold(style.cyan(`${config.usernamePrefix}${context.user.username}`))} gets ${points} ${points > 1 ? 'points' : 'point'}. ${style.bold(wordle.word)}${definition}`, context.room.id);
|
||||
context.setPoints(context.user, points, { key: wordle.mode === 'hard' ? 'hardle' : 'wordle' });
|
||||
|
||||
context.sendMessage(`${getBoard(check, false, context)} is correct in ${wordle.guesses.length} guesses! ${style.bold(style.cyan(`${config.usernamePrefix}${context.user.username}`))} gets ${points} ${points > 1 ? 'points' : 'point'}${assignBonusPoints ? '. ' : ` (${wordle.word.length}-letter dictionary too small for bonus points). `}${style.bold(wordle.word)}${definition}`, context.room.id);
|
||||
|
||||
wordles.delete(context.room.id);
|
||||
|
||||
@@ -234,7 +239,7 @@ function onCommand(args, context) {
|
||||
module.exports = {
|
||||
name: 'Wordle',
|
||||
commands: ['wordle', 'hardle', 'lingo', 'guess', 'w'],
|
||||
help: `Guess the ${settings.length}-letter word on the board. Submit a guess with ${config.prefix}w [word]. If the letter is green, it is in the correct place. If it is yellow, it is part of the word, but not in the correct place. The number of letters in the word is the highest score you can get. You lose 1 point per guess, down to 1 point.`,
|
||||
help: `Guess the ${settings.length}-letter word on the board. Submit a guess with ${config.prefix}w [word]. If the letter is green, it is in the correct place. If it is yellow, it is part of the word, but not in the correct place. The number of letters in the word is the highest score you can get. You lose 1 point per guess, down to 1 point. Change the numbers of letters or switch to hard mode with ~wordle [length] [hard] or ~hardle [length].`,
|
||||
onCommand,
|
||||
// onMessage,
|
||||
};
|
||||
|
||||
15
src/play.js
15
src/play.js
@@ -3,6 +3,7 @@
|
||||
const config = require('config');
|
||||
const fs = require('fs').promises;
|
||||
const logger = require('simple-node-logger').createSimpleLogger();
|
||||
const { getWeek } = require('date-fns');
|
||||
const { argv } = require('yargs');
|
||||
// const timers = require('timers/promises');
|
||||
|
||||
@@ -15,14 +16,16 @@ const points = {};
|
||||
|
||||
async function initPoints(identifier) {
|
||||
try {
|
||||
const pointsFile = await fs.readFile(`./points-${identifier}.json`, 'utf-8');
|
||||
const pointsFile = await fs.readFile(`./points/points-${identifier}.json`, 'utf-8');
|
||||
|
||||
Object.assign(points, JSON.parse(pointsFile));
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
logger.info('Creating new points file');
|
||||
|
||||
await fs.writeFile(`./points-${identifier}.json`, '{}');
|
||||
await fs.mkdir('./points', { recursive: true });
|
||||
|
||||
await fs.writeFile(`./points/points-${identifier}.json`, '{}');
|
||||
await initPoints(identifier);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +53,8 @@ async function setPoints(identifier, defaultKey, user, value, { mode = 'add', ke
|
||||
points[gameKey][userKey] = value;
|
||||
}
|
||||
|
||||
await fs.writeFile(`./points-${identifier}.json`, JSON.stringify(points, null, 4));
|
||||
await fs.writeFile(`./points/points-${identifier}_backup${getWeek(new Date())}.json`, JSON.stringify(points, null, 4)); // weekly back-up
|
||||
await fs.writeFile(`./points/points-${identifier}.json`, JSON.stringify(points, null, 4));
|
||||
}
|
||||
|
||||
function getPoints(game, rawUsername, { user, room, command }) {
|
||||
@@ -117,6 +121,11 @@ async function getGames(bot, identifier) {
|
||||
const sendMessage = (body, roomId, options, recipient) => {
|
||||
const curatedBody = curateMessageBody(body, game, key, options);
|
||||
|
||||
if (!roomId && !recipient) {
|
||||
logger.error(`Missing room ID or recipient for message: ${body}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.platform === 'irc') {
|
||||
bot.client.say(/^#/.test(roomId) ? roomId : recipient, curatedBody);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user