Curated Geo country file, improved hint letter spacing.

This commit is contained in:
Niels Simenon 2022-11-02 22:20:36 +01:00
parent 157ae8bfcc
commit c1b8340268
4 changed files with 1280 additions and 15 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

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);