From 88a4b0608c52703af47e0bbd3721526ffe5059d6 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 12 Apr 2024 15:05:04 -0400 Subject: [PATCH] Edit message in minesweeper --- commands/games-mp/apples-to-apples.js | 2 +- commands/games-mp/cards-against-humanity.js | 2 +- commands/games-mp/imposter.js | 2 +- commands/games-sp/minesweeper.js | 38 +++++++++++++++------ commands/info/first-message.js | 2 +- commands/other/prune.js | 2 +- util/Util.js | 4 +-- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/commands/games-mp/apples-to-apples.js b/commands/games-mp/apples-to-apples.js index 4686d893..939b0154 100644 --- a/commands/games-mp/apples-to-apples.js +++ b/commands/games-mp/apples-to-apples.js @@ -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.', guildOnly: true, game: true, - clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], + clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory], credit: [ { name: 'Mattel', diff --git a/commands/games-mp/cards-against-humanity.js b/commands/games-mp/cards-against-humanity.js index 9c27116e..2a3cc453 100644 --- a/commands/games-mp/cards-against-humanity.js +++ b/commands/games-mp/cards-against-humanity.js @@ -16,7 +16,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { guildOnly: true, nsfw: true, game: true, - clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], + clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory], credit: [ { name: 'Cards Against Humanity', diff --git a/commands/games-mp/imposter.js b/commands/games-mp/imposter.js index 049e3f48..c097a71b 100644 --- a/commands/games-mp/imposter.js +++ b/commands/games-mp/imposter.js @@ -16,7 +16,7 @@ module.exports = class ImposterCommand extends Command { description: 'Who is the imposter among us?', guildOnly: true, game: true, - clientPermissions: [PermissionFlagsBits.AddReactions, 'READ_MESSAGE_HISTORY'], + clientPermissions: [PermissionFlagsBits.AddReactions, PermissionFlagsBits.ReadMessageHistory], args: [ { key: 'playersCount', diff --git a/commands/games-sp/minesweeper.js b/commands/games-sp/minesweeper.js index db662e52..f21f6558 100644 --- a/commands/games-sp/minesweeper.js +++ b/commands/games-sp/minesweeper.js @@ -1,4 +1,5 @@ const Command = require('../../framework/Command'); +const { PermissionFlagsBits } = require('discord.js'); const BombSweeper = require('bombsweeper.js'); const moment = require('moment'); require('moment-duration-format'); @@ -15,6 +16,7 @@ module.exports = class MinesweeperCommand extends Command { group: 'games-sp', memberName: 'minesweeper', description: 'Play a game of Minesweeper.', + clientPermissions: [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.ReadMessageHistory], game: true, args: [ { @@ -37,9 +39,10 @@ module.exports = class MinesweeperCommand extends Command { const flagged = []; const startTime = new Date(); let cheatMode = false; + const gameMsg = await msg.say('Loading...'); while (win === null) { 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. Type \`flag \` 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). @@ -66,17 +69,22 @@ module.exports = class MinesweeperCommand extends Command { time: 120000 }); 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; } - const choice = turn.first().content; + const choiceMsg = turn.first(); + const choice = choiceMsg.content; if (choice.toLowerCase() === 'end') { + choiceMsg.delete().catch(() => null); win = false; break; } if (choice.toLowerCase() === 'xyzzy') { + choiceMsg.delete().catch(() => null); 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; } 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 flag = Boolean(coordPicked[1]); 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; } 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; } if (xRange) { + choiceMsg.delete().catch(() => null); for (let i = x; i <= xRange; i++) { const keepGoing = await this.runResult(msg, game, i, y, flag, flagged, win); if (keepGoing === false) break; if (keepGoing === null) continue; } } else if (yRange) { + choiceMsg.delete().catch(() => null); for (let i = y; i <= yRange; i++) { const keepGoing = await this.runResult(msg, game, x, i, flag, flagged, win); if (keepGoing === false) break; if (keepGoing === null) continue; } } else { + choiceMsg.delete().catch(() => null); const keepGoing = await this.runResult(msg, game, x, y, flag, flagged, win); if (keepGoing === false) break; 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}-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 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.'} ${scoreBeat ? `**New High Score!** Old:` : `High Score:`} ${displayTime} (Held by ${user}) @@ -141,10 +156,13 @@ module.exports = class MinesweeperCommand extends Command { } } else { 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); 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; } } diff --git a/commands/info/first-message.js b/commands/info/first-message.js index e8ccd0dc..d4ee2175 100644 --- a/commands/info/first-message.js +++ b/commands/info/first-message.js @@ -21,7 +21,7 @@ module.exports = class FirstMessageCommand extends Command { } 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}...`); } const messages = await channel.messages.fetch({ after: 1, limit: 1 }); diff --git a/commands/other/prune.js b/commands/other/prune.js index 506dc496..35fe55cf 100644 --- a/commands/other/prune.js +++ b/commands/other/prune.js @@ -14,7 +14,7 @@ module.exports = class PruneCommand extends Command { usages: 2, duration: 10 }, - clientPermissions: ['READ_MESSAGE_HISTORY', PermissionFlagsBits.ManageMessages], + clientPermissions: [PermissionFlagsBits.ReadMessageHistory, PermissionFlagsBits.ManageMessages], userPermissions: [PermissionFlagsBits.ManageMessages], args: [ { diff --git a/util/Util.js b/util/Util.js index e07ccce9..4cc7e86c 100644 --- a/util/Util.js +++ b/util/Util.js @@ -292,7 +292,7 @@ module.exports = class Util { if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has(PermissionFlagsBits.UseExternalEmojis))) { 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 { await msg.react(emoji); } catch { @@ -315,7 +315,7 @@ module.exports = class Util { }); if (!verify.size) return 0; 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; return false; }