From c31fd9151e54abce893f4ba16a812d5bd2b17735 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 26 Nov 2020 11:44:51 -0500 Subject: [PATCH] Convert all react methods to reactIfAble --- README.md | 10 ++++++---- commands/games-mp/bingo.js | 4 ++-- commands/games-mp/guesspionage.js | 4 ++-- commands/games-mp/imposter.js | 4 ++-- commands/games-mp/island.js | 4 ++-- commands/games-mp/lie-swatter.js | 4 ++-- commands/games-mp/quiz-duel.js | 4 ++-- commands/games-sp/anagramica.js | 5 +++-- package.json | 2 +- util/Util.js | 2 +- 10 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ecc4ecac..a3721956 100644 --- a/README.md +++ b/README.md @@ -81,18 +81,20 @@ don't grant that permission. - **View Channels** is required for every single command to work. - **Send Messages** is required for every single command to work. - **Manage Messages** allows Xiao to use the `prune` command. + * It also allows the `say` command to delete your message, but the command will still work without it. - **Embed Links** is required to allow commands that send embeds to work. Too many commands to list use it. - **Attach Files** is required to allow commands that send files to work. Too many commands to list use it. - **Read Message History** allows Xiao to use the `first-message` and `prune` commands. + * It is also required to allow Xiao to react to messages alongside "Add Reactions". - **Use External Emojis** allows Xiao to use custom emoji in certain commands. * While the commands benefit from it, it is not required for the commands to work. - **Add Reactions** allows Xiao to use commands that add reactions to messages in certain commands. - * While the commands benefit from it, it is not requried for the commands to work. -- **Connect** allows Xiao to connect to voice channels. This is needed for commands in the "Voice-Based" group. -- **Speak** allows Xiao to speak in voice channels. This is needed for commands in the "Voice-Based" group. + * While the commands benefit from it, it is not required for the commands to work. + * "Read Message History" is also required to allow Xiao to react. +- **Connect** allows Xiao to connect to voice channels. This is needed for commands that play audio. +- **Speak** allows Xiao to speak in voice channels. This is needed for commands that play audio. - **Use Voice Activity** is not _needed_, but is included as an extra precaution for voice commands. - ## Fun Information - 500+ commands diff --git a/commands/games-mp/bingo.js b/commands/games-mp/bingo.js index ef5b55dd..b5694c2f 100644 --- a/commands/games-mp/bingo.js +++ b/commands/games-mp/bingo.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const Collection = require('@discordjs/collection'); const { stripIndents } = require('common-tags'); -const { awaitPlayers } = require('../../util/Util'); +const { awaitPlayers, reactIfAble } = require('../../util/Util'); const nums = require('../../assets/json/bingo'); const { SUCCESS_EMOJI_ID } = process.env; const rows = Object.keys(nums); @@ -73,7 +73,7 @@ module.exports = class BingoCommand extends Command { if (!players.has(res.author.id)) return false; if (res.content.toLowerCase() === 'leave game') { players.delete(res.author.id); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); if (!players.size) return true; return false; } diff --git a/commands/games-mp/guesspionage.js b/commands/games-mp/guesspionage.js index bc2677df..5e6c3edb 100644 --- a/commands/games-mp/guesspionage.js +++ b/commands/games-mp/guesspionage.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const Collection = require('@discordjs/collection'); -const { delay, awaitPlayers } = require('../../util/Util'); +const { delay, awaitPlayers, reactIfAble } = require('../../util/Util'); const questions = require('../../assets/json/guesspionage'); const { SUCCESS_EMOJI_ID } = process.env; const guesses = ['much higher', 'higher', 'lower', 'much lower']; @@ -112,7 +112,7 @@ module.exports = class GuesspionageCommand extends Command { if (!awaitedPlayers.includes(res.author.id)) return false; if (!guesses.includes(res.content.toLowerCase())) return false; guessed.push(res.author.id); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; }; const everyoneElse = await msg.channel.awaitMessages(everyoneElseFilter, { diff --git a/commands/games-mp/imposter.js b/commands/games-mp/imposter.js index 8e1a1948..13ea77b5 100644 --- a/commands/games-mp/imposter.js +++ b/commands/games-mp/imposter.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { stripIndents, oneLine } = require('common-tags'); const Collection = require('@discordjs/collection'); -const { delay, awaitPlayers, list } = require('../../util/Util'); +const { delay, awaitPlayers, list, reactIfAble } = require('../../util/Util'); const words = require('../../assets/json/imposter'); const { SUCCESS_EMOJI_ID } = process.env; @@ -114,7 +114,7 @@ module.exports = class ImposterCommand extends Command { votes: currentVotes ? currentVotes + 1 : 1, id: ids[int - 1] }); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; } return false; diff --git a/commands/games-mp/island.js b/commands/games-mp/island.js index f38d57de..3fc2545c 100644 --- a/commands/games-mp/island.js +++ b/commands/games-mp/island.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const Collection = require('@discordjs/collection'); -const { delay, awaitPlayers } = require('../../util/Util'); +const { delay, awaitPlayers, reactIfAble } = require('../../util/Util'); const { SUCCESS_EMOJI_ID } = process.env; module.exports = class IslandCommand extends Command { @@ -71,7 +71,7 @@ module.exports = class IslandCommand extends Command { votes: currentVotes ? currentVotes + 1 : 1, id: ids[int - 1] }); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; } return false; diff --git a/commands/games-mp/lie-swatter.js b/commands/games-mp/lie-swatter.js index 4ca97860..ced28227 100644 --- a/commands/games-mp/lie-swatter.js +++ b/commands/games-mp/lie-swatter.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); const { stripIndents } = require('common-tags'); const Collection = require('@discordjs/collection'); -const { delay, awaitPlayers } = require('../../util/Util'); +const { delay, awaitPlayers, reactIfAble } = require('../../util/Util'); const { SUCCESS_EMOJI_ID } = process.env; const trueOptions = ['true', 'yes', 'the truth', 't', 'tru', 'tr', 'y', 'ye']; const falseOptions = ['false', 'lie', 'no', 'a lie', 'f', 'fals', 'fal', 'fa', 'n', 'l']; @@ -71,7 +71,7 @@ module.exports = class LieSwatterCommand extends Command { if (!awaitedPlayers.includes(res.author.id)) return false; const answer = res.content.toLowerCase(); if (trueOptions.includes(answer) || falseOptions.includes(answer)) { - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; } return false; diff --git a/commands/games-mp/quiz-duel.js b/commands/games-mp/quiz-duel.js index aeccd7b0..440dae82 100644 --- a/commands/games-mp/quiz-duel.js +++ b/commands/games-mp/quiz-duel.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); const { stripIndents } = require('common-tags'); const Collection = require('@discordjs/collection'); -const { delay, awaitPlayers, shuffle } = require('../../util/Util'); +const { delay, awaitPlayers, shuffle, reactIfAble } = require('../../util/Util'); const { SUCCESS_EMOJI_ID } = process.env; const choices = ['A', 'B', 'C', 'D']; @@ -64,7 +64,7 @@ module.exports = class QuizDuelCommand extends Command { if (!awaitedPlayers.includes(res.author.id)) return false; const answer = res.content.toUpperCase(); if (choices.includes(answer)) { - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; } return false; diff --git a/commands/games-sp/anagramica.js b/commands/games-sp/anagramica.js index dc652be5..7cc693e8 100644 --- a/commands/games-sp/anagramica.js +++ b/commands/games-sp/anagramica.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const request = require('node-superfetch'); +const { reactIfAble } = require('../../util/Util'); const scores = require('../../assets/json/anagramica'); const pool = 'abcdefghijklmnopqrstuvwxyz'.split(''); const { SUCCESS_EMOJI_ID, FAILURE_EMOJI_ID } = process.env; @@ -54,12 +55,12 @@ module.exports = class AnagramicaCommand extends Command { if (!valid.includes(res.content.toLowerCase())) { points -= score; picked.push(res.content.toLowerCase()); - res.react(FAILURE_EMOJI_ID || '❌').catch(() => null); + reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌'); return false; } points += score; picked.push(res.content.toLowerCase()); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; }; const msgs = await msg.channel.awaitMessages(filter, { diff --git a/package.json b/package.json index 3d816787..3fcfc6ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "121.3.0", + "version": "121.3.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index 9baf97e7..08169584 100644 --- a/util/Util.js +++ b/util/Util.js @@ -250,7 +250,7 @@ module.exports = class Util { if (joined.includes(res.author.id)) return false; if (res.content.toLowerCase() !== 'join game') return false; joined.push(res.author.id); - res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); + Util.reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); return true; }; const verify = await msg.channel.awaitMessages(filter, { max: max - 1, time: 60000 });