diff --git a/commands/bank.js b/commands/bank.js index b7daf6b..e0738ae 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -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() diff --git a/commands/config.js b/commands/config.js index 552a983..ba71bb6 100644 --- a/commands/config.js +++ b/commands/config.js @@ -395,7 +395,7 @@ module.exports = { if (error) return interaction.send({ embeds: [errorEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -442,7 +442,7 @@ module.exports = { if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.actionChannel":channelid}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -481,7 +481,7 @@ module.exports = { if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.tweetChannel":channelid}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -520,7 +520,7 @@ module.exports = { if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.advertsChannel":channelid}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -560,7 +560,7 @@ module.exports = { if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.dispatchChannel":channelid}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -590,7 +590,7 @@ module.exports = { } else if (args[0].name == 'starting_balance') { client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.startingBalance":args[0].options[0].value}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); let successEmbed = new EmbedBuilder() @@ -619,7 +619,7 @@ module.exports = { } client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push: {"server.incomeRoles":newIncome}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else { client.dbo.collection("guilds").updateOne({ @@ -631,7 +631,7 @@ module.exports = { "server.incomeRoles.$.income": args[0].options[0].options[1].value } }, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } const perform = searchIndex == -1 ? 'set' : 'updated'; @@ -676,7 +676,7 @@ module.exports = { const roleId = args[0].options[0].options[0].value; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.commercialRole": roleId}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -711,7 +711,7 @@ module.exports = { if (args[0].options[0].name== 'set') { client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.officerRole": roleId}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -746,7 +746,7 @@ module.exports = { const roleId = args[0].options[0].options[0].value; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.dispatcherRole": roleId}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -782,7 +782,7 @@ module.exports = { const roleId = args[0].options[0].options[0].value; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.botAdmin": roleId}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -814,7 +814,7 @@ module.exports = { } else if (args[0].name == 'only_officers_search') { const setting = args[0].options[0]; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.onlyOfficersSearch": setting}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const title = setting ? 'True: Only officers can use /search' : 'False: Any user can use /search'; @@ -826,7 +826,7 @@ module.exports = { return interaction.send({ embeds: [successEmbed] }); } else if (args[0].name == 'casino_multiplier') { client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.casinoMultiplier": args[0].options[0]}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() @@ -917,7 +917,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, function (err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -941,7 +941,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.actionChannel": null}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; @@ -965,7 +965,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.tweetChannel": null}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -989,7 +989,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.advertsChannel": null}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1013,7 +1013,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.dispatchChannel": null}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1037,7 +1037,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull: {"server.incomeRoles": roleId}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1061,7 +1061,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.commercialRole": null}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1085,7 +1085,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='no') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.officerRole": null}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1109,7 +1109,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.dispatcherRole": null}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1133,7 +1133,7 @@ module.exports = { if (interaction.customId.split('-')[1]=='yes') { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.botAdmin": null}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; @@ -1172,7 +1172,7 @@ module.exports = { onlyOfficersSearch: false, } client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (interaction.customId.split('-')[1]=='no') action = 'kept'; diff --git a/commands/fine.js b/commands/fine.js index 29065c3..0c350a2 100644 --- a/commands/fine.js +++ b/commands/fine.js @@ -77,20 +77,20 @@ 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 banking = banking.banking; if (!client.exists(banking.guilds[GuildDB.serverID])) { const success = addBank(banking.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'); } const newTargetBalance = banking.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() diff --git a/commands/inventory.js b/commands/inventory.js index af9c248..dcf47ac 100644 --- a/commands/inventory.js +++ b/commands/inventory.js @@ -181,13 +181,13 @@ module.exports = { let newInventory = new Inventory(); newInventory.createInventory(interaction.member.user.id, GuildDB.serverID); newInventory.save().catch(err => { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, 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) return client.sendInternalError('Failed to add inventory'); + if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } if (args[0].name == 'view') { @@ -251,7 +251,7 @@ module.exports = { } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: firearm}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); let message = new EmbedBuilder() @@ -271,7 +271,7 @@ module.exports = { } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); let message = new EmbedBuilder() @@ -454,7 +454,7 @@ module.exports = { let item = inventory.guilds[GuildDB.serverID].items[args[0].options[0].value-1]; client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$pull: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); let message = new EmbedBuilder() .setTitle(`You ${dropActions[Math.floor(Math.random() * dropActions.length)]} your ${item.name}`) @@ -487,7 +487,7 @@ module.exports = { newInventory.createInventory(targetUserID, GuildDB.serverID); newInventory.addItem(item); newInventory.save().catch(err => { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else { targetUserInventory = targetUserIventory.inventory; @@ -504,10 +504,10 @@ module.exports = { } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$pull: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); client.dbo.collection('inventories').updateOne({'inventory.userID': targetUserID}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } @@ -534,7 +534,7 @@ module.exports = { action = 'cleared'; const tempWallet = inventory.guilds[GuildDB.serverID].items[0]; client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id},{$set:{[`inventory.guilds.${GuildDB.serverID}.items`]: [tempWallet]}},function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else if (queryString==`inventoryClear-no-${interaction.member.user.id}`) action = 'kept'; diff --git a/commands/invoice.js b/commands/invoice.js new file mode 100644 index 0000000..54749dc --- /dev/null +++ b/commands/invoice.js @@ -0,0 +1,137 @@ +const { EmbedBuilder } = require('discord.js'); +const { Invoice, addInvoiceList, addInvoice } = require('../structures/invoice'); + +module.exports = { + name: "invoice", + debug: false, + description: "handle invoices", + usage: "[cmd] [opt]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + options: [ + { + name: "list", + description: "list invoices that have been sent to you", + value: "list", + type: 1, + }, + { + name: "create", + description: "send an invoice to a user", + value: "create", + type: 1, + options: [ + { + name: "title", + description: "title of the invoice", + value: "title", + type: 3, + required: true, + }, + { + name: "description", + description: "description of the invoice", + value: "description", + type: 3, + required: true, + }, + { + name: "user", + description: "user to send invoice to", + value: "user", + type: 6, + required: true, + }, + { + name: "fee", + description: "the amount due for this invoice", + value: "fee", + type: 10, + min_value: 0.01, + required: true, + } + ] + } + ], + SlashCommand: { + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus && !GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + if (args[0].name == 'list') { + console.log('list'); + + } else if (args[0].name == 'create') { + if (!client.exists(GuildDB.commercialRole)) { + let embed = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setTitle("Notice:") + .setDescription("An admin needs to configure the commercial role in order for this command to be used."); + + return interaction.send({ embeds: [embed] }); + } + + if (!interaction.member.roles.includes(GuildDB.commercialRole)) { + let embed = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Notice:** You require the <@&${GuildDB.commercialRole}> role`) + + return interaction.send({ embeds: [embed] }); + } + + let invoices = await client.dbo.collection("invoices").findOne({"invoiceDB.userID": args[0].options[2].value}).then(invoices => invoices); + + if (!invoices) { + invoices = { + userID: args[0].options[2].value, + guilds: {} + }; + invoices.guilds[GuildDB.serverID] = { invoices: [] }; + + // Register invoiceDB for user + let newInvoice = new Invoice(); + newInvoice.createInvoiceDB(args[0].options[2].value, GuildDB.serverID); + newInvoice.save().catch(err => { + if (err) return client.sendInternalError(interaction, err); + }); + } else invoices = invoices.invoiceDB; + + if (!client.exists(invoices.guilds[GuildDB.serverID])) { + let success = addInvoiceList(invoices.guilds, GuildDB.serverID, args[0].options[2].value, client); + if (!success) return client.sendInternalError(interaction, 'Failed to add invoice list'); + } + + let ID = Math.floor(100000 + Math.random() * 900000); + let invoice = { + id: ID, + name: args[0].options[0].value, + description: args[0].options[1].value, + amount: args[0].options[3].value, + to: args[0].options[2].value, + from: interaction.member.user.id, + paid: false + }; + + let success = addInvoice(GuildDB.serverID, args[0].options[2].value, invoice, client); + if (!success) return client.sendInternalError(interaction, 'Failed to add invoice to user'); + + let successEmbed = new EmbedBuilder() + .setTitle("Success") + .setDescription(`Successfully sent invoice **${ID}** to <@${args[0].options[2].value}>`) + .setColor(client.config.Colors.Green); + + return interaction.send({ embeds: [successEmbed] }); + } + }, + }, +} \ No newline at end of file diff --git a/commands/money.js b/commands/money.js index a6a55b4..e7bef09 100644 --- a/commands/money.js +++ b/commands/money.js @@ -96,14 +96,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 banking = banking.banking; if (!client.exists(banking.guilds[GuildDB.serverID])) { const success = addBank(banking.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'); } const newBalance = args[0].name == 'add' @@ -111,7 +111,7 @@ module.exports = { : banking.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`]:newBalance}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() diff --git a/commands/search.js b/commands/search.js index cb6e343..c817561 100644 --- a/commands/search.js +++ b/commands/search.js @@ -71,13 +71,13 @@ module.exports = { let newInventory = new Inventory(); newInventory.createInventory(targetUserID, GuildDB.serverID); newInventory.save().catch(err => { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); } else inventory = targetUserInventory.inventory; if (!client.exists(inventory.guilds[GuildDB.serverID])) { const success = addInventory(inventory.guilds, GuildDB.serverID, targetUserID, client); - if (!success) return client.sendInternalError('Failed to add inventory'); + if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } // Display Inventory diff --git a/commands/wallet.js b/commands/wallet.js index 1f13b05..6f95af9 100644 --- a/commands/wallet.js +++ b/commands/wallet.js @@ -83,13 +83,13 @@ module.exports = { let newInventory = new Inventory(); newInventory.createInventory(interaction.member.user.id, GuildDB.serverID); newInventory.save().catch(err => { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, 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) return client.sendInternalError('Failed to add inventory'); + if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } if (args[0].name == "view") { @@ -140,7 +140,7 @@ module.exports = { } client.dbo.collection("inventories").updateOne(query, update, function (err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); let successEmbed = new EmbedBuilder() diff --git a/commands/work.js b/commands/work.js index babe379..a6afaee 100644 --- a/commands/work.js +++ b/commands/work.js @@ -50,13 +50,13 @@ module.exports = { let newInventory = new Inventory(); newInventory.createInventory(interaction.member.user.id, GuildDB.serverID); newInventory.save().catch(err => { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, 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) return client.sendInternalError('Failed to add inventory'); + if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } const now = new Date(); @@ -92,14 +92,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 job, earned; @@ -112,11 +112,11 @@ module.exports = { newBalance = banking.guilds[GuildDB.serverID].account.balance + earned 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); }); client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id}, {$set: {[`inventory.guilds.${GuildDB.serverID}.lastWork`]: now}}, function(err, res) { - if (err) return client.sendInternalError(err); + if (err) return client.sendInternalError(interaction, err); }); const success = new EmbedBuilder() diff --git a/config/config.js b/config/config.js index e5e7502..ceabdab 100644 --- a/config/config.js +++ b/config/config.js @@ -2,7 +2,7 @@ require('dotenv').config(); module.exports = { Dev: "PROD.", - Version: "12.8.2", // (major).(feature).(revision/bug/refactoring) + Version: "12.8.3", // (major).(feature).(revision/bug/refactoring) Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot DefaultPrefix: "?", ServerID: "955668596745461830", diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 86cb2fc..cbba091 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -12,6 +12,6 @@ module.exports = async (client, interaction) => { try { interactionHandler.run(client, interaction, { GuildDB }); } catch (err) { - client.sendInternalError(err); + client.sendInternalError(interaction, err); } } \ No newline at end of file diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index 4f5af85..c6d7462 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -143,7 +143,7 @@ class QuarksBot extends Client { this.error(Error); 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) + .setColor(this.config.Colors.Red) Interaction.send({ embeds: [embed] }); }