diff --git a/commands/bank.js b/commands/bank.js index e0738ae..6aa86ac 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -131,7 +131,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); @@ -274,7 +274,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); @@ -340,7 +340,7 @@ module.exports = { let targetUserInventory = await client.dbo.collection("inventories").findOne({"inventory.userID":targetUserID}).then(inventory => inventory); if (!targetUserInventory) { - targetUserBanking = { + targetUserInventory = { userID: targetUserID, guilds: { [GuildDB.serverID]: { @@ -374,7 +374,7 @@ module.exports = { if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } - const newTargetCash = targetUserInventory.inventory.guilds[GuildDB.serverID].items[0].cash + args[0].options[1].value; + let newTargetCash = targetUserInventory.guilds[GuildDB.serverID].items[0].cash + args[0].options[1].value; client.dbo.collection("inventories").updateOne( { "inventory.userID": targetUserID, @@ -397,7 +397,7 @@ module.exports = { [GuildDB.serverID]: { account: { balance: GuildDB.startingBalance, - cash: 0.00, + cash: newTargetCash, } } } @@ -405,7 +405,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, newTargetCash); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); @@ -415,10 +415,6 @@ module.exports = { const success = addBank(targetUserBanking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); } - - client.dbo.collection("banks").updateOne({"banking.userID": targetUserID}, {$set: {[`banking.guilds.${GuildDB.serverID}.account.cash`]: newTargetCash}}, function(err, res) { - if (err) return client.sendInternalError(interaction, err); - }); const successEmbed = new EmbedBuilder() .setTitle('Success') diff --git a/commands/fine.js b/commands/fine.js index 0c350a2..6bbe2b5 100644 --- a/commands/fine.js +++ b/commands/fine.js @@ -75,7 +75,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); diff --git a/commands/invoice.js b/commands/invoice.js index 21d537b..c32530c 100644 --- a/commands/invoice.js +++ b/commands/invoice.js @@ -211,9 +211,9 @@ module.exports = { } } - // Register inventory for user + // Register bank for user let newBank = new Bank(); - newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); @@ -284,7 +284,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(invoice.from, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(invoice.from, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); diff --git a/commands/money.js b/commands/money.js index e7bef09..1b3aa9f 100644 --- a/commands/money.js +++ b/commands/money.js @@ -94,7 +94,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); @@ -106,7 +106,7 @@ module.exports = { if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); } - const newBalance = args[0].name == 'add' + let newBalance = args[0].name == 'add' ? banking.guilds[GuildDB.serverID].account.balance + args[0].options[1].value : banking.guilds[GuildDB.serverID].account.balance - args[0].options[1].value; diff --git a/commands/work.js b/commands/work.js index 81c1e8a..98f0861 100644 --- a/commands/work.js +++ b/commands/work.js @@ -90,7 +90,7 @@ module.exports = { // Register inventory for user let newBank = new Bank(); - newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance); + newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0); newBank.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); diff --git a/config/config.js b/config/config.js index fb799ad..00c0fc0 100644 --- a/config/config.js +++ b/config/config.js @@ -2,7 +2,7 @@ require('dotenv').config(); module.exports = { Dev: "PROD.", - Version: "13.1.1", // (major).(feature).(revision/bug/refactoring) + Version: "13.1.2", // (major).(feature).(revision/bug/refactoring) Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot DefaultPrefix: "?", ServerID: "955668596745461830", diff --git a/structures/bank.js b/structures/bank.js index 1abbb56..357e4a9 100644 --- a/structures/bank.js +++ b/structures/bank.js @@ -7,13 +7,13 @@ let bankSchema = mongoose.Schema({ } }); -bankSchema.methods.createBank = function (userID, guildID, startingBalance) { +bankSchema.methods.createBank = function (userID, guildID, startingBalance, cash) { this.banking.userID = userID; this.banking.guilds = {}; this.banking.guilds[guildID] = { account: { balance: startingBalance, - cash: 0.00, + cash: cash, } };; };