From 0af1e51f5008e5460d0775f94e28e39b48726ab1 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Tue, 23 Apr 2024 10:08:52 -0700 Subject: [PATCH] fix/save DayZ Mission to guild db for commands use --- commands/location.js | 11 ++++------- package.json | 2 +- src/DayzRBot.js | 9 +++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/commands/location.js b/commands/location.js index d6e2902..2c4e3e6 100644 --- a/commands/location.js +++ b/commands/location.js @@ -20,8 +20,8 @@ module.exports = { * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { - - if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { + + if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth) || !client.exists(GuildDB.Nitrado.Mission)) { const warnNitradoNotInitialized = new EmbedBuilder() .setColor(client.config.Colors.Yellow) .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); @@ -31,12 +31,9 @@ module.exports = { let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** You haven't linked your gamertag and are unable to use this command.`)], flags: (1 << 6) }); + if (!client.exists(playerStat.time)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** There is no location saved to your gamertag yet. Make sure you've logged into the server for more than **5 minutes.**`)], flags: (1 << 6)}); - if (!client.exists(playerStat.time)) return interaction.send({ emeds: [ - new EmbedBuilder() - .setColor(client.config.Colors.Yellow) - .setDescription(`**Not Found** There is no location saved to your gamertag yet. Make sure you've logged into the server for more than **5 minutes.**`) - ] }); + console.log(true); let newDt = await client.getDateEST(playerStat.time); let unixTime = Math.floor(newDt.getTime()/1000); diff --git a/package.json b/package.json index 2acba16..94bc8b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "13.0.7", + "version": "13.0.8", "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 95959b7..5d6e1bf 100644 --- a/src/DayzRBot.js +++ b/src/DayzRBot.js @@ -93,6 +93,8 @@ class DayzRBot extends Client { ); } + console.log(GuildDB.Nitrado); + for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) { const guild = this.guilds.cache.get(GuildDB.serverID); const role = guild.roles.cache.find(role => role.id == factionID); @@ -319,6 +321,13 @@ class DayzRBot extends Client { if (response == 1) return; const settings = response.data.gameserver; + // Update Nitrado DayZ Mission if change is detected + if (GuildDB.Nitrado.Mission !== Missions[settings.settings.config.mission]) { + c.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: { "Nitrado.Mission": Missions[settings.settings.config.mission] }}, (err, res) => { + if (err) this.error(`Failed to save mission to guild config [${guild.serverID}] for nitrado server [${guild.Nitrado.ServerID}]`); + }); + } + GuildDB.Nitrado.Mission = Missions[settings.settings.config.mission]; const filename = settings.game_specific.log_files.sort((a, b) => a.length - b.length)[0];