dayz-logwatch.js gelöscht
This commit is contained in:
182
dayz-logwatch.js
182
dayz-logwatch.js
@@ -1,182 +0,0 @@
|
||||
const Tail = require('tail-file');
|
||||
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
const mytail = new Tail("C:\\Games\\DayZ\\servers\\0\\profiles\\DayZServer_x64.ADM"); // absolute or relative path
|
||||
|
||||
function sendHook(spieler = "n/a", cat = "Keine Kategorie", action = "Ohne Titel", time = "n/a", pos = "unbekannt", color = '1752220') {
|
||||
|
||||
let img = 'https://i.imgur.com/yTs8OxC.png';
|
||||
if(cat == 'Zusammenpacken' || cat == 'Platzieren' || cat == 'Bauen') img = 'https://i.imgur.com/mVXNURq.png';
|
||||
if(cat == 'Verbunden' || cat == 'Getrennt') img = 'https://i.imgur.com/UcD1qO4.png';
|
||||
if(cat == 'Selbstmord' || cat == 'Spielertod' || cat == 'Kill') img = 'https://i.imgur.com/8l0W4HT.png';
|
||||
|
||||
var params = {
|
||||
"username": 'DayZ Bot',
|
||||
"avatar_url": 'https://i.imgur.com/JcXleWu.png',
|
||||
embeds: [
|
||||
{
|
||||
"title": cat,
|
||||
|
||||
"color": color,
|
||||
"thumbnail": {
|
||||
"url": img,
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "Spieler",
|
||||
"value": spieler,
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Zeit",
|
||||
"value": time,
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Position",
|
||||
"value": pos,
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Aktion",
|
||||
"value": action
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
fetch('WEBHOOK URL', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(params)
|
||||
});
|
||||
console.log("Spieler: " + spieler + " | Kategorie: " + cat + " | Aktion: " + action + " | Zeit: " + time + " | Pos: " + pos);
|
||||
}
|
||||
|
||||
mytail.on('line', line => {
|
||||
if(!line || line == "") return;
|
||||
|
||||
let checkline = line.toLowerCase();
|
||||
let entry = line.replace(/ *\(id=[^)]*\) */g, "")
|
||||
|
||||
let tmp = entry.split('"');
|
||||
let player = String(tmp[1]);
|
||||
let action = String(tmp[2]);
|
||||
let time = tmp[0].split('|')[0].split(" ")[0].split(",");
|
||||
let cat = "Keine Kategorie";
|
||||
let pos = "unbekannt";
|
||||
|
||||
//pos
|
||||
if(checkline.indexOf("pos=<") > 0) {
|
||||
pos = checkline.split("pos=<")[1].split(">)")[0];
|
||||
}
|
||||
// building
|
||||
if(checkline.indexOf(">)built") > 0) {
|
||||
return;
|
||||
cat = "Bauen";
|
||||
if(checkline.indexOf("on") > 0 && checkline.indexOf("with") > 0) {
|
||||
action = action.replace("Built ","Hat Objekt ");
|
||||
action = action.replace(" on "," auf Objekt ");
|
||||
action = action.replace(" with "," mit Werkzeug ");
|
||||
action = action + " gebaut";
|
||||
}
|
||||
sendHook(String(player), String(cat), String(action), String(time), pos, '16705372');
|
||||
return;
|
||||
}
|
||||
// placing
|
||||
if(checkline.indexOf("placed") > 0) {
|
||||
return;
|
||||
cat = "Platzieren";
|
||||
action = "Hat Objekt " + line.split("placed")[1] + " platziert";
|
||||
sendHook(String(player), String(cat), String(action), String(time), pos, '16705372');
|
||||
return;
|
||||
}
|
||||
// packing
|
||||
if(checkline.indexOf(">) packed") > 0) {
|
||||
return;
|
||||
cat = "Zusammenpacken";
|
||||
action = "Hat Objekt " + action.split("packed")[1].split(" ")[1] + " zusammengepackt";
|
||||
sendHook(String(player), String(cat), String(action), String(time), pos, '16705372');
|
||||
return;
|
||||
}
|
||||
// connect
|
||||
if(checkline.indexOf("is connected (id=") > 0) {
|
||||
cat = "Verbunden";
|
||||
sendHook(String(player), String(cat), "Der Spieler hat sich eingeloggt.", String(time), pos, '1752220');
|
||||
return;
|
||||
}
|
||||
// disconnect
|
||||
if(checkline.indexOf("has been disconnected") > 0) {
|
||||
cat = "Getrennt";
|
||||
sendHook(String(player), String(cat), "Der Spieler hat die Verbindung getrennt.", String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// bewusstlos
|
||||
if(checkline.indexOf(">) is unconscious") > 0) {
|
||||
cat = "Bewusstlos";
|
||||
sendHook(String(player), String(cat), "Der Spieler ist bewusstlos geworden", String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// bewusstlos vorbei
|
||||
if(checkline.indexOf(">) regained consciousness") > 0) {
|
||||
cat = "Bewusstlos";
|
||||
sendHook(String(player), String(cat), "Der Spieler ist wieder bei Bewusstsein", String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// explosion
|
||||
if(checkline.indexOf("hit by explosion") > 0) {
|
||||
cat = "Explosion";
|
||||
sendHook(String(player), String(cat), "Der Spieler wurde von einer Explosion getroffen", String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// suicid
|
||||
if(checkline.indexOf(") committed suicide") > 0) {
|
||||
cat = "Selbstmord";
|
||||
sendHook(String(player), String(cat), "hat sich selbst umgebracht.", String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// died
|
||||
if(checkline.indexOf(">) died") > 0) {
|
||||
cat = "Spielertod";
|
||||
action = line.split("died.")[1].trim().replace("Stats> ","");
|
||||
sendHook(String(player), String(cat), "ist gestorben: " + String(action), String(time), pos, '10038562');
|
||||
return;
|
||||
}
|
||||
// kill
|
||||
if(checkline.indexOf(">) killed by") > 0 && checkline.indexOf("from") > 0 && checkline.indexOf("with") > 0 && checkline.indexOf("meter") > 0) {
|
||||
cat = "Kill";
|
||||
action = entry.split("killed")[1].replace("by Player","").replaceAll('"','').trim();;
|
||||
action = player + " wurde von " + action;
|
||||
action = action.replace("with"," mit Waffe");
|
||||
action = action.replace("from","aus");
|
||||
action = action.replace("meters","Metern");
|
||||
action = action + " umgebracht";
|
||||
sendHook(String(player), String(cat), String(action), String(time), pos, '10038562');
|
||||
rcon.send("say -1 " + action);
|
||||
return;
|
||||
}
|
||||
// rais flag
|
||||
if(entry.indexOf("has raised") > 0 && entry.indexOf("TerritoryFlag") > 0 ) {
|
||||
cat = "Fahne gehisst";
|
||||
action = action.replace("has raised","Hat eine Fahne mit Typ");
|
||||
action = action.split("TerritoryFlag")[0];
|
||||
action = action.replace(" on ", " gehisst");
|
||||
sendHook(String(player), String(cat), String(action), String(time), pos, '16705372');
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mytail.on('ready', fd => console.log("Logreader ready") );
|
||||
|
||||
mytail.on('restart', reason => {
|
||||
if( reason == 'PRIMEFOUND' ) console.log("Now we can finally start tailing. File has appeared");
|
||||
if( reason == 'NEWPRIME' ) console.log("We will switch over to the new file now");
|
||||
if( reason == 'TRUNCATE' ) console.log("The file got smaller. I will go up and continue");
|
||||
if( reason == 'CATCHUP' ) console.log("We found a start in an earlier file and are now moving to the next one in the list");
|
||||
});
|
||||
|
||||
mytail.start();
|
||||
Reference in New Issue
Block a user