Compare commits

...

2 Commits

Author SHA1 Message Date
Niels Simenon 9c1966f600 1.20.3 2022-11-02 22:20:38 +01:00
Niels Simenon c1b8340268 Curated Geo country file, improved hint letter spacing. 2022-11-02 22:20:36 +01:00
6 changed files with 1283 additions and 18 deletions

View File

@ -985,7 +985,8 @@
"file": "174f.png", "file": "174f.png",
"code": 760, "code": 760,
"alpha2": "SY", "alpha2": "SY",
"name": "Syrian Arab Republic" "name": "Syria",
"fullName": "Syrian Arab Republic"
}, },
{ {
"file": "715f.png", "file": "715f.png",

View File

@ -2,9 +2,25 @@
const fs = require('fs').promises; const fs = require('fs').promises;
const crypto = require('crypto'); const crypto = require('crypto');
// const bhttp = require('bhttp');
const countries = require('./countries.json'); const countries = require('./countries.json');
/*
async function fetchCountries() {
const res = await bhttp.get('http://localhost:3000/api/countries');
if (res.statusCode === 200) {
await fs.writeFile('./assets/countries.json', JSON.stringify(res.body, null, 4));
console.log('Done fetching countries!');
return;
}
console.log(`Failed to fetch countries: ${res.statusCode}`);
}
*/
async function init() { async function init() {
const countryImgs = await fs.readdir('./assets/countries'); const countryImgs = await fs.readdir('./assets/countries');
const countriesByCode = Object.fromEntries(countries.map((country) => [country.alpha2, country])); const countriesByCode = Object.fromEntries(countries.map((country) => [country.alpha2, country]));
@ -28,3 +44,4 @@ async function init() {
} }
init(); init();
// fetchCountries();

File diff suppressed because one or more lines are too long

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.20.2", "version": "1.20.3",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.20.2", "version": "1.20.3",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"bhttp": "^1.2.8", "bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.20.2", "version": "1.20.3",
"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

@ -19,20 +19,12 @@ const questions = [
function hint(game, context) { function hint(game, context) {
if (game.name.length >= 5) { if (game.name.length >= 5) {
context.sendMessage(`${style.bold(game.name context.sendMessage(`${style.bold(`${game.name.slice(0, 1)}${game.name.slice(1, -1).replace(/\s/g, '').replace(/[^\s]/g, '_')}${game.name.slice(-1)}`.toUpperCase())}, the country code s ${style.bold(game.alpha2)}`, context.room.id); // eslint-disable-line no-irregular-whitespace
.split('')
.map((letter, index) => (index === 0 || index === game.name.length - 1 ? letter : '_'))
.join(' ')
.toUpperCase())}, the country code is ${style.bold(game.alpha2)}`, context.room.id);
return; return;
} }
context.sendMessage(`${style.bold(game.name context.sendMessage(`${style.bold(`${game.name.slice(0, 1)}${game.name.slice(1).replace(/\s/g, '').replace(/[^\s]/g, '_').trim()}`.toUpperCase())}, the country code is ${style.bold(game.alpha2)}`, context.room.id); // eslint-disable-line no-irregular-whitespace
.split('')
.map((letter, index) => (index === 0 ? letter : '_'))
.join(' ')
.toUpperCase())}, the country code is ${style.bold(game.alpha2)}`, context.room.id);
} }
function play(context) { function play(context) {
@ -42,7 +34,7 @@ function play(context) {
games.set(context.room.id, { games.set(context.room.id, {
...country, ...country,
url, url,
regexp: new RegExp(country.name, 'i'), regexp: new RegExp(country.fullName ? `(${country.name})|(${country.fullName})` : country.name, 'i'),
}); });
context.sendMessage(`${url} ${pickRandom(questions)}`, context.room.id); context.sendMessage(`${url} ${pickRandom(questions)}`, context.room.id);
@ -59,7 +51,7 @@ async function onCommand(args, context) {
const game = games.get(context.room.id); const game = games.get(context.room.id);
games.delete(context.room.id); games.delete(context.room.id);
context.sendMessage(`Geo was skipped by ${context.user.prefixedUsername}. The country was ${style.bold(game.name)}.`, context.room.id); context.sendMessage(`Geo was skipped by ${context.user.prefixedUsername}. The country was ${style.bold(game.fullName ? `${game.fullName} (${game.name})` : game.name)}.`, context.room.id);
await timers.setTimeout(2000); await timers.setTimeout(2000);
} }
@ -87,7 +79,7 @@ async function onMessage(message, context) {
} }
if (game.regexp.test(message.body)) { if (game.regexp.test(message.body)) {
context.sendMessage(`${style.answer(game.name)} is the right answer! ${style.username(context.user.prefixedUsername)} gets a point.`, context.room.id); context.sendMessage(`${style.answer(game.fullName || game.name)} is the right answer! ${style.username(context.user.prefixedUsername)} gets a point.`, context.room.id);
context.setPoints(context.user); context.setPoints(context.user);
games.delete(context.room.id); games.delete(context.room.id);