refactor/support multiple discord guilds with 1 nitrado server each + better handling for NitradoAPI

This commit is contained in:
SowinskiBraeden committed 2024-04-04 20:11:48 -07:00
1 parent 71d03ffa72
commit 55c8a9ee7f
33 files changed
+888 -1028

No files matched your search

+24
View File
@@ -134,6 +134,14 @@ module.exports = {
if (args[0].name == 'gamertag-link') {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[1].value});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].options[1].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] });
@@ -180,6 +188,14 @@ module.exports = {
} else if (args[0].name == 'gamertag-unlink') {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"discordID": args[0].options[0].value});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** <@${args[0].options[0].value}> has no gamertag linked.`)] });
@@ -265,6 +281,14 @@ module.exports = {
} else if (args[0].name == 'bounty-clear') {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** This player cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least ` 5 minutes `.')] });
+8
View File
@@ -214,6 +214,14 @@ module.exports = {
if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) canUseCommand = true;
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
if (args[0].name == 'create') {
if (args[0].options[3].value.includes('-') || args[0].options[3].value.includes(' ')) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription('**Invalid Name:** Alarm Names cannot include hyphens or spaces.')] })
+8
View File
@@ -59,6 +59,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let banking;
if (args[0].name == 'set' || args[0].name == 'pay') {
banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
+9
View File
@@ -33,6 +33,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let discord = args[0] && args[0].name == 'discord' ? args[0].value : undefined;
let gamertag = args[0] && args[0].name == 'gamertag' ? args[0].value : undefined;
+2 -11
View File
@@ -11,12 +11,7 @@ module.exports = {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
options: [{
name: 'sync-logs',
description: 'download the Nitrado logs and run checks now',
value: 'sync-logs',
type: CommandOptions.SubCommand,
}],
options: [],
SlashCommand: {
/**
*
@@ -28,11 +23,7 @@ module.exports = {
run: async (client, interaction, args, { GuildDB }) => {
if (!client.config.Admins.includes(interaction.member.user.id)) return interaction.send({ content: 'Only developers can access this command.', flags: (1 << 6) })
if (args[0].name == 'sync-logs') {
if (client.processingLogs) return interaction.send({ content: 'The Nitrado logs are already being processed at the moment...', flags: (1 << 6) });
interaction.send({ content: 'Downloading and processing Nitrado logs now...', flags: (1 << 6) });
return client.logsUpdateTimer(client);
}
return interaction.send({ content: `Hello ${interaction.member.user.id}, you are my creator!!` })
},
},
Interactions: {}
+8
View File
@@ -72,6 +72,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
let canUseCommand = false;
+8
View File
@@ -29,6 +29,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].value});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] });
+8
View File
@@ -21,6 +21,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**No Gamertag Linked** It Appears your don't have a gamertag linked to your account.`)] });
+9
View File
@@ -52,6 +52,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
const category = args[0].value;
const limit = args[1].value;
+11 -17
View File
@@ -1,6 +1,5 @@
const { EmbedBuilder } = require('discord.js');
const { destinations } = require('../database/destinations');
const { calculateVector } = require('../util/Vector');
const { nearest } = require('../database/destinations');
module.exports = {
name: "location",
@@ -21,27 +20,22 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id});
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** You haven't linked your gamertag and are unable to use this command.`)], flags: (1 << 6) });
let newDt = await client.getDateEST(playerStat.time);
let unixTime = Math.floor(newDt.getTime()/1000);
let tempDest;
let lastDist = 1000000;
let destination_dir;
if (showCoords) { // Only calculate if showing coords, very tiny minor optimization... probably amounts to nothing.
for (let i = 0; i < destinations.length; i++) {
let { distance, theta, dir } = calculateVector(info.victimPOS, destinations[i].coord);
if (distance < lastDist) {
tempDest = destinations[i].name;
lastDist = distance;
destination_dir = dir;
}
}
}
const destination = lastDist > 500 ? `${destination_dir} of ${tempDest}` : `Near ${tempDest}`;
const destination = nearest(playerStat.pos, GuildDB.Nitrado.Mission);
let lastLocation = new EmbedBuilder()
.setColor(client.config.Colors.Default)
+8
View File
@@ -46,6 +46,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
if (args[0].name == 'discord') {
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value});
+9
View File
@@ -21,6 +21,14 @@ module.exports = {
*/
run: async (client, interaction, args, { GuildDB }, start) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let activePlayers = await client.dbo.collection("players").find({"connected": true});
let des = activePlayers.length > 0 ? `` : `**No Players Online**`;
@@ -28,6 +36,7 @@ module.exports = {
des += `**- ${activePlayers[i].gamertag}**\n`;
}
// TODO: handle activePlayers.length being undefined
const activePlayersEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setTitle(`Online List - ${activePlayers.length} Player${(activePlayers.length>1||activePlayers.length==0)?'s':''} Online`)
+9
View File
@@ -56,6 +56,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }, start) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let category = args[0].value;
let discord = args[1] && args[1].name == 'discord' ? args[1].value : undefined;
let gamertag = args[1] && args[1].name == 'gamertag' ? args[1].value : undefined;
+9
View File
@@ -32,6 +32,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
if (client.exists(GuildDB.purchaseEMP) && !GuildDB.purchaseEMP) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Notice:** The admins have disabled this feature')] });
const duration = args[0].value;
+9
View File
@@ -39,6 +39,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
if (client.exists(GuildDB.purchaseUAV) && !GuildDB.purchaseUAV) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Notice:** The admins have disabled this feature')] });
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
+1
View File
@@ -3,6 +3,7 @@ const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
const { addUser } = require('../database/user');
const bitfieldCalculator = require('discord-bitfield-calculator');
// TODO: Reset User Banking, Reset User Game Stats, Reset All Users Banking, Reset All User Game stats
module.exports = {
name: "reset",
debug: false,
+168 -24
View File
@@ -1,8 +1,10 @@
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
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 { encrypt, decrypt } = require('../util/Cryptic');
// TODO: deactivate nitrado server from guild
module.exports = {
name: "server",
debug: false,
@@ -13,8 +15,13 @@ module.exports = {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
options: [
{
options: [{
name: "initialize",
description: "Connect your Nitrado server to the bot",
value: "initialize",
type: CommandOptions.SubCommand,
},
{
name: "ban-player",
description: "Ban a player from the DayZ server",
value: "ban-player",
@@ -91,16 +98,88 @@ module.exports = {
if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) canUseCommand = true;
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
const NitradoCred = client.exists(GuildDB.Nitrado) ? {
ServerID: GuildDB.Nitrado.ServerID,
UserID: GuildDB.Nitrado.UserID,
Auth: decrypt(
GuildDB.Nitrado.Auth,
client.config.EncryptionMethod,
client.key,
client.encryptionIV
)
} : {
ServerID: null,
UserID: null,
Auth: null
}
if (args[0].name == 'initialize') {
if (client.exists(GuildDB.Nitrado)) {
const prompt = new EmbedBuilder()
.setTitle(`Nitrado Server Information Already Configured!`)
.setDescription('**Notice:** This will overwrite your previously configured Nitrado Server Information')
.setColor(client.config.Colors.Yellow)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`OverwriteNitrado-yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`OverwriteNitrado-no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
}
const NitradoCredentials = new ModalBuilder()
.setTitle('Connect your Nitrado Server')
.setCustomId(`NitradoCredentials-${interaction.member.user.id}`);
const ServerID = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('ServerIDInput')
.setLabel('Your Nitrado Server ID')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
const UserID = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('UserIDInput')
.setLabel('Your Nitrado User ID')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
const Auth = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('AuthInput')
.setLabel('Your Nitrado Authentication Token')
.setPlaceholder("This will be encrypted to protect your server!")
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
NitradoCredentials.addComponents(ServerID, UserID, Auth);
return interaction.showModal(NitradoCredentials);
}
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') {
let data = await BanPlayer(client, args[0].options[0].value);
let data = await BanPlayer(NitradoCred, client, args[0].options[0].value);
if (data == 1) {
let failed = new EmbedBuilder()
.setColor(client.config.Colors.Red)
.setDescription(`Failed to ban **${args[0].options[0].value}**. Check internal logs for an error.`);
.setDescription(`Failed to ban **${args[0].options[0].value}**. This can result from a variety of reasons:\nNitrado servers may be experiencing issues\nThe DayZ.R Bot may be experiencing issues\nYour Nitrado credentials were entered incorrectly`);
return interaciton.send({ embeds: [failed] });
return interaction.send({ embeds: [failed], flags: (1 << 6) });
}
let banned = new EmbedBuilder()
@@ -111,12 +190,12 @@ module.exports = {
} else if (args[0].name == 'unban-player') {
let data = UnbanPlayer(client, args[0].options[0].value);
let data = UnbanPlayer(NitradoCred, client, args[0].options[0].value);
if (data == 1) {
let failed = new EmbedBuilder()
.setColor(client.config.Colors.Red)
.setDescription(`Failed to ban **${args[0].options[0].value}**. Check internal logs for an error.`);
.setDescription(`Failed to unban **${args[0].options[0].value}**. This can result from a variety of reasons:\nNitrado servers may be experiencing issues\nThe DayZ.R Bot may be experiencing issues\nYour Nitrado credentials were entered incorrectly`);
return interaction.send({ embeds: [failed] });
}
@@ -132,29 +211,26 @@ module.exports = {
restart_message = 'Server being restarted by an admin.';
message = 'The server was restarted by an admin!';
RestartServer(client, restart_message, message);
RestartServer(NitradoCred, client, restart_message, message);
return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('The server will restart shortly.')], flags: (1 << 6) });
} else if (args[0].name == "auto-restart") {
msg = 'Auto server restart periodic check enabled.';
pref = 0;
let msg = 'Auto server restart periodic check enabled.';
let pref = 0;
// Enable/Disable a 10min periodic server status check.
if (!client.arIntervalId) {
client.arIntervalId = setInterval(CheckServerStatus, client.arInterval, client);
client.log('Enabled and starting periodic Nitrado server status check.');
if (!client.arIntervalIds.has(GuildDB.serverID)) {
client.arIntervalIds.set(GuildDB.serverID, setInterval(CheckServerStatus, client.arInterval, NitradoCred, client));
pref = 1;
} else {
msg = 'Auto server restart periodic check disabled.'
clearInterval(client.arIntervalId);
client.arIntervalId = 0;
client.log('Disabled periodic Nitrado server status check.');
clearInterval(client.arIntervalIds.get(GuildDB.serverID));
}
// Update DB preference
client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, {
$set: {
"server.autoRestart": pref
"server.autoRestart": pref,
}
}, function (err, res) {
if (err) return client.sendInternalError(interaction, err);
@@ -166,23 +242,91 @@ module.exports = {
const preference = args[0].options[0].value;
await interaction.deferReply({ flags: (1 << 6) });
const disableBaseDamageFailed = await DisableBaseDamage(client, preference);
const disableBaseDamageFailed = await DisableBaseDamage(NitradoCred, client, preference);
if (disableBaseDamageFailed) return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription('Failed to set **disableBaseDamage**, try again later.')], flags: (1 << 6) });
if (disableBaseDamageFailed) return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription('Failed to set **disableBaseDamage**. This can result from a variety of reasons:\nNitrado servers may be experiencing issues\nThe DayZ.R Bot may be experiencing issues\nYour Nitrado credentials were entered incorrectly')], flags: (1 << 6) });
return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Green).setDescription(`Successfully set **disableBaseDamage** to ${preference}.\nRestart the DayZ server to apply these changes.`)], flags: (1 << 6) });
} else if (args[0].name == 'disable-container-damage') {
const preference = args[0].options[0].value;
await interaction.deferReply({ flags: (1 << 6) });
const disableContainerDamageFailed = await DisableContainerDamage(client, preference);
const disableContainerDamageFailed = await DisableContainerDamage(NitradoCred, client, preference);
if (disableContainerDamageFailed) return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription('Failed to set **disableContainerDamage**, try again later.')], flags: (1 << 6) });
if (disableContainerDamageFailed) return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription('Failed to set **disableContainerDamage**. This can result from a variety of reasons:\nNitrado servers may be experiencing issues\nThe DayZ.R Bot may be experiencing issues\nYour Nitrado credentials were entered incorrectly')], flags: (1 << 6) });
return interaction.editReply({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Green).setDescription(`Successfully set **disableContainerDamage** to ${preference}.\nRestart the DayZ server to apply these changes.`)], flags: (1 << 6) });
}
}
},
Interactions: {}
Interactions: {
NitradoCredentials: {
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) });
const Nitrado = {
ServerID: interaction.fields.fields.get('ServerIDInput').value,
UserID: interaction.fields.fields.get('UserIDInput').value,
Auth: encrypt(
interaction.fields.fields.get('AuthInput').value,
client.config.EncryptionMethod,
client.key,
client.encryptionIV
), // Encrypt the Authentication Token
};
await client.dbo.collection('guilds').updateOne({ "server.serverID": GuildDB.serverID }, { $set: { "Nitrado": Nitrado } }, (err, res) => {
if (err) client.sendInternalError(interaction, err);
});
client.initNewNitradoServer(GuildDB.serverID, Nitrado);
return interaction.reply({ content: 'Successfully configured your Nitrado Server Information', flags: (1 << 6) });
}
},
OverwriteNitrado: {
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') {
const NitradoCredentials = new ModalBuilder()
.setTitle('Connect your Nitrado Server')
.setCustomId(`NitradoCredentials-${interaction.member.user.id}`);
const ServerID = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('ServerIDInput')
.setLabel('Your Nitrado Server ID')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
const UserID = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('UserIDInput')
.setLabel('Your Nitrado User ID')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
const Auth = new ActionRowBuilder().addComponents(new TextInputBuilder()
.setCustomId('AuthInput')
.setLabel('Your Nitrado Authentication Token')
.setStyle(TextInputStyle.Short)
.setRequired(true)
);
NitradoCredentials.addComponents(ServerID, UserID, Auth);
return interaction.update(NitradoCredentials);
} else {
return interaction.reply({ content: 'Cancelled Overwriting Nitrado Server Information' });
}
}
}
}
}
+9
View File
@@ -53,6 +53,15 @@ module.exports = {
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
const warnNitradoNotInitialized = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable.");
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
}
let discord = args[1] && args[1].name == 'discord' ? args[1].value : undefined;
let gamertag = args[1] && args[1].name == 'gamertag' ? args[1].value : undefined;
let self = !discord && !gamertag; // searching for self if both discord and gamertag are undefined