guild specific banking data
This commit is contained in:
6 files changed
+289
-167
No files matched your search
+50
-29
@@ -56,42 +56,63 @@ module.exports = {
|
||||
}
|
||||
|
||||
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking);
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking);
|
||||
|
||||
if (!targetUserBanking) {
|
||||
targetUserBanking = {
|
||||
account: {
|
||||
userID: targetUserID,
|
||||
balance: (GuildDB.startingBalance - args[0].options[1].value),
|
||||
cash: 0.00,
|
||||
if (!banking) {
|
||||
banking = {
|
||||
userID: targetUserID,
|
||||
guidls: {
|
||||
[guildID]: {
|
||||
account: {
|
||||
balance: GuildDB.startingBalance,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(targetUserBanking, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
const embed = new MessageEmbed()
|
||||
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const newTargetBalance = targetUserBanking.account.balance - args[0].options[1].value;
|
||||
// Register inventory for user
|
||||
let newBank = new Bank();
|
||||
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
|
||||
newBank.save()
|
||||
.catch(err => {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
const embed = new MessageEmbed()
|
||||
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
|
||||
} else banking = banking.banking;
|
||||
|
||||
client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newTargetBalance}}, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
const embed = new MessageEmbed()
|
||||
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
if (!client.exists(banking.guilds[guildDB.serverID])) {
|
||||
const success = addBank(banking.guilds, guildDB.serverID, targetUserID, client, guildDB.startingBalance);
|
||||
if (!success) {
|
||||
client.log(err);
|
||||
const embed = new MessageEmbed()
|
||||
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
}
|
||||
|
||||
const newTargetBalance = banking.guilds[guildDB.serverID].account.balance - args[0].options[1].value;
|
||||
|
||||
client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newTargetBalance}}, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
const embed = new MessageEmbed()
|
||||
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
|
||||
const successEmbed = new MessageEmbed()
|
||||
.setTitle('Bank Notice:')
|
||||
.setDescription(`Successfully fined <@${targetUserID}> $${args[0].options[1].value.toFixed(2)}`)
|
||||
|
||||
Reference in new issue
Block a user