pay off bounties for double price
This commit is contained in:
2 files changed
+64
-7
No files matched your search
+63
-6
@@ -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()
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayz-armbands",
|
||||
"version": "8.3.6",
|
||||
"version": "8.4.0",
|
||||
"description": "A General Purpose Discord Bot for DayZ Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
Reference in new issue
Block a user