diff --git a/package.json b/package.json index 226835f..b6f3ae8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "10.0.12", + "version": "10.1.0", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index dabba09..d14c1b6 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -41,6 +41,7 @@ class DayzRBot extends Client { this.arInterval = arInterval; this.arIntervalId; // Interval for auto-restart functions this.playerSessions = new Map(); + this.alarmPingQueue = {}; this.autoRestartInit(); this.LoadCommandsAndInteractionHandlers(); this.LoadEvents(); @@ -155,6 +156,14 @@ class DayzRBot extends Client { if (lines[i].includes('killed by Player') && !lines[i - 1].includes('hit by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); // Handles deaths missing hit by log } + for (const [channel_id, role] of Object.entries(client.alarmPingQueue)) { + const channel = client.GetChannel(channel_id); + + channel.send({ content: `<@&${role}>`, embeds: client.alarmPingQueue[channel_id][role] }); + } + + client.alarmPingQueue = {}; + const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; let previouslyConnected = s.filter(p => p.connected); // All players with connection log captured above and no disconnect log let lastDetectedTime; diff --git a/util/AlarmsHandler.js b/util/AlarmsHandler.js index 71fde19..5f0418a 100644 --- a/util/AlarmsHandler.js +++ b/util/AlarmsHandler.js @@ -57,29 +57,33 @@ module.exports = { let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2) if (distance < alarm.radius) { - const channel = client.GetChannel(alarm.channel); let newDt = await client.getDateEST(data.time); let unixTime = Math.floor(newDt.getTime()/1000); - - if (alarm.rules.includes['ban_on_entry']) { - let alarmEmbed = new EmbedBuilder() - .setColor(client.config.Colors.Default) - .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`) - .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) - - channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }); + if (!client.alarmPingQueue[alarm.channel]) client.alarmPingQueue[alarm.channel] = {}; + if (!client.alarmPingQueue[alarm.channel][alarm.role]) client.alarmPingQueue[alarm.channel][alarm.role] = []; + + if (alarm.rules.includes['ban_on_entry']) { + client.alarmPingQueue[alarm.channel][alarm.role].push( + new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`) + .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) + ); BanPlayer(client, data.player); + return; } - let alarmEmbed = new EmbedBuilder() - .setColor(client.config.Colors.Default) - .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`) - .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) + client.alarmPingQueue[alarm.channel][alarm.role].push( + new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`) + .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) + ); - return await channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }); + return; } }