From 2df5ef0014c4f0caf8c23be92bf41713e828198b Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Mon, 12 Jun 2023 20:47:13 -0700 Subject: [PATCH] 7.0.0 EMP feature --- commands/alarm.js | 1 + commands/purchase-emp.js | 117 +++++++++++++++++++++++++++++++++++++ commands/purchase-uav.js | 7 +-- package.json | 2 +- structures/DayzArmbands.js | 1 + util/AlarmsHandler.js | 2 + 6 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 commands/purchase-emp.js diff --git a/commands/alarm.js b/commands/alarm.js index ac63c91..ae1709f 100644 --- a/commands/alarm.js +++ b/commands/alarm.js @@ -213,6 +213,7 @@ module.exports = { empExempt: client.exists(args[0].options[6]) ? args[0].options[6].value : false, showPlayerCoord: client.exists(args[0].options[7]) ? args[0].options[7].value : true, disabled: false, + empExpire: null, }; client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { diff --git a/commands/purchase-emp.js b/commands/purchase-emp.js new file mode 100644 index 0000000..fdff61d --- /dev/null +++ b/commands/purchase-emp.js @@ -0,0 +1,117 @@ +const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder } = require('discord.js'); +const { User, addUser } = require('../structures/user'); + +module.exports = { + name: "purchase-emp", + debug: false, + global: false, + description: "EMP an Alarm to prevent any updates for 30 minutes.", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + options: [], + SlashCommand: { + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + + let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); + + if (!banking) { + banking = { + userID: interaction.member.user.id, + guilds: { + [GuildDB.serverID]: { + bankAccount: { + balance: GuildDB.startingBalance, + cash: 0.00, + } + } + } + } + + // Register bank for user + let newBank = new User(); + newBank.createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0); + newBank.save().catch(err => { + if (err) return client.sendInternalError(interaction, err); + }); + + } else banking = banking.user; + + if (!client.exists(banking.guilds[GuildDB.serverID])) { + 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 (banking.guilds[GuildDB.serverID].balance.toFixed(2) - GuildDB.empPrice < 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 - GuildDB.empPrice; + + if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to EMP.')], flags: (1 << 6) }); + + 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); + }); + + let alarms = new SelectMenuBuilder() + .setCustomId(`EMPAlarmSelect-${interaction.member.user.id}`) + .setPlaceholder(`Select an Alarm to EMP.`) + + for (let i = 0; i < GuildDB.alarms.length; i++) { + if (!alarm.empExempt) { + alarms.addOptions({ + label: GuildDB.alarms[i].name, + description: `EMP this Alarm for $500,000`, + value: GuildDB.alarms[i].name + }); + } + } + + const opt = new ActionRowBuilder().addComponents(alarms); + + return interaction.send({ components: [opt], flags: (1 << 6) }); + }, + }, + + Interactions: { + EMPAlarmSelect: { + run: async (client, interaction, GuildDB) => { + let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]); + let alarms = GuildDB.alarms; + let alarmIndex = alarms.indexOf(alarm); + alarm.disabled = true; + let d = new Date(); + alarm.empExpire = new Date(d.getTime() += (30 * 60 * 1000)); + alarms[alarmIndex] = alarm; + + client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { + $set: { + 'server.alarms': alarms, + } + }, function (err, res) { + if (err) return client.sendInternalError(interaction, err); + }); + + let successEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`**Success:** Successfully EMP'd **${alarm.name}** for 30 minutes.`); + + return interaction.update({ embeds: [successEmbed], components: [] }); + } + } + } +} diff --git a/commands/purchase-uav.js b/commands/purchase-uav.js index 7d5f7e7..5f0cbea 100644 --- a/commands/purchase-uav.js +++ b/commands/purchase-uav.js @@ -6,11 +6,11 @@ module.exports = { debug: false, global: false, description: "Send a UAV to scout for 30 minutes. (500m range)", - usage: "[cmd] [opt]", + usage: "[x-coord] [y-coord]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: ["MANAGE_GUILD"], - }, + }, options: [ { name: "x-coord", @@ -73,7 +73,7 @@ module.exports = { .setTitle('**Bank Notice:** NSF. Non sufficient funds') .setColor(client.config.Colors.Red); - return interaction.send({ embeds: [embed] }); + return interaction.send({ embeds: [embed], flags: (1 << 6) }); } const newBalance = banking.guilds[GuildDB.serverID].balance - GuildDB.uavPrice; @@ -102,7 +102,6 @@ module.exports = { .setDescription(`**Success:** Successfully deployed a UAV to **[${uav.origin[0]}, ${uav.origin[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${uav.origin[0]};${uav.origin[1]})**\nRange: 500m`); return interaction.send({ embeds: [successEmbed], flags: (1 << 6) }); - }, } } diff --git a/package.json b/package.json index 053a584..e270986 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.14.2", + "version": "7.0.0", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 725cec5..969d870 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -356,6 +356,7 @@ class DayzArmbands extends Client { linkedGamertagRole: "", startingBalance: 500, uavPrice: 50000, + empPrice: 500000, memberRole: "", adminRole: "", } diff --git a/util/AlarmsHandler.js b/util/AlarmsHandler.js index b49209a..8133685 100644 --- a/util/AlarmsHandler.js +++ b/util/AlarmsHandler.js @@ -9,6 +9,8 @@ module.exports = { for (let i = 0; i < guild.alarms.length; i++) { let alarm = guild.alarms[i]; + let now = new Date(); + if (alarm.uavExpire!=null&&alarm.uavExpire