]> git.lizzy.rs Git - furrybot-discord.git/blob - economy.js
Add bad apple
[furrybot-discord.git] / economy.js
1 const google_images = require("free-google-images")
2 const common = require("./common.js")
3 let moneyStorage = common.storageLoad("money") || {}
4
5 const getMoney = user => moneyStorage[user] || 100
6 const setMoney = (user, money) => {
7         moneyStorage[user] = money
8         common.storageSave("money", moneyStorage)
9 }
10 const addMoney = (user, add) => setMoney(user, getMoney(user) + add)
11 const takeMoney = (user, remove) => {
12         const money = getMoney(user) - remove
13
14         if (money < 0)
15                 return false
16
17         setMoney(user, money)
18         return true
19 }
20
21 module.exports = {
22         money: {
23                 func: (msg, [targetPing]) => {
24                         const user = msg.author.id
25                         const target = targetPing ? common.getPing(msg, targetPing, true) : user
26
27                         if (target)
28                                 msg.reply((user == target ? "You have " : `<@!${target}> has `) + getMoney(target) + ":b:.")
29                 }
30         },
31         pay: {
32                 func: (msg, [targetPing, amountStr]) => {
33                         const user = msg.author.id
34                         const target = common.getPing(msg, targetPing, false)
35
36                         if (target) {
37                                 const amount = parseInt(amountStr)
38
39                                 if (amount && amount > 0) {
40                                         if (takeMoney(user, amount)) {
41                                                 addMoney(target, amount)
42
43                                                 google_images.searchRandom("free+bobux")
44                                                         .then(result => msg.channel.send(`<@!${target}>: <@!${user}> has payed you ${amount}:b:.\n${result.image.url}`))
45                                         } else {
46                                                 msg.reply("You don't have enough money.")
47                                         }
48                                 } else {
49                                         msg.reply("Invalid amount of money :stuck_out_tongue:")
50                                 }
51                         }
52                 }
53         }
54 }