Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0f59cc040 | ||
|
|
caf43aac4e | ||
|
|
bbe0fe5961 | ||
|
|
2cb409a36a | ||
|
|
7f675f4185 | ||
|
|
3c6faf7f75 | ||
|
|
64be8a5558 | ||
|
|
52c946bee5 | ||
|
|
14a8833f0d | ||
|
|
30acabde1d |
No files matched your search
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Execute command '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,33 @@
|
||||
const DayzR = require('./src/DayzRBot');
|
||||
const config = require('./config/config');
|
||||
const { GatewayIntentBits } = require('discord.js');
|
||||
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const { HandleActivePlayersList } = require('./util/LogsHandler');
|
||||
|
||||
// Log all uncaught exceptions before killing process.
|
||||
process.on('uncaughtException', async (error) => {
|
||||
console.trace(error);
|
||||
let d = new Date();
|
||||
// Asynchronously write the error message to a log file using Promises
|
||||
await new Promise((resolve, reject) => {
|
||||
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
||||
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
||||
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
||||
if (logErr) {
|
||||
console.error('Error writing uncaughtException to log file:', logErr);
|
||||
reject(logErr);
|
||||
process.exit()
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Now gracefully close the program
|
||||
process.exit()
|
||||
});
|
||||
|
||||
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
||||
client.build()
|
||||
+16
-7
@@ -133,17 +133,26 @@ module.exports = {
|
||||
return interaction.send({ embeds: [creditsEmbed] })
|
||||
} else if (args[0].name == 'stats') {
|
||||
const end = new Date().getTime();
|
||||
|
||||
const totalGuilds = await client.shard.fetchClientValues("guilds.cache.size").then(results => {
|
||||
return results.reduce((acc, guildCount) => acc + guildCount, 0);
|
||||
});
|
||||
|
||||
const totalUsers = await client.shard.broadcastEval(c => {
|
||||
c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
}).then(data => data.reduce((acc, memberCount) => acc + memberCount, 0));
|
||||
|
||||
const stats = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('DayZ Reforger Bot Statistics')
|
||||
.addFields(
|
||||
{ name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true },
|
||||
{ name: 'Users', value: `${client.users.cache.size}`, inline: true },
|
||||
{ name: 'Latency', value: `${end - start}ms`, inline: true },
|
||||
{ name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, inline: true },
|
||||
{ name: 'Bot Version', value: `${client.config.Dev} v${client.config.Version}`, inline: true },
|
||||
{ name: 'Discord Version', value: `Discord.js ${package.dependencies["discord.js"]}`, inline: true },
|
||||
{ name: 'MongoDB Version', value: `MongoDB ${package.dependencies.mongodb}`, inline: true},
|
||||
{ name: 'Guilds', value: `${totalGuilds}`, inline: false },
|
||||
{ name: 'Users', value: `${totalUsers}`, inline: false },
|
||||
{ name: 'Latency', value: `${end - start}ms`, inline: false },
|
||||
{ name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, inline: false },
|
||||
{ name: 'Bot Version', value: `${client.config.Dev} v${client.config.Version}`, inline: false },
|
||||
{ name: 'Discord Version', value: `Discord.js ${package.dependencies["discord.js"]}`, inline: false },
|
||||
{ name: 'MongoDB Version', value: `MongoDB ${package.dependencies.mongodb}`, inline: false },
|
||||
);
|
||||
|
||||
return interaction.send({ embeds: [stats] })
|
||||
|
||||
+99
-3
@@ -1,7 +1,7 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
const { BanPlayer, UnbanPlayer, RestartServer, CheckServerStatus, DisableBaseDamage, DisableContainerDamage } = require('../util/NitradoAPI');
|
||||
const { BanPlayer, UnbanPlayer, RestartServer, CheckServerStatus, DisableBaseDamage, DisableContainerDamage, NitradoCredentialStatus } = require('../util/NitradoAPI');
|
||||
const { encrypt, decrypt } = require('../util/Cryptic');
|
||||
|
||||
module.exports = {
|
||||
@@ -20,6 +20,24 @@ module.exports = {
|
||||
value: "initialize",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
{
|
||||
name: "disconnect",
|
||||
description: "Delete your Nitrado server from the bot database",
|
||||
value: "disconnect",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
{
|
||||
name: "credentials-status",
|
||||
description: "Check the status of your Nitrado Credentials",
|
||||
value: "credentials-status",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
{
|
||||
name: "retry-credentials",
|
||||
description: "If your credentials are marked as FAILED, try retreiving Nitrado logs again.",
|
||||
value: "retry-credentials",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
{
|
||||
name: "ban-player",
|
||||
description: "Ban a player from the DayZ server",
|
||||
@@ -150,11 +168,55 @@ module.exports = {
|
||||
|
||||
return interaction.showModal(NitradoCredentials);
|
||||
|
||||
} else if (args[0].name == 'disconnect') {
|
||||
|
||||
const prompt = new EmbedBuilder()
|
||||
.setTitle(`Delete your Nitrado Server?`)
|
||||
.setDescription('**Notice:** This will completely delete your configured Nitrado server from the bot database.')
|
||||
.setColor(client.config.Colors.Yellow)
|
||||
|
||||
const opt = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`DeleteNitrado-yes-${interaction.member.user.id}`)
|
||||
.setLabel("Yes")
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`DeleteNitrado-no-${interaction.member.user.id}`)
|
||||
.setLabel("No")
|
||||
.setStyle(ButtonStyle.Success)
|
||||
)
|
||||
|
||||
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
|
||||
}
|
||||
|
||||
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription(`**Notice:**\nThis Discord guild has not been configured with a Nitrado DayZ server. To configure your guild, use </server initialize:1166877457559851011>`)] });
|
||||
|
||||
if (args[0].name == 'ban-player') {
|
||||
if (args[0].name == 'credentials-status') {
|
||||
|
||||
const ok = GuildDB.Nitrado.Status == NitradoCredentialStatus.OK;
|
||||
const notice = ok ? "Your provided Nitrado Credentials are working correctly, logs are being checked." : "Your provided Nitrado Credentials are not working. They may be incorrect, or your server may be down. Ensure your DayZ server is online, and try to initialize your server again and verify your credentials are correct."
|
||||
const statusEmbed = new EmbedBuilder()
|
||||
.setColor(ok ? client.config.Colors.Green : client.config.Colors.Red)
|
||||
.setTitle("Nitrado Credentials Status")
|
||||
.setDescription(`**Status:** \`${GuildDB.Nitrado.Status}\`\n> ${notice}`);
|
||||
|
||||
return interaction.send({ embeds: [statusEmbed] });
|
||||
|
||||
} else if (args[0].name == 'retry-credentials') {
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set:{"Nitrado.Status": NitradoCredentialStatus.OK}}, (err, _) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
const updatedEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setTitle("Updated Nitrado Credentials Status")
|
||||
.setDescription(`**Success**\n> Successfully retrying your existing Nitrado Credentials to check DayZ logs.`);
|
||||
|
||||
return interaction.send({ embeds: [updatedEmbed] });
|
||||
|
||||
} else if (args[0].name == 'ban-player') {
|
||||
|
||||
let data = await BanPlayer(GuildDB.Nitrado, client, args[0].options[0].value);
|
||||
|
||||
@@ -260,6 +322,7 @@ module.exports = {
|
||||
client.key,
|
||||
client.encryptionIV
|
||||
), // Encrypt the Authentication Token
|
||||
Status: NitradoCredentialStatus.OK, // Indicate if these credentials dont work
|
||||
};
|
||||
|
||||
await client.dbo.collection('guilds').updateOne({ "server.serverID": GuildDB.serverID }, { $set: { "Nitrado": Nitrado } }, (err, res) => {
|
||||
@@ -312,7 +375,40 @@ module.exports = {
|
||||
return interaction.update({ embeds: [], components: [], content: 'Cancelled Overwriting Nitrado Server Information', flags: (1 << 6) });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
DeleteNitrado: {
|
||||
run: async(client, interaction, GuildDB) => {
|
||||
if (!interaction.customId.endsWith(interaction.member.user.id))
|
||||
return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) });
|
||||
|
||||
if (interaction.customId.split('-')[1] == 'yes') {
|
||||
await client.dbo.collection('guilds').updateOne({ "server.serverID": GuildDB.serverID }, { $set: { "Nitrado": null } }, (err, _) => {
|
||||
if (err) client.sendInternalError(interaction, err);
|
||||
});
|
||||
|
||||
return interaction.update({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setDescription(`**Success**\n> Successfully removed your Nitrado credentials from the database.`)
|
||||
],
|
||||
components: [],
|
||||
flags: (1 << 6)
|
||||
});
|
||||
} else {
|
||||
return interaction.update({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setDescription(`**Cancelled**\n> Your Nitrado credentials were not removed from the database.`)
|
||||
],
|
||||
components: [],
|
||||
flags: (1 << 6)
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,8 @@
|
||||
const DayzR = require('./src/DayzRBot');
|
||||
const { ShardingManager } = require('discord.js');
|
||||
const config = require('./config/config');
|
||||
const { GatewayIntentBits } = require('discord.js');
|
||||
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const { HandleActivePlayersList } = require('./util/LogsHandler');
|
||||
const manager = new ShardingManager('./bot.js', { token: config.Token });
|
||||
|
||||
// Log all uncaught exceptions before killing process.
|
||||
process.on('uncaughtException', async (error) => {
|
||||
console.trace(error);
|
||||
let d = new Date();
|
||||
// Asynchronously write the error message to a log file using Promises
|
||||
await new Promise((resolve, reject) => {
|
||||
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
||||
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
||||
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
||||
if (logErr) {
|
||||
console.error('Error writing uncaughtException to log file:', logErr);
|
||||
reject(logErr);
|
||||
process.exit()
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
|
||||
|
||||
// Now gracefully close the program
|
||||
process.exit()
|
||||
});
|
||||
|
||||
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
||||
client.build()
|
||||
manager.spawn();
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "13.2.0",
|
||||
"version": "13.3.5",
|
||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
+10
-4
@@ -6,7 +6,7 @@ const Logger = require("../util/Logger");
|
||||
const crypto = require('crypto');
|
||||
|
||||
// custom util imports
|
||||
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings, PostServerSettings } = require('../util/NitradoAPI');
|
||||
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings, PostServerSettings, NitradoCredentialStatus } = require('../util/NitradoAPI');
|
||||
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
||||
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
||||
@@ -308,6 +308,7 @@ class DayzRBot extends Client {
|
||||
*/
|
||||
|
||||
if (!c.exists(GuildDB.Nitrado)) return; // Continue if no nitrado credentials
|
||||
if (GuildDB.Nitrado.Status == NitradoCredentialStatus.FAILED) return; // Continue if these credentials are marked as failed
|
||||
|
||||
const NitradoCred = {
|
||||
ServerID: GuildDB.Nitrado.ServerID,
|
||||
@@ -317,17 +318,22 @@ class DayzRBot extends Client {
|
||||
c.config.EncryptionMethod,
|
||||
c.key,
|
||||
c.encryptionIV
|
||||
)
|
||||
),
|
||||
};
|
||||
|
||||
const response = await FetchServerSettings(NitradoCred, c, "logsUpdateTimer").then(res => res);
|
||||
if (response == 1) return;
|
||||
if (response == 1) {
|
||||
c.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID }, {$set: { "Nitrado.Status": NitradoCredentialStatus.FAILED }}, (err, _) => {
|
||||
if (err) this.error(`Failed to update Nitrado status to failed. [${GuildDB.serverID}]`);
|
||||
});
|
||||
return;
|
||||
};
|
||||
const settings = response.data.gameserver;
|
||||
|
||||
// Update Nitrado DayZ Mission if change is detected
|
||||
if (GuildDB.Nitrado.Mission !== Missions[settings.settings.config.mission]) {
|
||||
c.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: { "Nitrado.Mission": Missions[settings.settings.config.mission] }}, (err, res) => {
|
||||
if (err) this.error(`Failed to save mission to guild config [${guild.serverID}] for nitrado server [${guild.Nitrado.ServerID}]`);
|
||||
if (err) this.error(`Failed to save mission to guild config [${GuildDB.serverID}] for nitrado server [${GuildDB.Nitrado.ServerID}]`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -301,5 +301,10 @@ module.exports = {
|
||||
if (uploaded == 1) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
NitradoCredentialStatus: {
|
||||
FAILED: "FAILED",
|
||||
OK: "OK",
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user