Compare commits

...

8 Commits

Author SHA1 Message Date
ThePendulum
59dd7c793a 1.30.8 2025-02-18 22:13:26 +01:00
ThePendulum
a9f733227c Added weekly points back-up, writing points to dedicated directory. 2025-02-18 22:13:24 +01:00
ThePendulum
19feb9a55f 1.30.7 2024-09-04 22:28:02 +02:00
ThePendulum
df3c682ff6 Separated wordle and hardle score. 2024-09-04 22:28:00 +02:00
ThePendulum
aca9a4b597 1.30.6 2024-09-04 22:26:16 +02:00
ThePendulum
e4055ad99c Another fix for missing definition breaking mash. 2024-09-04 22:26:14 +02:00
ThePendulum
5dcb928c35 1.30.5 2024-08-24 18:01:10 +02:00
ThePendulum
8c7995340e Fixed missing definition breaking mash. 2024-08-24 18:01:08 +02:00
6 changed files with 20 additions and 9 deletions

2
.gitignore vendored
View File

@@ -4,5 +4,5 @@ config/*
*.config.js *.config.js
!ecosystem.config.js !ecosystem.config.js
*.sqlite *.sqlite
points*.json points/*
assets/mash-words.json assets/mash-words.json

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.30.4", "version": "1.30.8",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.30.4", "version": "1.30.8",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"better-sqlite3": "^8.3.0", "better-sqlite3": "^8.3.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.30.4", "version": "1.30.8",
"description": "Game host for SChat 2-powered chat sites", "description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js", "main": "src/app.js",
"scripts": { "scripts": {

View File

@@ -81,7 +81,9 @@ function play(rawWord, context, shouted) {
} }
if (answer) { 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 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)}.` ? `${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) { function sanitizeDefinition(definition, answers) {
if (!definition) {
return 'No definition';
}
return definition.replaceAll(/\w+/g, (word) => { return definition.replaceAll(/\w+/g, (word) => {
if (answers.some((answer) => answer.word.includes(word))) { if (answers.some((answer) => answer.word.includes(word))) {
return '*'.repeat(word.length); return '*'.repeat(word.length);

View File

@@ -192,7 +192,8 @@ function play(guess, context) {
const definition = wordle.definitions[0] ? `: ${style.italic(`${wordle.definitions[0].slice(0, 100)}${wordle.definitions[0].length > 100 ? '...' : ''}`)}` : ''; const definition = wordle.definitions[0] ? `: ${style.italic(`${wordle.definitions[0].slice(0, 100)}${wordle.definitions[0].length > 100 ? '...' : ''}`)}` : '';
context.setPoints(context.user, points); 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); 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); wordles.delete(context.room.id);

View File

@@ -3,6 +3,7 @@
const config = require('config'); const config = require('config');
const fs = require('fs').promises; const fs = require('fs').promises;
const logger = require('simple-node-logger').createSimpleLogger(); const logger = require('simple-node-logger').createSimpleLogger();
const { getWeek } = require('date-fns');
const { argv } = require('yargs'); const { argv } = require('yargs');
// const timers = require('timers/promises'); // const timers = require('timers/promises');
@@ -15,14 +16,16 @@ const points = {};
async function initPoints(identifier) { async function initPoints(identifier) {
try { 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)); Object.assign(points, JSON.parse(pointsFile));
} catch (error) { } catch (error) {
if (error.code === 'ENOENT') { if (error.code === 'ENOENT') {
logger.info('Creating new points file'); 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); await initPoints(identifier);
} }
} }
@@ -50,7 +53,8 @@ async function setPoints(identifier, defaultKey, user, value, { mode = 'add', ke
points[gameKey][userKey] = value; 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 }) { function getPoints(game, rawUsername, { user, room, command }) {