mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Make doors the monty hall paradox
This commit is contained in:
@@ -248,7 +248,7 @@ Xiao is a Discord bot coded in JavaScript with
|
|||||||
* **box-choosing:** Do you believe that there are choices in life? Taken from Higurashi Chapter 4.
|
* **box-choosing:** Do you believe that there are choices in life? Taken from Higurashi Chapter 4.
|
||||||
* **captcha:** Try to guess what the captcha says.
|
* **captcha:** Try to guess what the captcha says.
|
||||||
* **chance:** Attempt to win with a 1 in 1000 (or your choice) chance of winning.
|
* **chance:** Attempt to win with a 1 in 1000 (or your choice) chance of winning.
|
||||||
* **doors:** Open the right door, and you win the money! Make the wrong one, and you get the fire!
|
* **doors:** Open the right door, and you win the money! Make the wrong choice, and you get the fire!
|
||||||
* **emoji-emoji-revolution:** Can you type arrow emoji faster than anyone else has ever typed them before?
|
* **emoji-emoji-revolution:** Can you type arrow emoji faster than anyone else has ever typed them before?
|
||||||
* **fishy:** Go fishing.
|
* **fishy:** Go fishing.
|
||||||
* **google-feud:** Attempt to determine the top suggestions for a Google search.
|
* **google-feud:** Attempt to determine the top suggestions for a Google search.
|
||||||
|
|||||||
+32
-9
@@ -1,14 +1,16 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
|
const { verify } = require('../../util/Util');
|
||||||
|
const doors = [1, 2, 3];
|
||||||
|
|
||||||
module.exports = class DoorsCommand extends Command {
|
module.exports = class DoorsCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'doors',
|
name: 'doors',
|
||||||
aliases: ['door', 'door-opening', 'open-door'],
|
aliases: ['door', 'door-opening', 'open-door', 'monty-hall'],
|
||||||
group: 'games',
|
group: 'games',
|
||||||
memberName: 'doors',
|
memberName: 'doors',
|
||||||
description: 'Open the right door, and you win the money! Make the wrong one, and you get the fire!',
|
description: 'Open the right door, and you win the money! Make the wrong choice, and you get the fire!',
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'door',
|
key: 'door',
|
||||||
@@ -19,14 +21,35 @@ module.exports = class DoorsCommand extends Command {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.playing = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
run(msg, { door }) {
|
async run(msg, { door }) {
|
||||||
const win = Math.floor(Math.random() * 3) + 1;
|
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
|
||||||
const emoji = door === win ? '💰' : '🔥';
|
this.playing.add(msg.channel.id);
|
||||||
return msg.reply(stripIndents`
|
try {
|
||||||
${door === win ? 'You chose wisely.' : 'Hmm... Try again.'}
|
const win = doors[Math.floor(Math.random() * doors.length)];
|
||||||
${door === 1 ? emoji : '🚪'} ${door === 2 ? emoji : '🚪'} ${door === 3 ? emoji : '🚪'}
|
const doorNoWin = doors.filter(thisDoor => thisDoor !== win);
|
||||||
`);
|
const noWin = doorNoWin[Math.floor(Math.random() * doorNoWin.length)];
|
||||||
|
await msg.reply(stripIndents`
|
||||||
|
Well, there's nothing behind door number **${noWin}**. Do you want to stick with door ${door}?
|
||||||
|
${this.doorEmoji(1, noWin)} ${this.doorEmoji(2, noWin)} ${this.doorEmoji(3, noWin)}
|
||||||
|
`);
|
||||||
|
const stick = await verify(msg.channel, msg.author);
|
||||||
|
if (!stick) door = doors.filter(thisDoor => door !== thisDoor && thisDoor !== noWin)[0];
|
||||||
|
this.playing.delete(msg.channel.id);
|
||||||
|
return msg.reply(stripIndents`
|
||||||
|
${door === win ? 'You chose wisely.' : 'Hmm... Try again.'}
|
||||||
|
${this.doorEmoji(1, noWin, win)} ${this.doorEmoji(2, noWin, win)} ${this.doorEmoji(3, noWin, win)}
|
||||||
|
`);
|
||||||
|
} catch (err) {
|
||||||
|
this.playing.delete(msg.channel.id);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doorEmoji(door, noWin, win) {
|
||||||
|
return door === win ? '💰' : door === noWin ? '🔥' : '🚪';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "98.0.2",
|
"version": "98.0.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user