pay off bounties for double price

This commit is contained in:
SowinskiBraeden committed 2023-08-20 18:16:12 -07:00
1 parent 20e70c554b
commit dd1d326ff5
3 files changed
+75 -18

No files matched your search

+10 -10
View File
@@ -59,7 +59,7 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
}
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
@@ -74,13 +74,13 @@ module.exports = {
}
}
// Register bank for user
// Register bank for user
let newBank = new User();
newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance);
newBank.save().catch(err => {
if (err) return client.sendInternalError(interaction, err);
});
} else banking = banking.user;
if (!client.exists(banking.guilds[GuildDB.serverID])) {
@@ -108,13 +108,13 @@ module.exports = {
}
}
// Register bank for user
// Register bank for user
let newBank = new User();
newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
newBank.save().catch(err => {
if (err) return client.sendInternalError(interaction, err);
});
} else targetUserBanking = targetUserBanking.user;
if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) {
@@ -154,7 +154,7 @@ module.exports = {
}
const newBalance = banking.guilds[GuildDB.serverID].balance - args[0].options[1].value;
client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
@@ -171,26 +171,26 @@ module.exports = {
}
}
// Register bank for user
// Register bank for user
let newBank = new User();
newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
newBank.save().catch(err => {
if (err) return client.sendInternalError(interaction, err);
});
} else targetUserBanking = targetUserBanking.user;
const newTargetBalance = targetUserBanking.guilds[GuildDB.serverID].balance + args[0].options[1].value;
client.dbo.collection("users").updateOne({"user.userID":targetUserID},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newTargetBalance}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
const successEmbed = new EmbedBuilder()
.setTitle('Bank Notice:')
.setDescription(`Successfully transfered <@${targetUserID}> **$${args[0].options[1].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}**`)
.setColor(client.config.Colors.Green);
return interaction.send({ embeds: [successEmbed] });
return interaction.send({ embeds: [successEmbed] });
}
},
},
+64 -7
View File
@@ -35,6 +35,11 @@ module.exports = {
type: 5,
required: false
}]
}, {
name: "pay",
description: "Pay off your bounty (double price)",
value: "pay",
type: 1,
}, {
name: "view",
description: "View all active bounties",
@@ -51,12 +56,7 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (args[0].name == 'set') {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].options[0].value);
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** This player cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least ` 5 minutes `.')] });
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
if (args[0].name == 'set' || args[0].name == 'pay') {
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
if (!banking) {
@@ -82,6 +82,13 @@ module.exports = {
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
}
}
if (args[0].name == 'set') {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].options[0].value);
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** This player cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least ` 5 minutes `.')] });
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
if (args[0].options[1].value > banking.guilds[GuildDB.serverID].balance) {
let nsf = new EmbedBuilder()
@@ -116,7 +123,7 @@ module.exports = {
}
}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
});
const successEmbed = new EmbedBuilder()
.setTitle('Success')
@@ -126,6 +133,56 @@ module.exports = {
if (anonymous && anonymous.value) return interaction.send({ embeds: [successEmbed], flags: (1 << 6) });
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'pay') {
let playerStat = GuildDB.playerstats.find(stat => stat.discordID == interaction.member.user.id);
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** Your user ID could not be found, contact an Admin.')] });
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
if (playerStat.bounties.length == 0) {
const noBounty = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription(`You have no bounties to pay off.`)
return interaction.send({ embeds: [noBounty] });
}
let totalBounty = 0;
for (let i = 0; i < playerStat.bounties.length; i++) {
totalBounty += playerStat.bounties[i].value;
}
if (banking.guilds[GuildDB.serverID].balance.toFixed(2) - (totalBounty * 2) < 0) {
let embed = new EmbedBuilder()
.setTitle('**Bank Notice:** NSF. Non sufficient funds')
.setColor(client.config.Colors.Red);
return interaction.send({ embeds: [embed], flags: (1 << 6) });
}
const newBalance = banking.guilds[GuildDB.serverID].balance - (totalBounty * 2);
client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
playerStat.bounties = [];
GuildDB.playerstats[playerStatIndex] = playerStat;
client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, {
$set: {
'server.playerstats': GuildDB.playerstats,
}
}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
const payedOff = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setDescription(`Successfully paid off **$${(totalBounty * 2).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** in bounties.`);
return interaction.send({ embeds: [payedOff] });
} else if (args[0].name == 'view') {
let activeBounties = GuildDB.playerstats.filter((p) => p.bounties.length > 0);