debug/readLogs
This commit is contained in:
7 files changed
+47
-28
No files matched your search
@@ -1,8 +1,9 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { GetGuild } = require('../database/guild');
|
||||||
|
|
||||||
module.exports = async (client, member) => {
|
module.exports = async (client, member) => {
|
||||||
|
|
||||||
let GuildDB = await client.GetGuild(member.guild.id);
|
let GuildDB = await GetGuild(client, member.guild.id);
|
||||||
const channel = client.GetChannel(GuildDB.welcomeChannel);
|
const channel = client.GetChannel(GuildDB.welcomeChannel);
|
||||||
|
|
||||||
let embed = new EmbedBuilder()
|
let embed = new EmbedBuilder()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const { GetGuild } = require('../database/guild');
|
||||||
|
|
||||||
module.exports = async (client, interaction) => {
|
module.exports = async (client, interaction) => {
|
||||||
if (interaction.isCommand()) return;
|
if (interaction.isCommand()) return;
|
||||||
/*
|
/*
|
||||||
@@ -5,7 +7,7 @@ module.exports = async (client, interaction) => {
|
|||||||
from any command
|
from any command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let GuildDB = await client.GetGuild(interaction.guildId);
|
let GuildDB = await GetGuild(client, interaction.guildId);
|
||||||
const interactionName = interaction.customId.split("-")[0];
|
const interactionName = interaction.customId.split("-")[0];
|
||||||
let interactionHandler = client.interactionHandlers.get(interactionName);
|
let interactionHandler = client.interactionHandlers.get(interactionName);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const { HandleActivePlayersList } = require('./util/LogsHandler');
|
|||||||
|
|
||||||
// Log all uncaught exceptions before killing process.
|
// Log all uncaught exceptions before killing process.
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
|
console.trace(error);
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
// Asynchronously write the error message to a log file using Promises
|
// Asynchronously write the error message to a log file using Promises
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
|||||||
+21
-7
@@ -56,7 +56,7 @@ class DayzRBot extends Client {
|
|||||||
this.ws.on("INTERACTION_CREATE", async (interaction) => {
|
this.ws.on("INTERACTION_CREATE", async (interaction) => {
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
if (interaction.type != 3) {
|
if (interaction.type != 3) {
|
||||||
let GuildDB = await this.GetGuild(interaction.guild_id);
|
let GuildDB = await GetGuild(this, interaction.guild_id);
|
||||||
|
|
||||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||||
const guild = this.guilds.cache.get(GuildDB.serverID);
|
const guild = this.guilds.cache.get(GuildDB.serverID);
|
||||||
@@ -157,7 +157,11 @@ class DayzRBot extends Client {
|
|||||||
let logIndex = lines.indexOf(history.lastLog);
|
let logIndex = lines.indexOf(history.lastLog);
|
||||||
|
|
||||||
if (this.playerSessions.size === 0) {
|
if (this.playerSessions.size === 0) {
|
||||||
s.map(p => p.connected = false); // assume all players not connected on init only.
|
let players = await this.dbo.collection('players').find({"connected": true}).toArray();
|
||||||
|
players.map(p => p.connected = false); // assume all players not connected on init only.
|
||||||
|
for (let i = 0; i < players.length; i++) {
|
||||||
|
UpdatePlayer(this, players[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = logIndex + 1; i < lines.length; i++) {
|
for (let i = logIndex + 1; i < lines.length; i++) {
|
||||||
@@ -179,19 +183,31 @@ class DayzRBot extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle alarm pings
|
// Handle alarm pings
|
||||||
|
const maxEmbed = 10;
|
||||||
for (const [channel_id, data] of Object.entries(this.alarmPingQueue)) {
|
for (const [channel_id, data] of Object.entries(this.alarmPingQueue)) {
|
||||||
const channel = this.GetChannel(channel_id);
|
const channel = this.GetChannel(channel_id);
|
||||||
if (!channel) continue;
|
if (!channel) continue;
|
||||||
for (const [role, embeds] of Object.entries(data)) {
|
for (const [role, embeds] of Object.entries(data)) {
|
||||||
|
if (embeds.length > maxEmbed) {
|
||||||
|
let embedArrays = [];
|
||||||
|
while (embeds.length > maxEmbed)
|
||||||
|
embedArrays.push(embeds.splice(0, maxEmbed));
|
||||||
|
|
||||||
|
for (let i = 0; i < embedArrays.length; i++) {
|
||||||
|
if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
||||||
|
else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (role == '-no-role-ping-') channel.send({ embeds: embeds });
|
if (role == '-no-role-ping-') channel.send({ embeds: embeds });
|
||||||
else channel.send({ content: `<@&${role}>`, embeds: embeds });
|
else channel.send({ content: `<@&${role}>`, embeds: embeds });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.alarmPingQueue = {};
|
this.alarmPingQueue = {};
|
||||||
|
|
||||||
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
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 previouslyConnected = await this.dbo.collection('players').find({"connected": true}).toArray(); // All players with connection log captured above and no disconnect log
|
||||||
let lastDetectedTime;
|
let lastDetectedTime;
|
||||||
|
|
||||||
for (let i = lines.length - 1; i > 0; i--) {
|
for (let i = lines.length - 1; i > 0; i--) {
|
||||||
@@ -214,7 +230,7 @@ class DayzRBot extends Client {
|
|||||||
lastDetectedTime = await this.getDateEST(info.time);
|
lastDetectedTime = await this.getDateEST(info.time);
|
||||||
|
|
||||||
let playerStat = await this.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await this.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!this.exits(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, this.config.Nitrado.ServerID);
|
if (!this.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, this.config.Nitrado.ServerID);
|
||||||
|
|
||||||
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
||||||
|
|
||||||
@@ -262,7 +278,7 @@ class DayzRBot extends Client {
|
|||||||
const filename = settings.game_specific.log_files.sort((a, b) => a.length - b.length)[0];
|
const filename = settings.game_specific.log_files.sort((a, b) => a.length - b.length)[0];
|
||||||
const path = `${settings.game_specific.path.slice(0, -1)}${filename.split(settings.game)[1]}`;
|
const path = `${settings.game_specific.path.slice(0, -1)}${filename.split(settings.game)[1]}`;
|
||||||
|
|
||||||
let guild = await c.GetGuild(c, c.config.GuildID);
|
let guild = await GetGuild(c, c.config.GuildID);
|
||||||
|
|
||||||
await DownloadNitradoFile(c, path, './logs/server-logs.ADM').then(async (status) => {
|
await DownloadNitradoFile(c, path, './logs/server-logs.ADM').then(async (status) => {
|
||||||
if (status == 1) return c.error('...Failed to Download logs...');
|
if (status == 1) return c.error('...Failed to Download logs...');
|
||||||
@@ -416,8 +432,6 @@ class DayzRBot extends Client {
|
|||||||
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetGuild(GuildId) { return await GetGuild(this, GuildId) }
|
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
this.login(this.config.Token);
|
this.login(this.config.Token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { calculateVector } = require('./vector');
|
const { calculateVector } = require('./vector');
|
||||||
const { destinations } = require('../database/destinations');
|
const { destinations } = require('../database/destinations');
|
||||||
|
const { GetGuild } = require('../database/guild');
|
||||||
|
|
||||||
// Private functions (only called locally)
|
// Private functions (only called locally)
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
client.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {$set: { "server.uavs": uavs }}, (err, res) => {
|
client.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, {$set: { "server.uavs": uavs }}, (err, res) => {
|
||||||
if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err);
|
if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -167,7 +168,7 @@ module.exports = {
|
|||||||
|
|
||||||
KillInAlarm: async (client, guildId, data) => {
|
KillInAlarm: async (client, guildId, data) => {
|
||||||
|
|
||||||
let guild = await client.GetGuild(guildId);
|
let guild = await GetGuild(client, guildId);
|
||||||
|
|
||||||
for (let i = 0; i < guild.alarms.length; i++) {
|
for (let i = 0; i < guild.alarms.length; i++) {
|
||||||
let alarm = guild.alarms[i];
|
let alarm = guild.alarms[i];
|
||||||
|
|||||||
+12
-12
@@ -47,7 +47,7 @@ module.exports = {
|
|||||||
let diedTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) died\. Stats> Water: (.*) Energy: (.*) Bleed sources: (.*)/g;
|
let diedTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) died\. Stats> Water: (.*) Energy: (.*) Bleed sources: (.*)/g;
|
||||||
|
|
||||||
let data = line.includes('>) died.') ? [...line.matchAll(diedTemplate)][0] : [...line.matchAll(killedByZmb)][0];
|
let data = line.includes('>) died.') ? [...line.matchAll(diedTemplate)][0] : [...line.matchAll(killedByZmb)][0];
|
||||||
if (!data) return stats;
|
if (!data) return;
|
||||||
|
|
||||||
let info = {
|
let info = {
|
||||||
time: data[1],
|
time: data[1],
|
||||||
@@ -59,7 +59,7 @@ module.exports = {
|
|||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exits(victimStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client3.config.Nitrado.ServerID);
|
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
||||||
|
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ module.exports = {
|
|||||||
|
|
||||||
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.exits(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);
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
|
|
||||||
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
||||||
@@ -158,15 +158,15 @@ module.exports = {
|
|||||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||||
return await UpdatePlayer(client, victimStat);
|
return await UpdatePlayer(client, victimStat);
|
||||||
}
|
}
|
||||||
killerStat
|
|
||||||
KillInAlarm(client, guildId, info); // check if kill happened in a no kill zone
|
KillInAlarm(client, guild.serverID, 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;
|
if (!client.exists(info.victim) || !client.exists(info.victimID) || !client.exists(info.killer) || !client.exists(info.killerID)) return stats;
|
||||||
|
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||||
let killerStat = await client.dbo.collection("players").findOne({"playerID": info.killerID});
|
let killerStat = await client.dbo.collection("players").findOne({"playerID": info.killerID});
|
||||||
if (!client.exits(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);
|
||||||
if (!client.exits(killerStat)) killerStat = getDefaultPlayer(info.killer, info.killerID, client.config.Nitrado.ServerID);
|
if (!client.exists(killerStat)) killerStat = getDefaultPlayer(info.killer, info.killerID, client.config.Nitrado.ServerID);
|
||||||
|
|
||||||
killerStat.kills++;
|
killerStat.kills++;
|
||||||
killerStat.killStreak++;
|
killerStat.killStreak++;
|
||||||
@@ -191,21 +191,21 @@ module.exports = {
|
|||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
banking = await createUser(interaction.member.user.id, guildId, guild.startingBalance, client)
|
banking = await createUser(interaction.member.user.id, guild.serverID, guild.startingBalance, client)
|
||||||
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
if (!client.exists(banking)) return client.sendInternalError(interaction, err);
|
||||||
}
|
}
|
||||||
banking = banking.user;
|
banking = banking.user;
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[guildId])) {
|
if (!client.exists(banking.guilds[ guild.serverID])) {
|
||||||
const success = addUser(banking.guilds, guildId, interaction.member.user.id, client, guild.startingBalance);
|
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, client, guild.startingBalance);
|
||||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBalance = banking.guilds[guildId].balance + totalBounty;
|
const newBalance = banking.guilds[ guild.serverID].balance + totalBounty;
|
||||||
|
|
||||||
await client.dbo.collection("users").updateOne({ "user.userID": killerStat.discordID }, {
|
await client.dbo.collection("users").updateOne({ "user.userID": killerStat.discordID }, {
|
||||||
$set: {
|
$set: {
|
||||||
[`user.guilds.${guildId}.balance`]: newBalance,
|
[`user.guilds.${ guild.serverID}.balance`]: newBalance,
|
||||||
}
|
}
|
||||||
}, (err, res) => {
|
}, (err, res) => {
|
||||||
if (err) return client.sendError(client.GetChannel(guild.killfeedChannel), `Killfeed Error: Updating killer bank balance\n${err}`);
|
if (err) return client.sendError(client.GetChannel(guild.killfeedChannel), `Killfeed Error: Updating killer bank balance\n${err}`);
|
||||||
|
|||||||
+5
-5
@@ -30,7 +30,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exits(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastConnectionDate = newDt;
|
playerStat.lastConnectionDate = newDt;
|
||||||
@@ -74,7 +74,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exits(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
||||||
|
|
||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
const unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
const unixTime = Math.round(newDt.getTime() / 1000); // Seconds
|
||||||
@@ -124,7 +124,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exits(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
||||||
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastPos = playerStat.pos;
|
playerStat.lastPos = playerStat.pos;
|
||||||
@@ -161,7 +161,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exits(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
||||||
|
|
||||||
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
||||||
playerStat.lastHitBy = info.attacker;
|
playerStat.lastHitBy = info.attacker;
|
||||||
@@ -203,7 +203,7 @@ module.exports = {
|
|||||||
if (!client.exists(guild.activePlayersChannel)) return;
|
if (!client.exists(guild.activePlayersChannel)) return;
|
||||||
|
|
||||||
const channel = client.GetChannel(guild.activePlayersChannel);
|
const channel = client.GetChannel(guild.activePlayersChannel);
|
||||||
let activePlayers = client.dbo.collection("players").find({"connected": true})
|
let activePlayers = await client.dbo.collection("players").find({"connected": true}).toArray();
|
||||||
|
|
||||||
let des = ``;
|
let des = ``;
|
||||||
for (let i = 0; i < activePlayers.length; i++) {
|
for (let i = 0; i < activePlayers.length; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user