Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
add all flag to sell command
Browse files Browse the repository at this point in the history
  • Loading branch information
matievisthekat committed Jul 2, 2020
1 parent cfcfdc3 commit 3d1bf79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

23 changes: 14 additions & 9 deletions src/commands/Currency/sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand All @@ -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()}`
)
);
}
Expand Down

0 comments on commit 3d1bf79

Please sign in to comment.