mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add xyzzy to minesweeper
This commit is contained in:
@@ -62,7 +62,6 @@
|
||||
"In the `roman` command, typing \"zero\" will give you \"_nulla_\", the latin word for zero. This is because zero does not exist in roman numerals.",
|
||||
"The `horse-race` command contains several references: real horse names, My Little Pony characters, and various pop culture jokes. Even a few Xiao jokes are snuck in there!",
|
||||
"In `horse-race`, you will occasionally encounter horses named \"Donald Trump\" and \"Dragon Fire\". Be careful, as these aren't horses, their times are based on the actual human running the race!",
|
||||
"To this day, no one has actually tried to date Dragon Fire after using the `dating` command. Several irl friends thought the joke was funny, though.",
|
||||
"The `screenshot` command uses a massive 2,000,000 entry array to check for adult sites. Some _still_ fall through the cracks.",
|
||||
"The `ship` command will call you a narcissist if you test yourself with yourself.",
|
||||
"Whenever Dragon Fire gets a real fortune cookie, he adds the fortune to the `fortune` command.",
|
||||
@@ -70,5 +69,6 @@
|
||||
"The `pokedex` command will play the Pokémon's cry if both you and the bot are in a voice channel when the command is used.",
|
||||
"Answers from `would-you-rather` and `will-you-press-the-button` are sent to their respective sites in order to improve their results.",
|
||||
"Reminders in the `remind` command have a maximum length of ~24.84 days. This is due to how JavaScript timeouts work, anything higher than this will fire early, or possibly even instantly.",
|
||||
"For a very long time, `yu-gi-oh-gen` only supported Effect Monsters. `yu-gi-oh-token` was also a seperate command, and did not allow any customization outside of the image."
|
||||
"For a very long time, `yu-gi-oh-gen` only supported Effect Monsters. `yu-gi-oh-token` was also a seperate command, and did not allow any customization outside of the image.",
|
||||
"In `minesweeper`, typing \"xyzzy\" at any point in the game will activate cheat mode, displaying where mines are on the board. No high scores can be saved in this mode, however."
|
||||
]
|
||||
|
||||
@@ -40,18 +40,20 @@ module.exports = class MinesweeperCommand extends Command {
|
||||
game.onLoss = () => { win = false; };
|
||||
const flagged = [];
|
||||
const startTime = new Date();
|
||||
let cheatMode = false;
|
||||
while (win === null) {
|
||||
const currentTime = moment.duration(new Date() - startTime).format('mm:ss');
|
||||
await msg.say(stripIndents`
|
||||
${msg.author}, what coordinates do you pick (ex. 4,5)? Type \`end\` to forefeit.
|
||||
Type \`flag <coordinates>\` to flag a spot as a bomb. To remove a flag, run it again.
|
||||
|
||||
${this.displayBoard(game.board, game.mask, flagged)}
|
||||
${this.displayBoard(game.board, game.mask, flagged, cheatMode)}
|
||||
**Total Mines:** ${size + 1} | **Flagged:** ${flagged.length} | **Time:** ${currentTime}
|
||||
`);
|
||||
const filter = res => {
|
||||
if (res.author.id !== msg.author.id) return false;
|
||||
const pick = res.content;
|
||||
if (pick.toLowerCase() === 'xyzzy' && !cheatMode) return true;
|
||||
if (pick.toLowerCase() === 'end') return true;
|
||||
const coordPicked = pick.match(turnRegex);
|
||||
if (!coordPicked) return false;
|
||||
@@ -74,6 +76,11 @@ module.exports = class MinesweeperCommand extends Command {
|
||||
win = false;
|
||||
break;
|
||||
}
|
||||
if (choice.toLowerCase() === 'xyzzy') {
|
||||
cheatMode = true;
|
||||
await msg.say('Cheat mode is now active. No high score will be saved.');
|
||||
continue;
|
||||
}
|
||||
const coordPicked = choice.match(turnRegex);
|
||||
const x = Number.parseInt(coordPicked[2], 10);
|
||||
const y = Number.parseInt(coordPicked[3], 10);
|
||||
@@ -101,7 +108,7 @@ module.exports = class MinesweeperCommand extends Command {
|
||||
const highScoreGet = await this.client.redis.get(`minesweeper-${size}`);
|
||||
const highScore = highScoreGet ? Number.parseInt(highScoreGet, 10) : null;
|
||||
const highScoreUser = await this.client.redis.get(`minesweeper-${size}-user`);
|
||||
const scoreBeat = win && (!highScore || highScore > newScore);
|
||||
const scoreBeat = !cheatMode && win && (!highScore || highScore > newScore);
|
||||
const user = await fetchHSUserDisplay(this.client, highScoreUser);
|
||||
if (scoreBeat) {
|
||||
await this.client.redis.set(`minesweeper-${size}`, newScore);
|
||||
@@ -123,7 +130,7 @@ module.exports = class MinesweeperCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
displayBoard(board, mask, flagged) {
|
||||
displayBoard(board, mask, flagged, cheatMode = false) {
|
||||
let str = '';
|
||||
str += '⬛';
|
||||
str += nums.slice(0, board.length).join('');
|
||||
@@ -131,12 +138,12 @@ module.exports = class MinesweeperCommand extends Command {
|
||||
for (let i = 0; i < board.length; i++) {
|
||||
str += nums[i];
|
||||
board[i].forEach((item, j) => {
|
||||
if (!mask || mask[i][j]) {
|
||||
if (cheatMode || !mask || mask[i][j]) {
|
||||
if (item === '*') {
|
||||
str += '💣';
|
||||
} else if (item === 0) {
|
||||
} else if (!cheatMode && item === 0) {
|
||||
str += '⬜';
|
||||
} else {
|
||||
} else if (!cheatMode) {
|
||||
str += nums[item - 1];
|
||||
}
|
||||
} else if (flagged.includes(`${j},${i}`)) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "126.6.2",
|
||||
"version": "126.6.3",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user