Added Magic 8-Ball game.

This commit is contained in:
Niels Simenon 2022-10-28 00:22:00 +02:00
parent 34fb977e77
commit acf60eeca0
104 changed files with 124 additions and 5 deletions

0
.editorconfig Normal file → Executable file
View File

0
.eslintrc Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
.nvmrc Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
assets/curate-jeopardy.js Normal file → Executable file
View File

0
assets/dictionary-to-mash.js Normal file → Executable file
View File

0
assets/dictionary.json Normal file → Executable file
View File

0
assets/jeopardy.json Normal file → Executable file
View File

0
assets/mash-average.js Normal file → Executable file
View File

0
assets/mash-words_short.json Normal file → Executable file
View File

0
assets/trivia/questions_00 Normal file → Executable file
View File

0
assets/trivia/questions_01 Normal file → Executable file
View File

0
assets/trivia/questions_02 Normal file → Executable file
View File

0
assets/trivia/questions_03 Normal file → Executable file
View File

0
assets/trivia/questions_04 Normal file → Executable file
View File

0
assets/trivia/questions_05 Normal file → Executable file
View File

0
assets/trivia/questions_06 Normal file → Executable file
View File

0
assets/trivia/questions_07 Normal file → Executable file
View File

0
assets/trivia/questions_08 Normal file → Executable file
View File

0
assets/trivia/questions_09 Normal file → Executable file
View File

0
assets/trivia/questions_10 Normal file → Executable file
View File

0
assets/trivia/questions_11 Normal file → Executable file
View File

0
assets/trivia/questions_12 Normal file → Executable file
View File

0
assets/trivia/questions_13 Normal file → Executable file
View File

0
assets/trivia/questions_14 Normal file → Executable file
View File

0
assets/trivia/questions_15 Normal file → Executable file
View File

0
assets/trivia/questions_16 Normal file → Executable file
View File

0
assets/trivia/questions_17 Normal file → Executable file
View File

0
assets/trivia/questions_18 Normal file → Executable file
View File

0
assets/trivia/questions_19 Normal file → Executable file
View File

0
assets/trivia/questions_20 Normal file → Executable file
View File

0
assets/trivia/questions_21 Normal file → Executable file
View File

0
assets/trivia/questions_22 Normal file → Executable file
View File

0
assets/trivia/questions_23 Normal file → Executable file
View File

0
assets/trivia/questions_24 Normal file → Executable file
View File

0
assets/trivia/questions_25 Normal file → Executable file
View File

0
assets/trivia/questions_26 Normal file → Executable file
View File

0
assets/trivia/questions_27 Normal file → Executable file
View File

0
assets/trivia/questions_28 Normal file → Executable file
View File

0
assets/trivia/questions_29 Normal file → Executable file
View File

0
assets/trivia/questions_30 Normal file → Executable file
View File

0
assets/trivia/questions_31 Normal file → Executable file
View File

0
assets/trivia/questions_32 Normal file → Executable file
View File

0
assets/trivia/questions_33 Normal file → Executable file
View File

0
assets/trivia/questions_34 Normal file → Executable file
View File

0
assets/trivia/questions_35 Normal file → Executable file
View File

0
assets/trivia/questions_36 Normal file → Executable file
View File

0
assets/trivia/questions_37 Normal file → Executable file
View File

0
assets/trivia/questions_38 Normal file → Executable file
View File

0
assets/trivia/questions_39 Normal file → Executable file
View File

0
assets/trivia/questions_40 Normal file → Executable file
View File

0
assets/trivia/questions_41 Normal file → Executable file
View File

0
assets/trivia/questions_42 Normal file → Executable file
View File

0
assets/trivia/questions_43 Normal file → Executable file
View File

0
assets/trivia/questions_44 Normal file → Executable file
View File

0
assets/trivia/questions_45 Normal file → Executable file
View File

0
assets/trivia/questions_46 Normal file → Executable file
View File

0
assets/trivia/questions_47 Normal file → Executable file
View File

0
assets/trivia/questions_48 Normal file → Executable file
View File

0
assets/trivia/questions_49 Normal file → Executable file
View File

0
assets/trivia/questions_50 Normal file → Executable file
View File

0
assets/trivia/questions_51 Normal file → Executable file
View File

0
assets/trivia/questions_52 Normal file → Executable file
View File

0
assets/trivia/questions_53 Normal file → Executable file
View File

0
assets/trivia/questions_54 Normal file → Executable file
View File

0
assets/trivia/questions_55 Normal file → Executable file
View File

0
assets/trivia/questions_56 Normal file → Executable file
View File

0
assets/trivia/questions_57 Normal file → Executable file
View File

0
assets/trivia/questions_58 Normal file → Executable file
View File

0
assets/trivia/questions_59 Normal file → Executable file
View File

0
assets/trivia/questions_60 Normal file → Executable file
View File

0
assets/trivia/questions_61 Normal file → Executable file
View File

0
assets/trivia/questions_62 Normal file → Executable file
View File

0
assets/trivia/questions_63 Normal file → Executable file
View File

0
assets/trivia/questions_64 Normal file → Executable file
View File

0
assets/trivia/questions_65 Normal file → Executable file
View File

0
assets/trivia/questions_66 Normal file → Executable file
View File

7
config/default.js Normal file → Executable file
View File

