12.8.3 fix internal error handling
This commit is contained in:
12 files changed
+211
-74
No files matched your search
+20
-20
@@ -133,14 +133,14 @@ module.exports = {
|
||||
let newBank = new Bank();
|
||||
newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
|
||||
newBank.save().catch(err => {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
} else banking = banking.banking;
|
||||
|
||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||
const success = addBank(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||
if (!success) return client.sendInternalError('Failed to add bank');
|
||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||
}
|
||||
|
||||
let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory);
|
||||
@@ -176,7 +176,7 @@ module.exports = {
|
||||
|
||||
if (!client.exists(inventory.guilds[GuildDB.serverID])) {
|
||||
const success = addInventory(inventory.guilds, GuildDB.serverID, interaction.member.user.id, client);
|
||||
if (!success) return client.sendInternalError('Failed to add inventory');
|
||||
if (!success) return client.sendInternalError(interaction, 'Failed to add inventory');
|
||||
}
|
||||
|
||||
if (args[0].name == 'deposit') {
|
||||
@@ -192,7 +192,7 @@ module.exports = {
|
||||
const newCash = Math.abs(banking.guilds[GuildDB.serverID].account.cash.toFixed(2) - args[0].options[0].value);
|
||||
|
||||
client.dbo.collection("banks").updateOne({"banking.userID":interaction.member.user.id},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance,[`banking.guilds.${GuildDB.serverID}.account.cash`]:newCash}}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
client.dbo.collection("inventories").updateOne(
|
||||
{
|
||||
@@ -204,7 +204,7 @@ module.exports = {
|
||||
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newCash
|
||||
}
|
||||
}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
@@ -227,7 +227,7 @@ module.exports = {
|
||||
const newCash = banking.guilds[GuildDB.serverID].account.cash + args[0].options[0].value;
|
||||
|
||||
client.dbo.collection("banks").updateOne({"banking.userID":interaction.member.user.id},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance,[`banking.guilds.${GuildDB.serverID}.account.cash`]:newCash}}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
client.dbo.collection("inventories").updateOne(
|
||||
{
|
||||
@@ -239,7 +239,7 @@ module.exports = {
|
||||
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newCash
|
||||
}
|
||||
}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
@@ -276,14 +276,14 @@ module.exports = {
|
||||
let newBank = new Bank();
|
||||
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
|
||||
newBank.save().catch(err => {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
} else targetUserBanking = targetUserBanking.banking;
|
||||
|
||||
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
|
||||
const success = addBank(targetUserBanking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||
if (!success) return client.sendInternalError('Failed to add bank');
|
||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||
}
|
||||
|
||||
// This lame line of code to get username without ping on discord
|
||||
@@ -320,7 +320,7 @@ module.exports = {
|
||||
const newCash = banking.guilds[GuildDB.serverID].account.cash - args[0].options[1].value;
|
||||
|
||||
client.dbo.collection("banks").updateOne({"banking.userID":interaction.member.user.id},{$set:{[`banking.guilds.${GuildDB.serverID}.account.cash`]:newCash}}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
client.dbo.collection("inventories").updateOne(
|
||||
@@ -333,7 +333,7 @@ module.exports = {
|
||||
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`] :newCash
|
||||
}
|
||||
}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
@@ -365,13 +365,13 @@ module.exports = {
|
||||
newInventory.createInventory(targetUserID, GuildDB.serverID);
|
||||
newInventory.inventory.guilds[GuildDB.serverID].items[0].cash = args[0].options[1].value;
|
||||
newInventory.save().catch(err => {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
} else targetUserInventory = targetUserInventory.inventory;
|
||||
|
||||
if (!client.exists(targetUserInventory.guilds[GuildDB.serverID])) {
|
||||
const success = addInventory(targetUserInventory.guilds, GuildDB.serverID, targetUserID, client);
|
||||
if (!success) return client.sendInternalError('Failed to add inventory');
|
||||
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;
|
||||
@@ -385,7 +385,7 @@ module.exports = {
|
||||
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newTargetCash
|
||||
}
|
||||
}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
let targetUserBanking = await client.dbo.collection("banks").findOne({"banking.userID": targetUserID}).then(banking => banking);
|
||||
@@ -407,17 +407,17 @@ module.exports = {
|
||||
let newBank = new Bank();
|
||||
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
|
||||
newBank.save().catch(err => {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
} else targetUserBanking = targetUserBanking.banking;
|
||||
|
||||
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
|
||||
const success = addBank(targetUserBanking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||
if (!success) return client.sendInternalError('Failed to add bank');
|
||||
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(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
@@ -441,7 +441,7 @@ module.exports = {
|
||||
const newBalance = banking.guilds[GuildDB.serverID].account.balance - args[0].options[1].value;
|
||||
|
||||
client.dbo.collection("banks").updateOne({"banking.userID":interaction.member.user.id},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance}}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
@@ -461,14 +461,14 @@ module.exports = {
|
||||
}
|
||||
|
||||
client.dbo.collection("banks").insertOne(targetUserBanking, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
} else targetUserBanking = targetUserBanking.banking;
|
||||
|
||||
const newTargetBalance = targetUserBanking.guilds[GuildDB.serverID].account.balance + args[0].options[1].value;
|
||||
|
||||
client.dbo.collection("banks").updateOne({"banking.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newTargetBalance}}, function(err, res) {
|
||||
if (err) return client.sendInternalError(err);
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
|
||||
Reference in new issue
Block a user