Added flags to Geo.

This commit is contained in:
Niels Simenon
2022-11-06 16:14:14 +01:00
parent e0aab6acf3
commit 4727217b88
510 changed files with 1554 additions and 14 deletions

View File

@@ -3,16 +3,19 @@
const config = require('config');
const timers = require('timers/promises');
const countries = require('../../assets/countries-curated.json');
const states = require('../../assets/states-curated.json');
const pickRandom = require('../utils/pick-random');
const style = require('../utils/style');
const data = { countries, states };
const countries = require('../../assets/countries-curated.json');
const states = require('../../assets/states-curated.json');
const flags = require('../../assets/flags-curated.json');
const data = { countries, states, flags };
const games = {
countries: new Map(),
states: new Map(),
flags: new Map(),
};
const questions = [
@@ -48,8 +51,20 @@ function play(context, type = 'countries') {
context.logger.info(`Geo played '${country.name}' (${url})`);
}
function getType(command) {
if (['state', 'america'].includes(command)) {
return 'states';
}
if (['flag'].includes(command)) {
return 'flags';
}
return countries;
}
async function onCommand(args, context) {
const type = ['state', 'america'].includes(context.command) ? 'states' : 'countries';
const type = getType(context.command);
if (context.subcommand && !games[type].has(context.room.id)) {
context.sendMessage(`There is no country in play right now. Start a new round with ${config.prefix}geo!`, context.room.id);
@@ -81,7 +96,7 @@ async function onCommand(args, context) {
}
async function onMessage(message, context) {
['countries', 'states'].forEach(async (type) => {
['countries', 'states', 'flags'].forEach(async (type) => {
const game = games[type].get(context.room.id);
if (!game) {
@@ -104,6 +119,6 @@ async function onMessage(message, context) {
module.exports = {
onCommand,
onMessage,
commands: ['country', 'atlas', 'state', 'america'],
commands: ['country', 'atlas', 'state', 'america', 'flag'],
help: 'Name the country or US state on the map! Too hard? Try ~geo:hint or ~geo:skip.',
};

View File

@@ -101,7 +101,7 @@ function curateMessageBody(rawBody, game, key, options) {
return body;
}
const label = typeof options.label === 'string'
const label = typeof options?.label === 'string'
? capitalize(options.label)
: game.name || capitalize(key);