Added chat token reset. WIP numbers game.

This commit is contained in:
Niels Simenon
2023-04-10 01:23:19 +02:00
parent 7321037f4f
commit 74342ab07b
3 changed files with 110 additions and 9 deletions

79
src/games/numbers.js Normal file
View File

@@ -0,0 +1,79 @@
'use strict';
const config = require('config');
const { evaluate } = require('mathjs');
const games = new Map();
function getBoard(context) {
const game = games.get(context.room.id);
return game;
}
function pickNumbers(type, context) {
const game = games.get(context.room.id);
if (!game) {
return;
}
console.log('pick', type);
}
function playSolution(solution, context) {
}
function start(context) {
if (games.has(context.room.id)) {
context.sendMessage(`${getBoard(context)} This is the current board. Use ${config.prefix}numbers:stop to reset.`);
return;
}
games.set(context.room.id, {
state: 'pick',
});
context.sendMessage('Let\'s play the numbers! Would you like a big number or a small one?', context.room.id);
}
function onCommand(args, context) {
if (!args.subcommand) {
start(context);
}
}
function onMessage(message, context) {
console.log('message', message.body);
const game = games.get(context.room.id);
if (game?.state === 'pick') {
const multi = message.body.match(/\b[bs]{2,}\b/i)?.[0];
if (multi) {
pickNumbers(multi.toLowerCase(), context);
return;
}
if (/big/i.test(message.body)) {
pickNumbers('big', context);
return;
}
if (/small/i.test(message.body)) {
pickNumbers('small', context);
return;
}
}
if (game?.state === 'solutions') {
playSolution(message.body);
}
}
module.exports = {
onCommand,
onMessage,
};