diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-05 19:18:38 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-05 19:18:38 +0100 |
commit | a25d1acd1d702287b6ca095a4079cf3f898cbe89 (patch) | |
tree | 552f6ccc15a082f9d662e7ff58bf2f954c0451e5 /economy.js | |
download | furrybot-discord-a25d1acd1d702287b6ca095a4079cf3f898cbe89.tar.xz |
Initial commit
Diffstat (limited to 'economy.js')
-rw-r--r-- | economy.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/economy.js b/economy.js new file mode 100644 index 0000000..22d93bb --- /dev/null +++ b/economy.js @@ -0,0 +1,54 @@ +const google_images = require("free-google-images") +const common = require("./common.js") +let moneyStorage = common.storageLoad("money") || {} + +const getMoney = user => moneyStorage[user] || 100 +const setMoney = (user, money) => { + moneyStorage[user] = money + common.storageSave("money", moneyStorage) +} +const addMoney = (user, add) => setMoney(user, getMoney(user) + add) +const takeMoney = (user, remove) => { + const money = getMoney(user) - remove + + if (money < 0) + return false + + setMoney(user, money) + return true +} + +module.exports = { + money: { + func: (msg, [targetPing]) => { + const user = msg.author.id + const target = targetPing ? common.getPing(msg, targetPing, true) : user + + if (target) + msg.reply((user == target ? "You have " : `<@!${target}> has `) + getMoney(target) + ":b:.") + } + }, + pay: { + func: (msg, [targetPing, amountStr]) => { + const user = msg.author.id + const target = common.getPing(msg, targetPing, false) + + if (target) { + const amount = parseInt(amountStr) + + if (amount && amount > 0) { + if (takeMoney(user, amount)) { + addMoney(target, amount) + + google_images.searchRandom("free+bobux") + .then(result => msg.channel.send(`<@!${target}>: <@!${user}> has payed you ${amount}:b:.\n${result.image.url}`)) + } else { + msg.reply("You don't have enough money.") + } + } else { + msg.reply("Invalid amount of money :stuck_out_tongue:") + } + } + } + } +} |