diff --git a/commands/bank.js b/commands/bank.js index cbe0256..e480529 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -111,7 +111,7 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } - let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); + let banking = await client.dbo.collection("banks").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); if (!banking) { banking = { @@ -198,7 +198,7 @@ module.exports = { newBalance = banking.guilds[guildDB.serverID].account.balance + args[0].options[0].value; newCash = Math.abs(banking.guilds[guildDB.serverID].account.cash.toFixed(2) - args[0].options[0].value); - client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance,[`banking.guilds.${guildDB.serverID}.account.cash`]:newCash}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.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.log(err); const embed = new MessageEmbed() @@ -239,7 +239,7 @@ module.exports = { newBalance = banking.guilds[guildDB.serverID].account.balance - args[0].options[0].value; newCash = banking.guilds[guildDB.serverID].account.cash + args[0].options[0].value; - client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance,[`banking.guilds.${guildDB.serverID}.account.cash`]:newCash}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.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.log(err); const embed = new MessageEmbed() @@ -276,7 +276,7 @@ module.exports = { // Show target users balance let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); - let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + let targetUserBanking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!targetUserBanking) { banking = { @@ -353,7 +353,7 @@ module.exports = { newCash = banking.guilds[guildDB.serverID].account.cash - args[0].options[1].value; - client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.cash`]:newCash}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.cash`]:newCash}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -423,7 +423,7 @@ module.exports = { }); - let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + let targetUserBanking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!targetUserBanking) { targetUserBanking = { @@ -434,7 +434,7 @@ module.exports = { } } - client.dbo.collection("banking").insertOne(targetUserBanking, function(err, res) { + client.dbo.collection("banks").insertOne(targetUserBanking, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -447,7 +447,7 @@ module.exports = { } else { let newTargetCash = targetUserBanking.account.cash + args[0].options[1].value; - client.dbo.collection("banking").updateOne({"account.userID": targetUserID}, {$set: {[`banking.guilds.${guildDB.serverID}.account.cash`]: newTargetCash}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.userID": targetUserID}, {$set: {[`banking.guilds.${guildDB.serverID}.account.cash`]: newTargetCash}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -479,7 +479,7 @@ module.exports = { newBalance = banking.guilds[guildDB.serverID].account.balance - args[0].options[1].value; - client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -491,7 +491,7 @@ module.exports = { }); let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); - let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + let targetUserBanking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!targetUserBanking) { targetUserBanking = { @@ -502,7 +502,7 @@ module.exports = { } } - client.dbo.collection("banking").insertOne(targetUserBanking, function(err, res) { + client.dbo.collection("banks").insertOne(targetUserBanking, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -515,7 +515,7 @@ module.exports = { } else { let newTargetBalance = targetUserBanking.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) { + client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newTargetBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() diff --git a/commands/fine.js b/commands/fine.js index 2eec42f..72d66e5 100644 --- a/commands/fine.js +++ b/commands/fine.js @@ -56,7 +56,7 @@ module.exports = { } const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); - let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!banking) { banking = { @@ -102,7 +102,7 @@ module.exports = { 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) { + client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newTargetBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() diff --git a/commands/money.js b/commands/money.js index 54058dd..e909630 100644 --- a/commands/money.js +++ b/commands/money.js @@ -69,7 +69,7 @@ module.exports = { } let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); - let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!banking) { banking = { @@ -118,7 +118,7 @@ module.exports = { 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) { + client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() @@ -140,7 +140,7 @@ module.exports = { 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) { + client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() diff --git a/commands/settings.js b/commands/settings.js index 4d416d3..7a05a70 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -1,4 +1,5 @@ const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); +const bitfieldCalculator = require('discord-bitfield-calculator'); module.exports = { name: "settings", @@ -322,18 +323,33 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } + const permissions = bitfieldCalculator.permissions(interaction.member.permissions); + + let canUseCommand = false; + + if (permissions.includes("MANAGE_GUILD")) { + canUseCommand = true; + } + + if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) { + canUseCommand = true; + } + + if (!canUseCommand) { + return interaction.send('You don\'t have the permissions to use this command.'); + } + if (args[0].name == 'allowed_channels') { const channelid = args[0].options[0].options[0].value; - if (args[0].options[0].value == 'add') { + if (args[0].options[0].name == 'add') { const channel = client.channels.cache.get(channelid); const errorEmbed = new MessageEmbed().setColor("RED") let error = false; - if (!channel) errorEmbed.setDescription(`**Error Notice:** Cannot find that channel.`); - if (channel.type=="voice") errorEmbed.setDescriptions(`**Error Notice:** Cannot add voice channel to allowed channels.`); - if (channel.deleted) errorEmbed.setDescription(`**Error Notice":** Cannot add deleted channel to allowed channels.`); + if (!channel) {error=true;errorEmbed.setDescription(`**Error Notice:** Cannot find that channel.`);} + if (channel.type=="voice") {error=true;errorEmbed.setDescriptions(`**Error Notice:** Cannot add voice channel to allowed channels.`);} if (error) return interaction.send({ embeds: [errorEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) { @@ -352,7 +368,7 @@ module.exports = { .setDescription(`**Success:** Set <#${channelid}> as an allowed channel.`); return interaction.send({ embeds: [successEmbed] }); - } else if (args[0].options[0].name== 'remove') { + } else if (args[0].options[0].name=='remove') { const embed = new MessageEmbed() .setDescription(`**Error Notice:** <#${channelid}> is not in allowed channels.`) @@ -409,10 +425,10 @@ module.exports = { return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); return; - } + } else console.log('exception?'); } else if (args[0].name == 'action_channel') { - if (args[0].options[0].name== 'set') { + if (args[0].options[0].name=='set') { const channelid = args[0].options[0].options[0].value; const channelSetting = GuildDB.actionChannel; diff --git a/commands/work.js b/commands/work.js index 0e498a5..265ddd3 100644 --- a/commands/work.js +++ b/commands/work.js @@ -74,7 +74,7 @@ module.exports = { } } - let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); + let banking = await client.dbo.collection("banks").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); if (!banking) { banking = { @@ -127,7 +127,7 @@ module.exports = { earned = workPays[highestPayIndex] newBalance = banking.guilds[guildDB.serverID].account.balance + earned - client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { + client.dbo.collection("banks").updateOne({"account.userID":interaction.member.user.id},{$set:{[`banking.guilds.${guildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() diff --git a/package-lock.json b/package-lock.json index 4442f38..892b5ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "colors": "^1.4.0", + "discord-bitfield-calculator": "^1.0.0", "discord.js": "^13.8.1", "mongodb": "^4.7.0", "mongoose": "^6.4.2", @@ -166,9 +167,9 @@ ] }, "node_modules/bson": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/bson/-/bson-4.6.4.tgz", - "integrity": "sha512-TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz", + "integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==", "dependencies": { "buffer": "^5.6.0" }, @@ -300,6 +301,11 @@ "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz", "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, + "node_modules/discord-bitfield-calculator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discord-bitfield-calculator/-/discord-bitfield-calculator-1.0.0.tgz", + "integrity": "sha512-I1istpckG90n/kTId2OGFLz4Bm1uaJUXx6B7CsazMo3MvoQHOsLk0OWzIRlQnOyGynr8A/q9b+6Eo+Ep0UUaCA==" + }, "node_modules/discord.js": { "version": "13.8.1", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.1.tgz", @@ -446,11 +452,11 @@ } }, "node_modules/mongodb": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", - "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.8.1.tgz", + "integrity": "sha512-/NyiM3Ox9AwP5zrfT9TXjRKDJbXlLaUDQ9Rg//2lbg8D2A8GXV0VidYYnA/gfdK6uwbnL4FnAflH7FbGw3TS7w==", "dependencies": { - "bson": "^4.6.3", + "bson": "^4.6.5", "denque": "^2.0.1", "mongodb-connection-string-url": "^2.5.2", "socks": "^2.6.2" @@ -472,13 +478,13 @@ } }, "node_modules/mongoose": { - "version": "6.4.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.4.2.tgz", - "integrity": "sha512-VRotms+XC42vPlS3Tr2GTg0qkppHzWob62sUjdC22ir8aqWVrbCsHjEuMsL6zZlKSIj8zNBODm9hRV+RHRiLRQ==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.2.tgz", + "integrity": "sha512-3CFDrSLtK2qjM1pZeZpLTUyqPRkc11Iuh74ZrwS4IwEJ3K2PqGnmyPLw7ex4Kzu37ujIMp3MAuiBlUjfrcb6hw==", "dependencies": { - "bson": "^4.6.2", + "bson": "^4.6.5", "kareem": "2.4.1", - "mongodb": "4.7.0", + "mongodb": "4.8.1", "mpath": "0.9.0", "mquery": "4.0.3", "ms": "2.1.3", @@ -905,9 +911,9 @@ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, "bson": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/bson/-/bson-4.6.4.tgz", - "integrity": "sha512-TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz", + "integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==", "requires": { "buffer": "^5.6.0" } @@ -1004,6 +1010,11 @@ "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz", "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, + "discord-bitfield-calculator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discord-bitfield-calculator/-/discord-bitfield-calculator-1.0.0.tgz", + "integrity": "sha512-I1istpckG90n/kTId2OGFLz4Bm1uaJUXx6B7CsazMo3MvoQHOsLk0OWzIRlQnOyGynr8A/q9b+6Eo+Ep0UUaCA==" + }, "discord.js": { "version": "13.8.1", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.1.tgz", @@ -1117,11 +1128,11 @@ } }, "mongodb": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", - "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.8.1.tgz", + "integrity": "sha512-/NyiM3Ox9AwP5zrfT9TXjRKDJbXlLaUDQ9Rg//2lbg8D2A8GXV0VidYYnA/gfdK6uwbnL4FnAflH7FbGw3TS7w==", "requires": { - "bson": "^4.6.3", + "bson": "^4.6.5", "denque": "^2.0.1", "mongodb-connection-string-url": "^2.5.2", "saslprep": "^1.0.3", @@ -1138,13 +1149,13 @@ } }, "mongoose": { - "version": "6.4.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.4.2.tgz", - "integrity": "sha512-VRotms+XC42vPlS3Tr2GTg0qkppHzWob62sUjdC22ir8aqWVrbCsHjEuMsL6zZlKSIj8zNBODm9hRV+RHRiLRQ==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.2.tgz", + "integrity": "sha512-3CFDrSLtK2qjM1pZeZpLTUyqPRkc11Iuh74ZrwS4IwEJ3K2PqGnmyPLw7ex4Kzu37ujIMp3MAuiBlUjfrcb6hw==", "requires": { - "bson": "^4.6.2", + "bson": "^4.6.5", "kareem": "2.4.1", - "mongodb": "4.7.0", + "mongodb": "4.8.1", "mpath": "0.9.0", "mquery": "4.0.3", "ms": "2.1.3", diff --git a/package.json b/package.json index 9dbd016..63fc267 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "license": "ISC", "dependencies": { "colors": "^1.4.0", + "discord-bitfield-calculator": "^1.0.0", "discord.js": "^13.8.1", "mongodb": "^4.7.0", "mongoose": "^6.4.2", diff --git a/structures/bank.js b/structures/bank.js index f508974..41c8209 100644 --- a/structures/bank.js +++ b/structures/bank.js @@ -29,7 +29,7 @@ function addBank(guilds, guildID, userID, client, startingBalance) { } } - client.dbo.collection("banking").updateOne({"banking.userID":userID}, {$set: {"banking.guilds": updatedGuilds}}, function(err, res) { + client.dbo.collection("banks").updateOne({"banking.userID":userID}, {$set: {"banking.guilds": updatedGuilds}}, function(err, res) { if (err) return false }) return true