guild specific banking data
This commit is contained in:
6 files changed
+289
-167
No files matched your search
+69
-71
@@ -67,46 +67,68 @@ module.exports = {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send(`You are not allowed to use the bot in this channel.`);
|
||||
}
|
||||
|
||||
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking);
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
userID: targetUserID,
|
||||
guidls: {
|
||||
[guildID]: {
|
||||
account: {
|
||||
balance: GuildDB.startingBalance,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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] });
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0].name == "add") {
|
||||
// add money to user
|
||||
|
||||
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking);
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
account: {
|
||||
userID: targetUserID,
|
||||
balance: GuildDB.startingBalance + args[0].options[1].value,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(banking, 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 {
|
||||
let newBalance = banking.account.balance + args[0].options[1].value;
|
||||
|
||||
client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newBalance}}, 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")
|
||||
let newBalance = banking.guilds[guildDB.serverID].account.balance + args[0].options[1].value;
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
}
|
||||
client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, 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] });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let successEmbed = new MessageEmbed()
|
||||
.setDescription(`Successfully added $${args[0].options[1].value.toFixed(2)} to <@${targetUserID}>'s balance`)
|
||||
@@ -115,44 +137,20 @@ module.exports = {
|
||||
return interaction.send({ embeds: [successEmbed] });
|
||||
} else if (args[0].name == "remove") {
|
||||
// remove money from user
|
||||
|
||||
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking);
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
account: {
|
||||
userID: targetUserID,
|
||||
balance: GuildDB.startingBalance - args[0].options[1].value,
|
||||
cash: 0.00,
|
||||
}
|
||||
|
||||
let newBalance = 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`]:newBalance}}, 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] });
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(banking, 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 {
|
||||
let newBalance = banking.account.balance - args[0].options[1].value;
|
||||
});
|
||||
|
||||
client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newBalance}}, 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] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let successEmbed = new MessageEmbed()
|
||||
.setDescription(`Successfully removed $${args[0].options[1].value.toFixed(2)} from <@${targetUserID}>'s balance`)
|
||||
.setColor('GREEN');
|
||||
|
||||
Reference in new issue
Block a user