From 3d1bf79b025e884c0868eab62fce4b3e1a079e25 Mon Sep 17 00:00:00 2001 From: MatievisTheKat Date: Thu, 2 Jul 2020 15:47:37 +0200 Subject: [PATCH] add all flag to sell command --- .prettierrc | 6 ------ src/commands/Currency/sell.js | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 429b52b..0000000 --- a/.prettierrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "printWidth": 110, - "tabWidth": 2, - "useTabs": true, - "trailingComma": "none" -} diff --git a/src/commands/Currency/sell.js b/src/commands/Currency/sell.js index a485f20..918a0ce 100644 --- a/src/commands/Currency/sell.js +++ b/src/commands/Currency/sell.js @@ -7,7 +7,8 @@ module.exports = class Sell extends Command { category: "Currency", description: "Sell some of your hard earned items", usage: "{item ID}", - examples: ["dog", "ultrachicken"], + flags: ["all"], + examples: ["dog", "ultrachicken --all"], currency: true }); } @@ -20,28 +21,32 @@ module.exports = class Sell extends Command { return msg.client.errors.custom( msg, msg.channel, - "You currently do not won any items!" + "You currently do not own any items!" ); - const item = data.inv.find( - (i) => i.name.toLowerCase().replace(/ +/gi, "") === args[0] + const items = data.inv.filter( + (i) => i.name.toLowerCase().replace(/ +/gi, "") === args[0].toLowerCase() ); - if (!item) + if (!items || !items[0]) return msg.client.errors.custom( msg, msg.channel, "You do not own that item or it is not a valid item ID!" ); - data.inv.splice(data.inv.indexOf(item), 1); + if (flags.all) for(const item of items) data.inv.splice(data.inv.indexOf(item), 1); + else data.inv.splice(data.inv.indexOf(items[0]), 1); + + const price = flags.all ? items.reduce((p,c) => p += c.price, 0) : items[0].price; + await data.save(); - await msg.author.currency.add(item.price); + await msg.author.currency.add(price); msg.channel.send( msg.success( - `You sold one **${item.name}** for ${ + `You sold ${flags.all ? items.length : "one"} **${args[0].toLowerCase()}** for ${ msg.client.emoji.coin - }${item.price.toLocaleString()}` + }${price.toLocaleString()}` ) ); }