v12.7.8 clean internal error handling

This commit is contained in:
SowinskiBraeden committed 2022-10-12 17:30:27 -07:00
1 parent e4a3000a15
commit ded3831fb1
11 files changed
+154 -510

No files matched your search

+71 -191
View File
@@ -132,30 +132,15 @@ module.exports = {
// Register inventory for user
let newBank = new Bank();
newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
newBank.save()
.catch(err => {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
newBank.save().catch(err => {
if (err) return client.sendInternalError(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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (!success) return client.sendInternalError('Failed to add bank');
}
let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory);
@@ -184,29 +169,14 @@ module.exports = {
// Register inventory for user
let newInventory = new Inventory();
newInventory.createInventory(interaction.member.user.id, GuildDB.serverID);
newInventory.save()
.catch(err => {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
newInventory.save().catch(err => {
if (err) return client.sendInternalError(err)
});
} else inventory = inventory.inventory;
if (!client.exists(inventory.guilds[GuildDB.serverID])) {
const success = addInventory(inventory.guilds, GuildDB.serverID, interaction.member.user.id, client);
if (!success) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (!success) return client.sendInternalError('Failed to add inventory');
}
if (args[0].name == 'deposit') {
@@ -222,25 +192,19 @@ 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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, [`inventory.guilds.${GuildDB.serverID}.items.type`]:"wallet"},
{$set:{[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]:newCash}}, function(err, res) {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
client.dbo.collection("inventories").updateOne(
{
"inventory.userID": interaction.member.user.id,
[`inventory.guilds.${GuildDB.serverID}.items.type`]: "wallet"
},
{
$set: {
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newCash
}
}, function(err, res) {
if (err) return client.sendInternalError(err);
});
const successEmbed = new EmbedBuilder()
@@ -263,25 +227,19 @@ 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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, [`inventory.guilds.${GuildDB.serverID}.items.type`]:"wallet"},
{$set:{[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]:newCash}}, function(err, res) {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
client.dbo.collection("inventories").updateOne(
{
"inventory.userID": interaction.member.user.id,
[`inventory.guilds.${GuildDB.serverID}.items.type`]: "wallet"
},
{
$set: {
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newCash
}
}, function(err, res) {
if (err) return client.sendInternalError(err);
});
const successEmbed = new EmbedBuilder()
@@ -317,30 +275,15 @@ module.exports = {
// Register inventory for user
let newBank = new Bank();
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
newBank.save()
.catch(err => {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
newBank.save().catch(err => {
if (err) return client.sendInternalError(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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (!success) return client.sendInternalError('Failed to add bank');
}
// This lame line of code to get username without ping on discord
@@ -377,26 +320,20 @@ 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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, [`inventory.guilds.${GuildDB.serverID}.items.type`]:"wallet"},
{$set:{[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]:newCash}}, function(err, res) {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
client.dbo.collection("inventories").updateOne(
{
"inventory.userID": interaction.member.user.id,
[`inventory.guilds.${GuildDB.serverID}.items.type`]: "wallet"
},
{
$set: {
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`] :newCash
}
}, function(err, res) {
if (err) return client.sendInternalError(err);
});
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
@@ -427,42 +364,28 @@ module.exports = {
let newInventory = new Inventory();
newInventory.createInventory(targetUserID, GuildDB.serverID);
newInventory.inventory.guilds[GuildDB.serverID].items[0].cash = args[0].options[1].value;
newInventory.save()
.catch(err => {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
newInventory.save().catch(err => {
if (err) return client.sendInternalError(err);
});
} else targetUserInventory = targetUserInventory.inventory;
if (!client.exists(targetUserInventory.guilds[GuildDB.serverID])) {
const success = addInventory(targetUserInventory.guilds, GuildDB.serverID, targetUserID, client);
if (!success) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (!success) return client.sendInternalError('Failed to add inventory');
}
const newTargetCash = targetUserInventory.inventory.guilds[GuildDB.serverID].items[0].cash + args[0].options[1].value;
client.dbo.collection("inventories").updateOne({"inventory.userID":targetUserID, [`inventory.guilds.${GuildDB.serverID}.items.type`]:"wallet"},
{$set:{[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]:newTargetCash}}, function(err, res) {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
client.dbo.collection("inventories").updateOne(
{
"inventory.userID": targetUserID,
[`inventory.guilds.${GuildDB.serverID}.items.type`]: "wallet"
},
{
$set: {
[`inventory.guilds.${GuildDB.serverID}.items.$.cash`]: newTargetCash
}
}, function(err, res) {
if (err) return client.sendInternalError(err);
});
let targetUserBanking = await client.dbo.collection("banks").findOne({"banking.userID": targetUserID}).then(banking => banking);
@@ -483,40 +406,18 @@ module.exports = {
// Register inventory for user
let newBank = new Bank();
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
newBank.save()
.catch(err => {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
newBank.save().catch(err => {
if (err) return client.sendInternalError(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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (!success) return client.sendInternalError('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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
const successEmbed = new EmbedBuilder()
@@ -540,14 +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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
@@ -567,28 +461,14 @@ module.exports = {
}
client.dbo.collection("banks").insertOne(targetUserBanking, function(err, res) {
if (err) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(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) {
client.error(err);
const embed = new EmbedBuilder()
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
if (err) return client.sendInternalError(err);
});
const successEmbed = new EmbedBuilder()