Edit message in minesweeper

This commit is contained in:
Dragon Fire
2024-04-12 15:05:04 -04:00
parent 93bb1db77b
commit 88a4b0608c
7 changed files with 35 additions and 17 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = class ApplesToApplesCommand extends Command {
description: 'Compete to see who can come up with the best card to match an adjective.', description: 'Compete to see who can come up with the best card to match an adjective.',
guildOnly: true, guildOnly: true,
game: true, game: true,
clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory],
credit: [ credit: [
{ {
name: 'Mattel', name: 'Mattel',
+1 -1
View File
@@ -16,7 +16,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
guildOnly: true, guildOnly: true,
nsfw: true, nsfw: true,
game: true, game: true,
clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory],
credit: [ credit: [
{ {
name: 'Cards Against Humanity', name: 'Cards Against Humanity',
+1 -1
View File
@@ -16,7 +16,7 @@ module.exports = class ImposterCommand extends Command {
description: 'Who is the imposter among us?', description: 'Who is the imposter among us?',
guildOnly: true, guildOnly: true,
game: true, game: true,
clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory],
args: [ args: [
{ {
key: 'playersCount', key: 'playersCount',
+28 -10
View File
@@ -1,4 +1,5 @@
const Command = require('../../framework/Command'); const Command = require('../../framework/Command');
const { PermissionFlagsBits } = require('discord.js');
const BombSweeper = require('bombsweeper.js'); const BombSweeper = require('bombsweeper.js');
const moment = require('moment'); const moment = require('moment');
require('moment-duration-format'); require('moment-duration-format');
@@ -15,6 +16,7 @@ module.exports = class MinesweeperCommand extends Command {
group: 'games-sp', group: 'games-sp',
memberName: 'minesweeper', memberName: 'minesweeper',
description: 'Play a game of Minesweeper.', description: 'Play a game of Minesweeper.',
clientPermissions: [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.ReadMessageHistory],
game: true, game: true,
args: [ args: [
{ {
@@ -37,9 +39,10 @@ module.exports = class MinesweeperCommand extends Command {
const flagged = []; const flagged = [];
const startTime = new Date(); const startTime = new Date();
let cheatMode = false; let cheatMode = false;
const gameMsg = await msg.say('Loading...');
while (win === null) { while (win === null) {
const currentTime = moment.duration(new Date() - startTime).format('mm:ss'); const currentTime = moment.duration(new Date() - startTime).format('mm:ss');
await msg.say(stripIndents` await gameMsg.edit(stripIndents`
${msg.author}, what coordinates do you pick (ex. 4,5)? Type \`end\` to forfeit. ${msg.author}, what coordinates do you pick (ex. 4,5)? Type \`end\` to forfeit.
Type \`flag <coordinates>\` to flag a spot as a bomb. To remove a flag, run it again. Type \`flag <coordinates>\` to flag a spot as a bomb. To remove a flag, run it again.
You can also use ranges to mark multiple spots (ex. 4-7,5 or 7,4-5). You can also use ranges to mark multiple spots (ex. 4-7,5 or 7,4-5).
@@ -66,17 +69,22 @@ module.exports = class MinesweeperCommand extends Command {
time: 120000 time: 120000
}); });
if (!turn.size) { if (!turn.size) {
await msg.say('Sorry, time is up!'); await msg.say('Sorry, time is up!')
.then(helpMsg => setTimeout(() => helpMsg.delete().catch(() => null), 5000));
break; break;
} }
const choice = turn.first().content; const choiceMsg = turn.first();
const choice = choiceMsg.content;
if (choice.toLowerCase() === 'end') { if (choice.toLowerCase() === 'end') {
choiceMsg.delete().catch(() => null);
win = false; win = false;
break; break;
} }
if (choice.toLowerCase() === 'xyzzy') { if (choice.toLowerCase() === 'xyzzy') {
choiceMsg.delete().catch(() => null);
cheatMode = true; cheatMode = true;
await msg.say('Cheat mode is now active. No high score will be saved.'); await msg.say('Cheat mode is now active. No high score will be saved.')
.then(helpMsg => setTimeout(() => helpMsg.delete().catch(() => null), 5000));
continue; continue;
} }
const coordPicked = choice.match(turnRegex); const coordPicked = choice.match(turnRegex);
@@ -86,26 +94,33 @@ module.exports = class MinesweeperCommand extends Command {
const yRange = coordPicked[5] ? Math.abs(Number.parseInt(coordPicked[5], 10)) : null; const yRange = coordPicked[5] ? Math.abs(Number.parseInt(coordPicked[5], 10)) : null;
const flag = Boolean(coordPicked[1]); const flag = Boolean(coordPicked[1]);
if (xRange && yRange) { if (xRange && yRange) {
await msg.say('You cannot have both an X and Y range.'); choiceMsg.delete().catch(() => null);
await msg.say('You cannot have both an X and Y range.')
.then(helpMsg => setTimeout(() => helpMsg.delete().catch(() => null), 5000));
continue; continue;
} }
if ((yRange && flag) || (xRange && flag)) { if ((yRange && flag) || (xRange && flag)) {
await msg.say('You cannot flag a range.'); choiceMsg.delete().catch(() => null);
await msg.say('You cannot flag a range.')
.then(helpMsg => setTimeout(() => helpMsg.delete().catch(() => null), 5000));
continue; continue;
} }
if (xRange) { if (xRange) {
choiceMsg.delete().catch(() => null);
for (let i = x; i <= xRange; i++) { for (let i = x; i <= xRange; i++) {
const keepGoing = await this.runResult(msg, game, i, y, flag, flagged, win); const keepGoing = await this.runResult(msg, game, i, y, flag, flagged, win);
if (keepGoing === false) break; if (keepGoing === false) break;
if (keepGoing === null) continue; if (keepGoing === null) continue;
} }
} else if (yRange) { } else if (yRange) {
choiceMsg.delete().catch(() => null);
for (let i = y; i <= yRange; i++) { for (let i = y; i <= yRange; i++) {
const keepGoing = await this.runResult(msg, game, x, i, flag, flagged, win); const keepGoing = await this.runResult(msg, game, x, i, flag, flagged, win);
if (keepGoing === false) break; if (keepGoing === false) break;
if (keepGoing === null) continue; if (keepGoing === null) continue;
} }
} else { } else {
choiceMsg.delete().catch(() => null);
const keepGoing = await this.runResult(msg, game, x, y, flag, flagged, win); const keepGoing = await this.runResult(msg, game, x, y, flag, flagged, win);
if (keepGoing === false) break; if (keepGoing === false) break;
if (keepGoing === null) continue; if (keepGoing === null) continue;
@@ -121,10 +136,10 @@ module.exports = class MinesweeperCommand extends Command {
await this.client.redis.set(`minesweeper-${size}`, newScore); await this.client.redis.set(`minesweeper-${size}`, newScore);
await this.client.redis.set(`minesweeper-${size}-user`, msg.author.id); await this.client.redis.set(`minesweeper-${size}-user`, msg.author.id);
} }
if (win === null) return msg.say('Game ended due to inactivity.'); if (win === null) return gameMsg.edit('Game ended due to inactivity.');
const newDisplayTime = moment.duration(newScore).format('mm:ss'); const newDisplayTime = moment.duration(newScore).format('mm:ss');
const displayTime = moment.duration(highScore).format('mm:ss'); const displayTime = moment.duration(highScore).format('mm:ss');
return msg.say(stripIndents` return gameMsg.edit(stripIndents`
${win ? `Nice job! You win! (Took ${newDisplayTime})` : 'Sorry... You lose.'} ${win ? `Nice job! You win! (Took ${newDisplayTime})` : 'Sorry... You lose.'}
${scoreBeat ? `**New High Score!** Old:` : `High Score:`} ${displayTime} (Held by ${user}) ${scoreBeat ? `**New High Score!** Old:` : `High Score:`} ${displayTime} (Held by ${user})
@@ -141,10 +156,13 @@ module.exports = class MinesweeperCommand extends Command {
} }
} else { } else {
if (flagged.includes(`${x - 1},${y - 1}`)) { if (flagged.includes(`${x - 1},${y - 1}`)) {
await msg.say(`Are you sure you want to check (${x}, ${y})? You have it flagged.`); const checkMsg = await msg.say(`Are you sure you want to check (${x}, ${y})? You have it flagged.`);
const verification = await verify(msg.channel, msg.author); const verification = await verify(msg.channel, msg.author);
if (!verification) { if (!verification) {
await msg.say('Okay, the spot will remain unchecked.'); verification.delete().catch(() => null);
checkMsg.delete().catch(() => null);
await msg.say('Okay, the spot will remain unchecked.')
.then(helpMsg => setTimeout(() => helpMsg.delete().catch(() => null), 5000));
return null; return null;
} }
} }
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = class FirstMessageCommand extends Command {
} }
async run(msg, { channel }) { async run(msg, { channel }) {
if (msg.guild && !channel.permissionsFor(this.client.user).has('READ_MESSAGE_HISTORY')) { if (msg.guild && !channel.permissionsFor(this.client.user).has(PermissionFlagsBits.ReadMessageHistory)) {
return msg.reply(`Sorry, I don't have permission to read ${channel}...`); return msg.reply(`Sorry, I don't have permission to read ${channel}...`);
} }
const messages = await channel.messages.fetch({ after: 1, limit: 1 }); const messages = await channel.messages.fetch({ after: 1, limit: 1 });
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class PruneCommand extends Command {
usages: 2, usages: 2,
duration: 10 duration: 10
}, },
clientPermissions: ['READ_MESSAGE_HISTORY', PermissionFlagsBits.ManageMessages], clientPermissions: [PermissionFlagsBits.ReadMessageHistory, PermissionFlagsBits.ManageMessages],
userPermissions: [PermissionFlagsBits.ManageMessages], userPermissions: [PermissionFlagsBits.ManageMessages],
args: [ args: [
{ {
+2 -2
View File
@@ -292,7 +292,7 @@ module.exports = class Util {
if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has(PermissionFlagsBits.UseExternalEmojis))) { if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has(PermissionFlagsBits.UseExternalEmojis))) {
emoji = fallbackEmoji; emoji = fallbackEmoji;
} }
if (dm || msg.channel.permissionsFor(user).has([PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'])) { if (dm || msg.channel.permissionsFor(user).has([PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory])) {
try { try {
await msg.react(emoji); await msg.react(emoji);
} catch { } catch {
@@ -315,7 +315,7 @@ module.exports = class Util {
}); });
if (!verify.size) return 0; if (!verify.size) return 0;
const choice = verify.first().content.toLowerCase(); const choice = verify.first().content.toLowerCase();
if (yes.includes(choice) || extraYes.includes(choice)) return true; if (yes.includes(choice) || extraYes.includes(choice)) return verify.first();
if (no.includes(choice) || extraNo.includes(choice)) return false; if (no.includes(choice) || extraNo.includes(choice)) return false;
return false; return false;
} }