fix banking db calls, add permission check for settings command
This commit is contained in:
8 files changed
+79
-51
No files matched your search
+12
-12
@@ -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()
|
||||
|
||||
+2
-2
@@ -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()
|
||||
|
||||
+3
-3
@@ -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()
|
||||
|
||||
+23
-7
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user