refactor/KillfeedHandler
This commit is contained in:
1 parent
66660657da
commit
17ce345101
2 files changed
+17
-18
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "12.5.8",
|
"version": "12.5.9",
|
||||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
|
|||||||
+16
-17
@@ -17,6 +17,16 @@ const Templates = {
|
|||||||
Vehicle: 7,
|
Vehicle: 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TemplateExpressions = {
|
||||||
|
1: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) with (.*) from (.*) meters /g,
|
||||||
|
2: /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g,
|
||||||
|
3: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g,
|
||||||
|
4: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by with (.*)/g,
|
||||||
|
5: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by LandMineTrap/g,
|
||||||
|
6: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*)/g,
|
||||||
|
7: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by (.*) with TransportHit/g,
|
||||||
|
};
|
||||||
|
|
||||||
const Vehicles = {
|
const Vehicles = {
|
||||||
CivilianSedan: 'White Olga',
|
CivilianSedan: 'White Olga',
|
||||||
CivilianSedan_Black: 'Black Olga',
|
CivilianSedan_Black: 'Black Olga',
|
||||||
@@ -73,28 +83,14 @@ module.exports = {
|
|||||||
|
|
||||||
const channel = client.GetChannel(guild.killfeedChannel);
|
const channel = client.GetChannel(guild.killfeedChannel);
|
||||||
|
|
||||||
let templateKilled = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) with (.*) from (.*) meters /g;
|
const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
||||||
let template = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
|
||||||
let templateDEAD = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
|
||||||
let explosionTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by with (.*)/g;
|
|
||||||
let landMineTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by LandMineTrap/g;
|
|
||||||
let meleeTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*)/g;
|
|
||||||
let vehicleTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by (.*) with TransportHit/g;
|
|
||||||
|
|
||||||
let killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
|
||||||
line.includes('hit by Player') && !line.includes('meters') ? Templates.Melee : // Missing meters indicates it was a melee attack.
|
line.includes('hit by Player') && !line.includes('meters') ? Templates.Melee : // Missing meters indicates it was a melee attack.
|
||||||
line.includes('hit by Player') ? Templates.HitBy :
|
line.includes('hit by Player') ? Templates.HitBy :
|
||||||
line.includes('killed by Player') ? Templates.Killed :
|
line.includes('killed by Player') ? Templates.Killed :
|
||||||
line.includes('TransportHit') ? Templates.Vehicle :
|
line.includes('TransportHit') ? Templates.Vehicle :
|
||||||
line.includes('killed by LandMineTrap') ? Templates.LandMine : Templates.Explosion;
|
line.includes('killed by LandMineTrap') ? Templates.LandMine : Templates.Explosion;
|
||||||
|
|
||||||
let data = killedBy == Templates.HitByAndDead ? [...line.matchAll(templateDEAD)][0] :
|
let data = [...line.matchAll(TemplateExpressions[killedBy])][0];
|
||||||
killedBy == Templates.HitBy ? [...line.matchAll(template)][0] :
|
|
||||||
killedBy == Templates.Killed ? [...line.matchAll(templateKilled)][0] :
|
|
||||||
killedBy == Templates.LandMine ? [...line.matchAll(landMineTemplate)][0] :
|
|
||||||
killedBy == Templates.Melee ? [...line.matchAll(meleeTemplate)][0] :
|
|
||||||
killedBy == Templates.Vehicle ? [...line.matchAll(vehicleTemplate)][0] :
|
|
||||||
[...line.matchAll(explosionTemplate)][0];
|
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
@@ -107,7 +103,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add additional data
|
// Add additional data
|
||||||
if (killedBy == Templates.HitBy || killedBy == Templates.HitByAndDead || killedBy == Templates.Melee) {
|
if ([Templates.HitBy, Templates.HitByAndDead, Templates.Melee].includes(killedBy)) {
|
||||||
info.killer = data[6];
|
info.killer = data[6];
|
||||||
info.killerID = data[7];
|
info.killerID = data[7];
|
||||||
info.killerPOS = data[8].split(', ').map(v => parseFloat(v));
|
info.killerPOS = data[8].split(', ').map(v => parseFloat(v));
|
||||||
@@ -134,6 +130,7 @@ module.exports = {
|
|||||||
let tempDest;
|
let tempDest;
|
||||||
let lastDist = 1000000;
|
let lastDist = 1000000;
|
||||||
let destination_dir;
|
let destination_dir;
|
||||||
|
if (showCoords) { // Only calculate if showing coords, very tiny minor optimization... probably amounts to nothing.
|
||||||
for (let i = 0; i < destinations.length; i++) {
|
for (let i = 0; i < destinations.length; i++) {
|
||||||
let { distance, theta, dir } = calculateVector(info.victimPOS, destinations[i].coord);
|
let { distance, theta, dir } = calculateVector(info.victimPOS, destinations[i].coord);
|
||||||
if (distance < lastDist) {
|
if (distance < lastDist) {
|
||||||
@@ -142,9 +139,11 @@ module.exports = {
|
|||||||
destination_dir = dir;
|
destination_dir = dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const destination = lastDist > 500 ? `${destination_dir} of ${tempDest}` : `Near ${tempDest}`;
|
const destination = lastDist > 500 ? `${destination_dir} of ${tempDest}` : `Near ${tempDest}`;
|
||||||
|
|
||||||
|
if ([Templates.LandMine, Templates.Explosion, Templates.Vehicle].includes(killedBy))
|
||||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, client.config.Nitrado.ServerID);
|
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, client.config.Nitrado.ServerID);
|
||||||
|
|||||||
Reference in new issue
Block a user