Permalink
Browse files

Fix for Adopt command

The `getResponse` method didn't properly account for the author of the response needed might not be the initial author of the message. I added an optional userId parameter that if provided will be used to verify the response is from the user necessary.
  • Loading branch information...
Alcha committed Oct 6, 2018
1 parent 84d1a54 commit 78c7298b6a3475fb85c170fc09ca03721564c43f
Showing with 12 additions and 5 deletions.
  1. +11 −4 cmds/BaseCmd.js
  2. +1 −1 cmds/features/Adopt.js
@@ -55,6 +55,7 @@ module.exports = class BaseCmd extends Command {
*
* @param {CommandMessage} msg The message object used to retrieve responses
* @param {Function} verify The function used to verify the user input is valid
* @param {string} [userId] The id of the user you want a response from
*
* @returns {Promise<String>|Promise<undefined>} The response or undefined via a Promise
*
@@ -66,11 +67,17 @@ module.exports = class BaseCmd extends Command {
* getResponse(msg, val => { return val.toLocaleLowerCase() = 'help' })
* .then(res => console.log('User requires help.'))
*/
static getResponse (msg, verify) {
static getResponse (msg, verify, userId = undefined) {
return new Promise((resolve, reject) => {
let coll = msg.channel.createMessageCollector(m =>
m.member.id === msg.author.id && m.channel.id === msg.channel.id, { time: 60000 }
)
if (userId === undefined) {
var coll = msg.channel.createMessageCollector(m =>
m.author.id === msg.author.id && m.channel.id === msg.channel.id, { time: 60000 }
)
} else {
coll = msg.channel.createMessageCollector(m =>
m.member.id === userId && m.channel.id === msg.channel.id, { time: 60000 }
)
}

coll.on('collect', (m, c) => {
if (verify(m.content)) {
@@ -48,7 +48,7 @@ const adoptUser = async (msg, adoptee) => {
else {
await msg.channel.send(`<@${adoptee}>, do you wish to be adopted by <@${adopter}>? (Yes/No)`)
try {
let res = await Command.getResponse(msg, val => val.toLowerCase() === 'yes' || val.toLowerCase() === 'no')
let res = await Command.getResponse(msg, val => val.toLowerCase() === 'yes' || val.toLowerCase() === 'no', adoptee)
if (res === undefined) return msg.reply('Sorry, looks like you won\'t be getting a response this time around :cry:')
else if (res.toLowerCase() === 'yes') {
// WOOT

0 comments on commit 78c7298

Please sign in to comment.