Partial refactoring/bug fix w/ session time correction
This commit is contained in:
6 files changed
+141
-143
No files matched your search
@@ -1,15 +1,14 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
||||
SendConnectionLogs: async (client, guildId, data) => {
|
||||
|
||||
let guild = await client.GetGuild(guildId);
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
|
||||
let connectionLog = new EmbedBuilder()
|
||||
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
||||
@@ -17,7 +16,7 @@ module.exports = {
|
||||
|
||||
if (!data.connected) {
|
||||
if (!(data.lastConnectionDate == null)) {
|
||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime()/1000);
|
||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
||||
let sessionTime = client.secondsToDhms(unixTime - oldUnixTime);
|
||||
connectionLog.addFields({ name: '**Session Time**', value: `**${sessionTime}**`, inline: false });
|
||||
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
||||
@@ -28,7 +27,7 @@ module.exports = {
|
||||
|
||||
DetectCombatLog: async (client, guildId, data) => {
|
||||
if (data.lastDamageDate == null) return;
|
||||
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
|
||||
let diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
||||
@@ -36,21 +35,21 @@ module.exports = {
|
||||
// If diff is greater than 5 minutes, not a combat log
|
||||
// or if death after last combat
|
||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||
if (diffSeconds > (5 * 60)) return;
|
||||
if (diffSeconds > 5 * 60) return;
|
||||
|
||||
let guild = await client.GetGuild(guildId);
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return;
|
||||
|
||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
|
||||
let combatLog = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Red)
|
||||
.setDescription(`**NOTICE:**\n**${data.player}** has combat logged at <t:${unixTime}> when fighting **${data.lastHitBy}\nLocation [${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`);
|
||||
|
||||
|
||||
if (client.exists(guild.adminRole)) channel.send({ content: `<@&${guild.adminRole}>` });
|
||||
|
||||
return channel.send({ embeds: [combatLog] });
|
||||
}
|
||||
}
|
||||
};
|
||||
+47
-45
@@ -18,10 +18,10 @@ module.exports = {
|
||||
const deadTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
||||
|
||||
if (line.includes(' connected')) {
|
||||
let data = [...line.matchAll(connectTemplate)][0];
|
||||
const data = [...line.matchAll(connectTemplate)][0];
|
||||
if (!data) return stats;
|
||||
|
||||
let info = {
|
||||
const info = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
@@ -29,17 +29,19 @@ module.exports = {
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID)
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
let playerStatIndex = stats.indexOf(playerStat);
|
||||
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
|
||||
playerStat.lastConnectionDate = await client.getDateEST(info.time);;
|
||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
|
||||
const newDt = await client.getDateEST(info.time);
|
||||
|
||||
playerStat.lastConnectionDate = newDt;
|
||||
playerStat.connected = true;
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
if (playerStatIndex === -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
|
||||
SendConnectionLogs(client, guildId, {
|
||||
await SendConnectionLogs(client, guildId, {
|
||||
time: info.time,
|
||||
player: info.player,
|
||||
connected: true,
|
||||
@@ -48,25 +50,25 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (line.includes(' disconnected')) {
|
||||
let data = [...line.matchAll(disconnectTemplate)][0];
|
||||
const data = [...line.matchAll(disconnectTemplate)][0];
|
||||
if (!data) return stats;
|
||||
|
||||
let info = {
|
||||
const info = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
}
|
||||
};
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID)
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
let playerStatIndex = stats.indexOf(playerStat);
|
||||
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
|
||||
let newDt = await client.getDateEST(info.time);
|
||||
let unixTime = Math.round(newDt.getTime()/1000); // Seconds
|
||||
let oldUnixTime = Math.round(playerStat.lastConnectionDate.getTime()/1000); // Seconds
|
||||
let sessionTimeSeconds = unixTime - oldUnixTime;
|
||||
const newDt = await client.getDateEST(info.time);
|
||||
const unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
||||
const oldUnixTime = Math.round(playerStat.lastConnectionDate.getTime() / 1000); // Seconds
|
||||
const sessionTimeSeconds = unixTime - oldUnixTime;
|
||||
if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0;
|
||||
|
||||
playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds;
|
||||
@@ -74,10 +76,10 @@ module.exports = {
|
||||
playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime;
|
||||
playerStat.connected = false;
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
if (playerStatIndex === -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
|
||||
SendConnectionLogs(client, guildId, {
|
||||
await SendConnectionLogs(client, guildId, {
|
||||
time: info.time,
|
||||
player: info.player,
|
||||
connected: false,
|
||||
@@ -95,10 +97,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (line.includes('pos=<') && !line.includes('hit by')) {
|
||||
let data = [...line.matchAll(positionTemplate)][0];
|
||||
const data = [...line.matchAll(positionTemplate)][0];
|
||||
if (!data) return stats;
|
||||
|
||||
let info = {
|
||||
const info = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
@@ -107,11 +109,11 @@ module.exports = {
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID)
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
let playerStatIndex = stats.indexOf(playerStat);
|
||||
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
||||
|
||||
|
||||
playerStat.lastPos = playerStat.pos;
|
||||
playerStat.pos = info.pos;
|
||||
playerStat.lastTime = playerStat.time;
|
||||
@@ -119,7 +121,7 @@ module.exports = {
|
||||
playerStat.time = `${info.time} EST`;
|
||||
playerStat.date = await client.getDateEST(info.time);
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
if (playerStatIndex === -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
|
||||
if (line.includes('hit by') || line.includes('killed by')) return stats; // prevent additional information from being fed to Alarms & UAVs
|
||||
@@ -130,33 +132,32 @@ module.exports = {
|
||||
playerID: info.playerID,
|
||||
pos: info.pos,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (line.includes('hit by Player')) {
|
||||
let data = line.includes('(DEAD)') ? [...line.matchAll(deadTemplate)][0] : [...line.matchAll(damageTemplate)][0];
|
||||
const data = line.includes('(DEAD)') ? [...line.matchAll(deadTemplate)][0] : [...line.matchAll(damageTemplate)][0];
|
||||
if (!data) return stats;
|
||||
|
||||
let info = {
|
||||
const info = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
attacker: data[6],
|
||||
attackerID: data[7]
|
||||
}
|
||||
};
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID)
|
||||
let playerStat = stats.find(stat => stat.playerID == info.playerID);
|
||||
let playerStatIndex = stats.indexOf(playerStat);
|
||||
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
if (playerStat === undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
|
||||
let newDt = await client.getDateEST(info.time);
|
||||
const newDt = await client.getDateEST(info.time);
|
||||
|
||||
playerStat.lastDamageDate = newDt;
|
||||
playerStat.lastHitBy = info.attacker;
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
if (playerStatIndex === -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
}
|
||||
|
||||
@@ -168,12 +169,13 @@ module.exports = {
|
||||
|
||||
const data = await FetchServerSettings(client, 'HandleActivePlayersList'); // Fetch server status
|
||||
|
||||
if (data && data != 1) {
|
||||
if (data && data !== 1) {
|
||||
let hostname = data.data.gameserver.settings.config.hostname;
|
||||
let map = data.data.gameserver.settings.config.mission.slice(12);
|
||||
let map = data.data.gameserver.settings.config.mission.slice(12);
|
||||
let status = data.data.gameserver.status;
|
||||
let slots = data.data.gameserver.slots;
|
||||
|
||||
let slots = data.data.gameserver.slots;
|
||||
let playersOnline = data.data.gameserver.query.player_current;
|
||||
|
||||
let statusEmoji;
|
||||
let statusText;
|
||||
if (status === "started") {
|
||||
@@ -189,13 +191,13 @@ module.exports = {
|
||||
statusEmoji = "❓"; // Unknown status
|
||||
statusText = "Unknown Status";
|
||||
}
|
||||
|
||||
|
||||
let guild = await client.GetGuild(guildId);
|
||||
if (!client.exists(guild.playerstats)) guild.playerstats = [];
|
||||
if (!client.exists(guild.activePlayersChannel)) return;
|
||||
|
||||
const channel = client.GetChannel(guild.activePlayersChannel);
|
||||
let activePlayers = guild.playerstats.filter(p => p.connected == true);
|
||||
let activePlayers = guild.playerstats.filter(p => p.connected === true);
|
||||
|
||||
let des = ``;
|
||||
for (let i = 0; i < activePlayers.length; i++) {
|
||||
@@ -204,11 +206,11 @@ module.exports = {
|
||||
const nodes = activePlayers.length === 0;
|
||||
const PlayersEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle(`Online List \` ${activePlayers.length} \` Player${activePlayers.length>1?'s':''} Online`)
|
||||
.setTitle(`Online List \` ${playersOnline} \` Player${playersOnline > 1 ? 's' : ''} Online`)
|
||||
.addFields(
|
||||
{ name: 'Server:', value: `\` ${hostname} \``, inline: false },
|
||||
{ name: 'Server:', value: `\` ${hostname} \``, inline: false },
|
||||
{ name: 'Map:', value: `\` ${map} \``, inline: true },
|
||||
{ name: 'Status:', value: `\` ${statusEmoji} ${statusText} \``, inline: true },
|
||||
{ name: 'Status:', value: `\` ${statusEmoji} ${statusText} \``, inline: true },
|
||||
{ name: 'Slots:', value: `\` ${slots} \``, inline: true }
|
||||
);
|
||||
|
||||
@@ -216,13 +218,13 @@ module.exports = {
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTimestamp()
|
||||
.setTitle(`Players Online:`)
|
||||
.setDescription(des || (nodes ? "No Players Online :(" : ""))
|
||||
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
||||
|
||||
if (lastSendMessage) lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous message before reprinting
|
||||
|
||||
return channel.send({ embeds: [PlayersEmbed, activePlayersEmbed] }).then(sentMessage =>
|
||||
return channel.send({ embeds: [PlayersEmbed, activePlayersEmbed] }).then(sentMessage =>
|
||||
lastSendMessage = sentMessage
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+3
-3
@@ -75,11 +75,11 @@ module.exports = {
|
||||
}).then(response =>
|
||||
response.json().then(data => data)
|
||||
).then(res => res);
|
||||
|
||||
|
||||
const stream = fs.createWriteStream(outputDir);
|
||||
if (!res.data || !res.data.token) {
|
||||
client.error(`Error downloading File "${filename}":`);
|
||||
client.error(res);
|
||||
const errorText = await res.text();
|
||||
client.error(`Error downloading File "${filename}": message: ${errorText}: DownloadNitradoFile`);
|
||||
return 1;
|
||||
}
|
||||
const { body } = await fetch(res.data.token.url);
|
||||
|
||||
Reference in new issue
Block a user