From 1d1698c8c4cd54bc4dc26083d08401b2c13830c8 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sat, 21 Oct 2023 21:23:36 -0700 Subject: [PATCH] feature/disbale emp+uav commands --- commands/config.js | 56 +++++++++++++++++++++++++++++++++++++-- commands/purchase-emp.js | 4 +-- commands/purchase-uav.js | 2 +- database/guildSettings.js | 6 +++-- package.json | 2 +- src/DayzRBot.js | 2 ++ 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/commands/config.js b/commands/config.js index be45099..9b2a4cc 100644 --- a/commands/config.js +++ b/commands/config.js @@ -330,7 +330,33 @@ module.exports = { type: CommandOptions.Integer, min_value: 0, }] - } + }, + { + name: "toggle-uav-purchase", + description: "Allow/Disallow UAV purchases", + value: "toggle-uav-purchase", + type: CommandOptions.SubCommand, + options: [{ + name: "configuration", + description: "True or False", + value: false, + type: CommandOptions.Boolean, + required: true, + }] + }, + { + name: "toggle-emp-purchase", + description: "Allow/Disallow EMP purchases", + value: "toggle-uav-purchase", + type: CommandOptions.SubCommand, + options: [{ + name: "configuration", + description: "True or False", + value: false, + type: CommandOptions.Boolean, + required: true, + }] + }, ], SlashCommand: { /** @@ -737,7 +763,33 @@ module.exports = { .setColor(client.config.Colors.Green) .setDescription(`Successfully set combat log timer to **${args[0].options[0].value.toFixed(0)} minutes.**`); - return interaction.send({ embeds: [successCobatLogTimerEmbed] }); + return interaction.send({ embeds: [successCobatLogTimerEmbed] }); + + case 'toggle-uav-purchase': + const togggleUAVpurchase = args[0].options[0].value ? 1 : 0; + + client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.purchaseUAV": togggleUAVpurchase}}, (err, res) => { + if (err) return client.sendInternalError(interaction, err); + }); + + let successToggleUAVpurchaseEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`Users can ${togggleUAVpurchase ? 'now' : 'no longer'} purchase UAVs.`); + + return interaction.send({ embeds: [successToggleUAVpurchaseEmbed] }); + + case 'toggle-emp-purchase': + const togggleEMPpurchase = args[0].options[0].value ? 1 : 0; + + client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.purchaseEMP": togggleEMPpurchase}}, (err, res) => { + if (err) return client.sendInternalError(interaction, err); + }); + + let successToggleEMPpurchaseEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`Users can ${togggleUAVpurchase ? 'now' : 'no longer'} purchase EMPs.`); + + return interaction.send({ embeds: [successToggleEMPpurchaseEmbed] }); default: return client.sendInternalError(interaction, 'There was an error parsing the config command'); diff --git a/commands/purchase-emp.js b/commands/purchase-emp.js index 7f85dd2..ade55bd 100644 --- a/commands/purchase-emp.js +++ b/commands/purchase-emp.js @@ -1,4 +1,4 @@ -const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js'); +const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, Embed } = require('discord.js'); const { createUser, addUser } = require('../database/user'); module.exports = { @@ -21,9 +21,9 @@ module.exports = { * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { + if (client.exists(GuildDB.purchaseEMP) && !GuildDB.purchaseEMP) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Notice:** The admins have disabled this feature')] }); let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); - if (!banking) { banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) diff --git a/commands/purchase-uav.js b/commands/purchase-uav.js index 6032a04..335f6a5 100644 --- a/commands/purchase-uav.js +++ b/commands/purchase-uav.js @@ -39,10 +39,10 @@ module.exports = { * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { + if (client.exists(GuildDB.purchaseUAV) && !GuildDB.purchaseUAV) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Notice:** The admins have disabled this feature')] }); let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); - if (!banking) { banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) if (!client.exists(banking)) return client.sendInternalError(interaction, err); diff --git a/database/guildSettings.js b/database/guildSettings.js index bb0554b..bf7c209 100644 --- a/database/guildSettings.js +++ b/database/guildSettings.js @@ -2,8 +2,10 @@ module.exports = { getDefaultSettings(GuildId) { return { serverID: GuildId, - autoRestart: 0, - showKillfeedCoords: 0, + autoRestart: 0, // + showKillfeedCoords: 0, + purchaseUAV: 1, // Allow/Disallow purchase of UAVs + purchaseEMP: 1, // Allow/Disallow purchase of EMPs allowedChannels: [], killfeedChannel: "", diff --git a/package.json b/package.json index e94865b..cb26593 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "11.0.1", + "version": "11.1.0", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/src/DayzRBot.js b/src/DayzRBot.js index 2420cb9..fcfbc33 100644 --- a/src/DayzRBot.js +++ b/src/DayzRBot.js @@ -444,6 +444,8 @@ class DayzRBot extends Client { memberRole: guild.server.memberRole, adminRole: guild.server.adminRole, combatLogTimer: guild.server.combatLogTimer, + purchaseUAV: guild.server.purchaseUAV, + purchaseEMP: guild.server.purchaseEMP, }; }