debug and combat log detection
This commit is contained in:
8 files changed
+125
-13
No files matched your search
+1
-1
@@ -135,7 +135,7 @@ module.exports = {
|
|||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else banking = banking.banking;
|
} else banking = banking.user;
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ module.exports = {
|
|||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else banking = banking.banking;
|
} else banking = banking.user;
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
const { EmbedBuilder, } = require('discord.js');
|
||||||
|
const { Inventory, addInventory } = require('../structures/inventory');
|
||||||
|
const { Bank, addBank } = require('../structures/bank');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "collect-income",
|
||||||
|
debug: false,
|
||||||
|
global: false,
|
||||||
|
description: "Collect Your Income",
|
||||||
|
usage: "",
|
||||||
|
permissions: {
|
||||||
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
member: [],
|
||||||
|
},
|
||||||
|
options: [],
|
||||||
|
SlashCommand: {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {require("../structures/QuarksBot")} client
|
||||||
|
* @param {import("discord.js").Message} message
|
||||||
|
* @param {string[]} args
|
||||||
|
* @param {*} param3
|
||||||
|
*/
|
||||||
|
run: async (client, interaction, args, { GuildDB }) => {
|
||||||
|
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||||
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasIncomeRole = GuildDB.incomeRoles.some(data => {
|
||||||
|
if (interaction.member.roles.includes(data.role)) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasIncomeRole) {
|
||||||
|
const error = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Red)
|
||||||
|
.setTitle('No Income!')
|
||||||
|
.setDescription(`It appears you don't have any roles to earn income.`)
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [error] })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
+2
-2
@@ -94,8 +94,8 @@ module.exports = {
|
|||||||
|
|
||||||
// Register inventory for user
|
// Register inventory for user
|
||||||
let newBank = new User();
|
let newBank = new User();
|
||||||
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
|
await newBank.createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
|
||||||
newBank.save().catch(err => {
|
await newBank.save().catch(err => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "stats",
|
name: "player-list",
|
||||||
debug: true,
|
debug: false,
|
||||||
global: true,
|
global: false,
|
||||||
description: "check bot statistics",
|
description: "get current online players",
|
||||||
usage: "",
|
usage: "",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ module.exports = {
|
|||||||
|
|
||||||
let bankingReset = false;
|
let bankingReset = false;
|
||||||
if (!banking) bankingReset = true
|
if (!banking) bankingReset = true
|
||||||
else banking = banking.banking
|
else banking = banking.user
|
||||||
|
|
||||||
if (!bankingReset) {
|
if (!bankingReset) {
|
||||||
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
|
|||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const { REST } = require('@discordjs/rest');
|
const { REST } = require('@discordjs/rest');
|
||||||
const Logger = require("../util/Logger");
|
const Logger = require("../util/Logger");
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -186,7 +187,7 @@ class DayzArmbands extends Client {
|
|||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else banking = banking.banking;
|
} else banking = banking.user;
|
||||||
|
|
||||||
if (!this.exists(banking.guilds[guild.serverID])) {
|
if (!this.exists(banking.guilds[guild.serverID])) {
|
||||||
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, this, guild.startingBalance);
|
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, this, guild.startingBalance);
|
||||||
@@ -310,6 +311,30 @@ class DayzArmbands extends Client {
|
|||||||
if (this.exists(channel)) channel.send({ embeds: [connectionLog] });
|
if (this.exists(channel)) channel.send({ embeds: [connectionLog] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async detectCombatLog(guildId, data) {
|
||||||
|
if (data.lastDamageDate == null) return;
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
let newDt = new Date(`${today.toLocaleDateString('default', { month: 'long' })} ${today.getDate()}, ${today.getFullYear()} ${info.time} EST`);
|
||||||
|
|
||||||
|
let diffMs = (newDt - data.lastDamageDate)
|
||||||
|
let diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
|
||||||
|
|
||||||
|
if (diffMins > 5) return;
|
||||||
|
|
||||||
|
let guild = await this.GetGuild(guildId);
|
||||||
|
if (!this.exists(guild.connectionLogsChannel)) return;
|
||||||
|
const channel = this.channels.cache.get(guild.connectionLogsChannel);
|
||||||
|
|
||||||
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
|
let combatLog = new EmbedBuilder()
|
||||||
|
.setColor(this.config.Colors.Red)
|
||||||
|
.setDescription(`**NOTICE:**\n**${info.player}** has combat logged at <t:${unixTime}> when fighting **${info.lastHitBy}**`);
|
||||||
|
|
||||||
|
return channel.send({ embeds: {combatLog} });
|
||||||
|
}
|
||||||
|
|
||||||
async handlePlayerLogs(guildId, line) {
|
async handlePlayerLogs(guildId, line) {
|
||||||
|
|
||||||
let guild = await this.GetGuild(guildId);
|
let guild = await this.GetGuild(guildId);
|
||||||
@@ -318,6 +343,7 @@ class DayzArmbands extends Client {
|
|||||||
const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g;
|
const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g;
|
||||||
const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g;
|
const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g;
|
||||||
const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
||||||
|
const damangeTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP: (.*)\] hit by Player \"(.*)\"\(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
||||||
|
|
||||||
if (line.includes('connected')) {
|
if (line.includes('connected')) {
|
||||||
let data = [...line.matchAll(connectTemplate)][0];
|
let data = [...line.matchAll(connectTemplate)][0];
|
||||||
@@ -388,9 +414,16 @@ class DayzArmbands extends Client {
|
|||||||
this.sendConnectionLogs(guildId, {
|
this.sendConnectionLogs(guildId, {
|
||||||
time: info.time,
|
time: info.time,
|
||||||
player: info.player,
|
player: info.player,
|
||||||
conected: info.connected,
|
connected: info.connected,
|
||||||
lastConnectionDate: playerStat.lastConnectionDate,
|
lastConnectionDate: playerStat.lastConnectionDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.detectCombatLog(guildId, {
|
||||||
|
time: info.time,
|
||||||
|
player: info.player,
|
||||||
|
lastDamageDate: playerStat.lastDamageDate,
|
||||||
|
lastHitBy: playerStat.lastHitBy,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes('pos=<')) {
|
if (line.includes('pos=<')) {
|
||||||
@@ -427,6 +460,37 @@ class DayzArmbands extends Client {
|
|||||||
if (err) this.error(err);
|
if (err) this.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line.includes('hit by Player')) {
|
||||||
|
let data = [...line.matchAll(damangeTemplate)];
|
||||||
|
|
||||||
|
let info = {
|
||||||
|
time: data[1],
|
||||||
|
player: data[2],
|
||||||
|
playerID: data[3],
|
||||||
|
}
|
||||||
|
|
||||||
|
let playerStat = guild.playerstats.find(stat => stat.playerID == info.playerID)
|
||||||
|
let playerStatIndex = guild.playerstats.indexOf(playerStat);
|
||||||
|
if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
let newDt = new Date(`${today.toLocaleDateString('default', { month: 'long' })} ${today.getDate()}, ${today.getFullYear()} ${info.time} EST`);
|
||||||
|
|
||||||
|
playerStats.lastDamageDate = newDt;
|
||||||
|
playerStats.lastHitBy = data[6];
|
||||||
|
|
||||||
|
if (playerStatIndex == -1) guild.playerstats.push(playerStat);
|
||||||
|
else guild.playerstatus[playerStatIndex] = playerStat;
|
||||||
|
|
||||||
|
this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {
|
||||||
|
$set: {
|
||||||
|
"server.playerstats": guild.playerstats
|
||||||
|
}
|
||||||
|
}, function (err, res) {
|
||||||
|
if (err) this.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleActivePlayersList(guildId) {
|
async handleActivePlayersList(guildId) {
|
||||||
@@ -524,6 +588,7 @@ class DayzArmbands extends Client {
|
|||||||
// Connect to Mongo database.
|
// Connect to Mongo database.
|
||||||
this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 1000});
|
this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 1000});
|
||||||
this.dbo = this.db.db(dbo);
|
this.dbo = this.db.db(dbo);
|
||||||
|
mongoose.connect(`${mongoURI}/${dbo}`);
|
||||||
this.log('Successfully connected to mongoDB');
|
this.log('Successfully connected to mongoDB');
|
||||||
databaselogs.connected = true;
|
databaselogs.connected = true;
|
||||||
databaselogs.attempts = 0; // reset attempts
|
databaselogs.attempts = 0; // reset attempts
|
||||||
@@ -635,6 +700,7 @@ class DayzArmbands extends Client {
|
|||||||
botAdminRoles: [],
|
botAdminRoles: [],
|
||||||
playerstats: [],
|
playerstats: [],
|
||||||
alarms: [],
|
alarms: [],
|
||||||
|
incomeRoles: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,6 +718,8 @@ class DayzArmbands extends Client {
|
|||||||
worstDeathStreak: 0,
|
worstDeathStreak: 0,
|
||||||
pos: [],
|
pos: [],
|
||||||
lastConnectionDate: null,
|
lastConnectionDate: null,
|
||||||
|
lastDamageDate: null,
|
||||||
|
lastHitBy: null,
|
||||||
connected: false,
|
connected: false,
|
||||||
bounties: [],
|
bounties: [],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ userSchema.methods.createUser = function (userID, guildID, startingBalance, cash
|
|||||||
balance: startingBalance,
|
balance: startingBalance,
|
||||||
cash: cash,
|
cash: cash,
|
||||||
},
|
},
|
||||||
faction: "",
|
|
||||||
gamertag: ""
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user