Added question rotation to Geo.
This commit is contained in:
parent
d99503885b
commit
631dc58d3c
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const timers = require('timers/promises');
|
||||
|
||||
const countries = require('../../assets/countries-curated.json');
|
||||
const pickRandom = require('../utils/pick-random');
|
||||
|
@ -10,7 +11,10 @@ const games = new Map();
|
|||
|
||||
const questions = [
|
||||
'What\'s this country?',
|
||||
'Name this country:',
|
||||
'Where are we going on holiday?',
|
||||
'What\'s our destination?',
|
||||
'I\'d never heard of that place, what\'s it called?',
|
||||
];
|
||||
|
||||
function hint(game, context) {
|
||||
|
@ -31,7 +35,7 @@ function hint(game, context) {
|
|||
.toUpperCase())}, the country code is ${style.bold(game.alpha2)}`, context.room.id);
|
||||
}
|
||||
|
||||
function start(context) {
|
||||
function play(context) {
|
||||
const country = pickRandom(countries);
|
||||
const url = `${config.geo.url}${country.file}`;
|
||||
|
||||
|
@ -46,20 +50,22 @@ function start(context) {
|
|||
}
|
||||
|
||||
async function onCommand(args, context) {
|
||||
const game = games.get(context.room.id);
|
||||
|
||||
if (!game && context.subcommand) {
|
||||
if (context.subcommand && !games.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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (['skip', 'stop', 'reset'].includes(context.subcommand)) {
|
||||
const game = games.get(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);
|
||||
|
||||
return;
|
||||
await timers.setTimeout(2000);
|
||||
}
|
||||
|
||||
const game = games.get(context.room.id);
|
||||
|
||||
if (context.subcommand === 'hint') {
|
||||
hint(game, context);
|
||||
return;
|
||||
|
@ -70,7 +76,7 @@ async function onCommand(args, context) {
|
|||
return;
|
||||
}
|
||||
|
||||
start(context);
|
||||
play(context);
|
||||
}
|
||||
|
||||
async function onMessage(message, context) {
|
||||
|
@ -85,10 +91,16 @@ async function onMessage(message, context) {
|
|||
context.setPoints(context.user);
|
||||
|
||||
games.delete(context.room.id);
|
||||
|
||||
await timers.setTimeout(3000);
|
||||
|
||||
play(context);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
onCommand,
|
||||
onMessage,
|
||||
commands: ['country', 'atlas'],
|
||||
help: 'Name the country on the map! Too hard? Try ~geo:hint or ~geo:skip.',
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue