From 9927d79c480eb3479b843ac4bda830afd3ba4f25 Mon Sep 17 00:00:00 2001 From: maisans-maid <56829176+maisans-maid@users.noreply.github.com> Date: Fri, 15 Jan 2021 14:39:46 +0800 Subject: [PATCH] (fix): fix bug on transfer command --- commands/social/transfer.js | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/commands/social/transfer.js b/commands/social/transfer.js index 0a5484c7..9b95aef8 100644 --- a/commands/social/transfer.js +++ b/commands/social/transfer.js @@ -13,43 +13,41 @@ module.exports = { run: (client, message, [ friend='', amount='' ]) => profile.findById(message.author.id, async (err, doc) => { const fr = friend; - friend = await message.guild.members.fetch(friend.match(/\d{17,19}/)||[][0]||' ') + friend = await message.guild.members.fetch(friend.match(/\d{17,19}/)?.[0]||' ') .catch(()=>{}); - amount = Math.round(amount.split(',').join('')); + amount = Math.round(amount.split(',').join('')) || 'Nothing'; if (err){ - return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`); + return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: \`${err.name}\``); } else if (!doc || doc.data.economy.wallet === null){ - return message.channel.send(`\\❌ **${message.member.displayName}**, You don't have a **wallet** yet!\nTo create one, type \`${client.prefix}register\`.`); + return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a **wallet** yet!\nTo create one, type \`${client.prefix}register\`.`); } else if (doc.data.economy.bank === null){ - return message.channel.send(`\\❌ **${message.member.displayName}**, You don't have a **bank** yet!\nTo create one, type \`${client.prefix}bank\`.`); + return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a **bank** yet!\nTo create one, type \`${client.prefix}bank\`.`); + } else if (!fr){ + return message.channel.send(`\\❌ **${message.author.tag}**, please specify the user you want to give credits to!`); } else if (!friend){ - return message.channel.send(`\\❌ **${message.member.displayName}**, I couldn't find ${fr} in this server!`); - } else if (!amount){ - return message.channel.send(`\\❌ **${message.member.displayName}**, **${amount}** is not a valid amount!`); + return message.channel.send(`\\❌ **${message.author.tag}**, I couldn't find \`${fr}\` in this server!`); + } else if (!amount || amount === 'Nothing'){ + return message.channel.send(`\\❌ **${message.author.tag}**, **${amount}** is not a valid amount!`); } else if (amount < 100 || amount > 20000){ - return message.channel.send(`\\❌ **${message.member.displayName}**, only valid amount to transfer is between **100** and **20,000**!`); + return message.channel.send(`\\❌ **${message.author.tag}**, only valid amount to transfer is between **100** and **20,000**!`); } else if (Math.ceil(amount * 1.1) > doc.data.economy.bank){ - return message.channel.send(`\\❌ **${message.member.displayName}**, Insuffecient credits! You only have **${text.commatize(doc.data.economy.bank)}** in your bank! (10% fee applies)`); + return message.channel.send(`\\❌ **${message.author.tag}**, Insuffecient credits! You only have **${text.commatize(doc.data.economy.bank)}** in your bank! (10% fee applies)`); }; - const friendName = friend.displayName; - friend = await profile.findById(friend.id).catch(()=>{}); + const friendName = friend.user.tag; + friend = await profile.findById(friend.id).catch(err => err); - if (!(friend instanceof profile)){ - return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`); - }; - - if (!friend || friend.economy.data.bank === null){ - return message.channel.send(`\\❌ **${message.member.displayName}**, **${friend.displayName}** doesn't have a bank yet! He is not yet eligible to receive credits!`); + if (!friend || friend.data.economy.bank === null){ + return message.channel.send(`\\❌ **${message.author.tag}**, **${friendName}** doesn't have a bank yet! He is not yet eligible to receive credits!`); }; doc.data.economy.bank = doc.data.economy.bank - Math.floor(amount * 1.1); friend.data.economy.bank = friend.data.economy.bank + amount; return Promise.all([ doc.save(), friend.save() ]) - .then(()=> message.channel.send(`\\✔️ **${message.member.displayName}**, successfully transferred **${amount}**`)) - .catch(()=> message.channel.send(`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`)); + .then(()=> message.channel.send(`\\✔️ **${message.author.tag}**, successfully transferred **${amount}** to **${friendName}**`)) + .catch(err => message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: \`${err.name}\``)); }) };