diff --git a/package.json b/package.json index 05a64ed..ef2374e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.6.7", + "version": "6.7.1", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 010e1e6..9b72954 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -140,7 +140,8 @@ class DayzArmbands extends Client { for (let i = logIndex + 1; i < lines.length; i++) { if (lines[i].includes("Unknown")) continue; - if (lines[i].includes('connected') || lines[i].includes('pos=<') || lines[1].includes['hit by Player']) s = await HandlePlayerLogs(this, guildId, s, lines[i]); + if (lines[i].includes('connected') || lines[i].includes('pos=<') || lines[1].includes('hit by Player')) s = await HandlePlayerLogs(this, guildId, s, lines[i]); + if (lines[i].includes('hit by explosion') && lines[i].includes('(DEAD)')) s = await HandleKillfeed(this, guildId, s, lines[i]); if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); } diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index 9da64a8..e0fc13a 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -9,28 +9,46 @@ module.exports = { let guild = await client.GetGuild(guildId); const channel = client.channels.cache.get(guild.killfeedChannel); - let template = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: 0\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; - let data = [...line.matchAll(template)][0]; + let template = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: 0\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; + let explosionTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: 0] hit by explosion \((.*)\)/g; + + let killedByPlayer = line.includes('hit by Player') ? true : false; + + let data = killedByPlayer ? [...line.matchAll(template)][0] : [...line.matchAll(explosionTemplate)]; if (!data) return stats; + // Create base data let info = { - time: data[1], - victim: data[2], - victimID: data[3], + time: data[1], + victim: data[2], + victimID: data[3], victimPOS: data[4], - killer: data[5], - killerID: data[6], - killerPOS: data[7], - bodyPart: data[8], - damage: data[9], - bullet: data[10], - weapon: data[11], - distance: data[12] - }; + }; + + // Add additional data + if (killedByPlayer) { + info.killer = data[5]; + info.killerID = data[6]; + info.killerPOS = data[7]; + info.bodyPart = data[8]; + info.damage = data[9]; + info.bullet = data[10]; + info.weapon = data[11]; + info.distance = data[12]; + } else info.explosive = data[5]; let newDt = await client.getDateEST(info.time); let unixTime = Math.floor(newDt.getTime()/1000); + if (!killedByPlayer) { + const killEvent = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`**Death Event** - \n**${info.victim}** blew up from a **${info.explosive}.**>`); + + if (client.exists(channel)) await channel.send({ embeds: [killEvent] }); + return stats; + } + KillInAlarm(client, guildId, info); // check if kill happened in a no kill zone if (!client.exists(info.victim) || !client.exists(info.victimID) || !client.exists(info.killer) || !client.exists(info.killerID)) return stats; diff --git a/util/LogsHandler.js b/util/LogsHandler.js index fae491a..7894083 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -6,11 +6,11 @@ module.exports = { HandlePlayerLogs: async (client, guildId, stats, line) => { - const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g; + const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g; const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g; - const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; - const damageTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; - const deadTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; + const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; + const damageTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; + const deadTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: 0] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; if (line.includes(' connected')) { let data = [...line.matchAll(connectTemplate)][0]; @@ -98,6 +98,11 @@ module.exports = { playerStat.lastTime = playerStat.time; playerStat.time = `${info.time} EST`; + if (playerStatIndex == -1) stats.push(playerStat); + else stats[playerStatIndex] = playerStat; + + if (line.includes('hit by') || line.includes('killed by')) return; // prevent additional information from being fed to Alarms & UAVs + HandleAlarmsAndUAVs(client, guildId, { time: info.time, player: info.player, @@ -105,8 +110,6 @@ module.exports = { pos: info.pos, }); - if (playerStatIndex == -1) stats.push(playerStat); - else stats[playerStatIndex] = playerStat; } if (line.includes('hit by Player')) {