@ -21,8 +21,13 @@ module.exports = {
greeting: 'Hi, I am aisha, your game host!',
usernamePrefix: '@',
channels: ['GamesNight'],
games: ['mash', 'trivia', 'letters', 'duck', 'dice', 'rock-paper-scissors', 'ping', 'say', 'kill', 'uptime', 'help'],
games: ['mash', 'trivia', 'letters', 'duck', '8ball', 'dice', 'rock-paper-scissors', 'ping', 'say', 'kill', 'uptime', 'help'],
schatColors: {
white: 'white',
blue: 'var(--message-40)',
navy: 'var(--message-41)',
},
schatColorAliases: {
red: 'red',
orange: 'orange',
yellow: 'yellow',

0
ecosystem.config.js Normal file → Executable file
View File

11
package-lock.json generated Normal file → Executable file
View File

@ -21,6 +21,7 @@
"jsdom": "^18.1.0",
"linkify-it": "^3.0.3",
"simple-node-logger": "^21.8.12",
"string-similarity": "^4.0.4",
"tensify": "^0.0.4",
"ws": "^8.2.3",
"yargs": "^17.2.1"
@ -3250,6 +3251,11 @@
"safe-buffer": "~5.1.0"
}
},
"node_modules/string-similarity": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz",
"integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ=="
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@ -6334,6 +6340,11 @@
"safe-buffer": "~5.1.0"
}
},
"string-similarity": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz",
"integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ=="
},
"string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",

1
package.json Normal file → Executable file
View File

@ -30,6 +30,7 @@
"jsdom": "^18.1.0",
"linkify-it": "^3.0.3",
"simple-node-logger": "^21.8.12",
"string-similarity": "^4.0.4",
"tensify": "^0.0.4",
"ws": "^8.2.3",
"yargs": "^17.2.1"

0
src/app.js Normal file → Executable file
View File

102
src/games/8ball.js Normal file
View File

@ -0,0 +1,102 @@
'use strict';
const config = require('config');
const crypto = require('crypto');
const timers = require('timers/promises');
const stringSimilarity = require('string-similarity');
const style = require('../utils/style');
const contemplations = [
'Hmmm...',
'🤔',
'Let\'s see...',
];
const answers = {
positive: [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs points to yes',
],
inconclusive: [
'Reply hazy, try again',
'Ask again later',
'Better not tell you now',
'Cannot predict now',
'Concentrate and ask again',
],
negative: [
'Don\'t count on it',
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful',
],
};
const questions = new Map();
function purgeQuestions() {
Array.from(questions.entries()).forEach(([question, { timestamp }]) => {
if (new Date() - timestamp > 5 * 60 * 1000) { // 5 minutes
questions.delete(question);
}
});
}
async function onCommand(args, context) {
const question = args.join(' ');
if (!/\w+\s+\w+\?/.test(question)) {
context.sendMessage('Please ask me a question, any question...', context.room.id);
return;
}
// attempt to give consistent answers between similar questions
const similarQuestion = questions.size > 0
? stringSimilarity.findBestMatch(question, Array.from(questions.keys())).bestMatch
: null;
const answerType = similarQuestion?.rating > 0.5
? questions.get(similarQuestion.target).answerType
: Object.keys(answers)[crypto.randomInt(0, 3)];
const answer = answers[answerType][crypto.randomInt(0, answers[answerType].length)];
questions.set(question, { answerType, timestamp: new Date() });
context.sendMessage(`🎱 ${contemplations[crypto.randomInt(0, contemplations.length)]}`, context.room.id, { label: false });
await timers.setTimeout(Math.random() * 3000 + 1000);
context.sendMessage(style.bgnavy(style.white(`${answer}`)), context.room.id, {
label: false,
style: {
color: config.schatColors.white,
background: config.schatColors.navy,
},
});
purgeQuestions();
}
function onMessage(message, context) {
const regex = new RegExp(`^${config.usernamePrefix}${config.user.username}:?\\s+\\w+\\s+\\w+.*\\?`, 'i');
if (regex.test(message.body)) {
onCommand([message.body.replaceAll(`${config.usernamePrefix}${config.user.username}:?`, '').trim()], context, false);
}
}
module.exports = {
onCommand,
onMessage,
};

0
src/games/cursed.js Normal file → Executable file
View File

0
src/games/dice.js Normal file → Executable file
View File

0
src/games/duck.js Normal file → Executable file
View File

0
src/games/help.js Normal file → Executable file
View File

0
src/games/kill.js Normal file → Executable file
View File

0
src/games/letters.js Normal file → Executable file
View File

0
src/games/mash.js Normal file → Executable file
View File

0
src/games/ping.js Normal file → Executable file
View File

0
src/games/rock-paper-scissors.js Normal file → Executable file
View File

0
src/games/say.js Normal file → Executable file
View File

0
src/games/trivia.js Normal file → Executable file
View File

0
src/games/uptime.js Normal file → Executable file
View File

0
src/irc.js Normal file → Executable file
View File

6
src/play.js Normal file → Executable file
View File

@ -117,9 +117,9 @@ async function getGames(bot, identifier) {
bot.socket.transmit('message', {
roomId,
recipient,
type: recipient && options.type !== 'message' ? 'whisper' : 'message',
type: recipient && options?.type !== 'message' ? 'whisper' : 'message',
body: curatedBody,
style: config.style,
style: { ...config.style, ...options?.style },
});
}
};
@ -235,7 +235,7 @@ function onMessage(message, bot, games) {
}
}
if (message.type === 'message') {
if (message.type === 'message' && user.username !== config.user.username) {
Object.values(Object.fromEntries(Object.values(games).map((game) => [game.key, game]))).forEach((game) => game.onMessage?.(message, {
...game,
bot,

0
src/schat.js Normal file → Executable file
View File

0
src/utils/get-leaders.js Normal file → Executable file
View File

Some files were not shown because too many files have changed in this diff Show More