Added chat token reset. WIP numbers game.
This commit is contained in:
79
src/games/numbers.js
Normal file
79
src/games/numbers.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user