Compare commits
40
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37b6f3b1e1
|
||
|
|
71cd1808d9
|
||
|
|
8abd3dadd1
|
||
|
|
67116c85be
|
||
|
|
bf95bba612
|
||
|
|
11432cb262
|
||
|
|
3b32c65340
|
||
|
|
e8303fc14a
|
||
|
|
df6b9140ec
|
||
|
|
8249feaf62
|
||
|
|
66955361b0
|
||
|
|
316f4d44b6
|
||
|
|
15d250eb76 | ||
|
|
265f0d3f38 | ||
|
|
cd2ae35a1f | ||
|
|
0abde2d041 | ||
|
|
fff476c725 | ||
|
|
72922dc3a3 | ||
|
|
d1550ff7b5 | ||
|
|
dd983cf9f2 | ||
|
|
dfa36f2e4b | ||
|
|
8d822a352a | ||
|
|
eea202e131 | ||
|
|
64c3ecf6bc | ||
|
|
5fb88a0a09 | ||
|
|
a3a0e978f9 | ||
|
|
8274f8e0da | ||
|
|
9e1f3ca371 | ||
|
|
360fd450eb | ||
|
|
a536bc1045 | ||
|
|
5859c07571 | ||
|
|
5e0a45554f | ||
|
|
d4cf9ec613 | ||
|
|
35a1dac081 | ||
|
|
862686bb07 | ||
|
|
b8197e18d2 | ||
|
|
c0f59cc040 | ||
|
|
caf43aac4e | ||
|
|
bbe0fe5961 | ||
|
|
2cb409a36a |
No files matched your search
+2
-2
@@ -6,8 +6,8 @@ mongoURI='Your mongodb URI'
|
||||
dbo='Your mongodb database'
|
||||
|
||||
# Encryption
|
||||
key='Secret Encryption Key',
|
||||
iv='Secret Initialization Vector',
|
||||
key='Secret Encryption Key'
|
||||
iv='Secret Initialization Vector'
|
||||
|
||||
# Other Bot Configuration
|
||||
Dev=PROD. # or DEV.
|
||||
|
||||
+1
-15
@@ -1,15 +1 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: SowinskiBraeden # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
github: SowinskiBraeden
|
||||
+1
-3
@@ -4,12 +4,10 @@ node_modules/*
|
||||
# Testing/dev related
|
||||
*_test.js
|
||||
dev-*.js
|
||||
commands/debug.js
|
||||
|
||||
# Logs
|
||||
logs/*
|
||||
|
||||
# env
|
||||
.env
|
||||
|
||||
# Admin Script backups
|
||||
admin/backup/*
|
||||
@@ -1,21 +1,121 @@
|
||||
MIT License
|
||||
Creative Commons Legal Code
|
||||
|
||||
Copyright (c) 2023 Braeden Sowinski
|
||||
CC0 1.0 Universal
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
Statement of Purpose
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, PermissionsBitField } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
const { Armbands } = require('../database/armbands.js');
|
||||
@@ -125,10 +125,10 @@ module.exports = {
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
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.' });
|
||||
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, PermissionsBitField } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
|
||||
@@ -230,10 +230,10 @@ module.exports = {
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
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.' });
|
||||
|
||||
|
||||
+210
-54
@@ -1,6 +1,6 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const { PermissionsBitField, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
// const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
const { getDefaultSettings } = require('../database/guild');
|
||||
|
||||
module.exports = {
|
||||
@@ -100,6 +100,12 @@ module.exports = {
|
||||
description: "Clears all configured channels",
|
||||
value: "clear",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
{
|
||||
name: "view",
|
||||
description: "View configured allowed channels",
|
||||
value: "view",
|
||||
type: CommandOptions.SubCommand,
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -160,31 +166,46 @@ module.exports = {
|
||||
name: "bot_admin_role",
|
||||
description: "Set/remove bot admin role",
|
||||
value: "bot_admin_role",
|
||||
type: CommandOptions.SubCommand,
|
||||
type: CommandOptions.SubCommandGroup,
|
||||
options: [
|
||||
{
|
||||
name: "action",
|
||||
description: "Set or remove a role to be a bot administrator",
|
||||
value: "action",
|
||||
type: CommandOptions.String,
|
||||
choices: [
|
||||
{ name: 'add', value: 'add' }, { name: 'remove', value: 'remove' },
|
||||
],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "add",
|
||||
description: "Configure role to be bot admin",
|
||||
value: "add",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "role",
|
||||
description: "Role to configure",
|
||||
description: "Role to confiure",
|
||||
value: "role",
|
||||
type: CommandOptions.Role,
|
||||
required: true,
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "remove",
|
||||
description: "Remove configured role as bot admin",
|
||||
value: "remove",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "role",
|
||||
description: "Role to remove",
|
||||
value: "role",
|
||||
type: CommandOptions.Role,
|
||||
required: true,
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "view",
|
||||
description: "View the configured bot admin roles",
|
||||
value: "view",
|
||||
type: CommandOptions.SubCommand,
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "admin_role",
|
||||
name: "admin_ping_role",
|
||||
description: "Admin role to ping in admin logs channel",
|
||||
value: "admin_role",
|
||||
value: "admin_ping_role",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "role",
|
||||
@@ -196,26 +217,41 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
name: "exclude",
|
||||
description: "Exclude roles that users can use to claim an armband",
|
||||
description: "Exclude roles that can be used to claim armbands",
|
||||
value: "exclude",
|
||||
type: CommandOptions.SubCommand,
|
||||
type: CommandOptions.SubCommandGroup,
|
||||
options: [
|
||||
{
|
||||
name: "action",
|
||||
description: "Add or remove a role from the exclude list.",
|
||||
value: "action",
|
||||
type: CommandOptions.String,
|
||||
choices: [
|
||||
{ name: 'add', value: 'add' }, { name: 'remove', value: 'remove' },
|
||||
],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "add",
|
||||
description: "Configure role to be excluded",
|
||||
value: "add",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "role",
|
||||
description: "The role to manage",
|
||||
description: "Role to confiure",
|
||||
value: "role",
|
||||
type: CommandOptions.Role,
|
||||
required: true,
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "remove",
|
||||
description: "Remove configured role thats excluded",
|
||||
value: "remove",
|
||||
type: CommandOptions.SubCommand,
|
||||
options: [{
|
||||
name: "role",
|
||||
description: "Role to remove",
|
||||
value: "role",
|
||||
type: CommandOptions.Role,
|
||||
required: true,
|
||||
}]
|
||||
},
|
||||
{
|
||||
name: "view",
|
||||
description: "View the configured excluded roles",
|
||||
value: "view",
|
||||
type: CommandOptions.SubCommand,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -393,10 +429,11 @@ module.exports = {
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
// const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
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.' });
|
||||
|
||||
@@ -478,11 +515,36 @@ module.exports = {
|
||||
return interaction.send({ embeds: [promptClearChannels], components: [optClearChannels], flags: (1 << 6) });
|
||||
|
||||
|
||||
} else if (channels_config == 'view') {
|
||||
|
||||
if (!GuildDB.customChannelStatus) {
|
||||
const noConfiguredChannels = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Channels')
|
||||
.setDescription('> There are no configured channels');
|
||||
|
||||
return interaction.send({ embeds: [noConfiguredChannels] });
|
||||
}
|
||||
|
||||
const configuredChannels = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Channels')
|
||||
|
||||
let des = '';
|
||||
for (let i = 0; i < GuildDB.allowedChannels.length; i++) {
|
||||
if (i == 0) des += `> <#${GuildDB.allowedChannels[i]}>`;
|
||||
else des += `\n> <#${GuildDB.allowedChannels[i]}>`;
|
||||
}
|
||||
configuredChannels.setDescription(des);
|
||||
|
||||
return interaction.send({ embeds: [configuredChannels] });
|
||||
|
||||
}
|
||||
|
||||
case 'bot_admin_role':
|
||||
if (args[0].options[0].value == 'add') {
|
||||
const botAdminRoleId = args[0].options[1].value;
|
||||
const bot_admin_config = args[0].options[0].name;
|
||||
const botAdminRoleId = ['add', 'remove'].includes(bot_admin_config) ? args[0].options[0].options[0].value : null;
|
||||
if (bot_admin_config == 'add') {
|
||||
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$push: {"server.botAdminRoles": botAdminRoleId}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
@@ -494,7 +556,7 @@ module.exports = {
|
||||
|
||||
return interaction.send({ embeds: [successSetBotAdminRoleEmbed] });
|
||||
|
||||
} else if (args[0].options[0].value== 'remove') {
|
||||
} else if (bot_admin_config == 'remove') {
|
||||
|
||||
if (!GuildDB.botAdminRoles.includes(botAdminRoleId)) {
|
||||
const nonAdminRoleEmbed = new EmbedBuilder()
|
||||
@@ -521,9 +583,33 @@ module.exports = {
|
||||
)
|
||||
|
||||
return interaction.send({ embeds: [promptRemoveAdminRole], components: [optRemoveAdminRole], flags: (1 << 6) });
|
||||
|
||||
} else if (bot_admin_config == 'view') {
|
||||
|
||||
if (GuildDB.botAdminRoles.length == 0) {
|
||||
const noBotAdminRoles = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Admin Roles')
|
||||
.setDescription('> There have been no configured admin roles');
|
||||
|
||||
return interaction.send({ embeds: [noBotAdminRoles] });
|
||||
}
|
||||
|
||||
case 'admin_role':
|
||||
const botAdminRolesEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Admin Roles')
|
||||
|
||||
let des = '';
|
||||
for (let i = 0; i < GuildDB.botAdminRoles.length; i++) {
|
||||
des += `\n> <@&${GuildDB.botAdminRoles[i]}>`;
|
||||
}
|
||||
botAdminRolesEmbed.setDescription(des);
|
||||
|
||||
return interaction.send({ embeds: [botAdminRolesEmbed] });
|
||||
|
||||
}
|
||||
|
||||
case 'admin_ping_role':
|
||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.adminRole": args[0].options[0].value}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
@@ -535,27 +621,54 @@ module.exports = {
|
||||
return interaction.send({ embeds: [successSetAdminRoleEmbed] });
|
||||
|
||||
case 'exclude':
|
||||
if (args[0].options[0].value == 'add') {
|
||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$push: {'server.excludedRoles': args[0].options[1].value}}, (err, res) => {
|
||||
const exclude_config = args[0].options[0].name;
|
||||
const exclude_roleid = ['add', 'remove'].includes(exclude_config) ? args[0].options[0].options[0].value : null;
|
||||
|
||||
if (exclude_config == 'add') {
|
||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$push: {'server.excludedRoles': exclude_roleid}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
})
|
||||
|
||||
const successExcludeEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setDescription(`**Done!**\n> Successfully added <@&${args[0].options[1].value}> to list of excluded roles.`)
|
||||
.setDescription(`**Done!**\n> Successfully added <@&${exclude_roleid}> to list of excluded roles.`)
|
||||
|
||||
return interaction.send({ embeds: [successExcludeEmbed] });
|
||||
|
||||
} else if (args[0].options[0].value == 'remove') {
|
||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$pull: {'server.excludedRoles': args[0].options[1].value}}, (err, res) => {
|
||||
} else if (exclude_config == 'remove') {
|
||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$pull: {'server.excludedRoles': exclude_roleid}}, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
})
|
||||
|
||||
const successRemoveExcludeEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setDescription(`**Done!**\n> Successfully removed <@&${args[0].options[1].value}> to list of excluded roles.`)
|
||||
.setDescription(`**Done!**\n> Successfully removed <@&${exclude_roleid}> to list of excluded roles.`)
|
||||
|
||||
return interaction.send({ embeds: [successRemoveExcludeEmbed] });
|
||||
|
||||
} else if (exclude_config == "view") {
|
||||
|
||||
if (GuildDB.excludedRoles.length == 0) {
|
||||
const noExcludedRoles = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Excluded Roles')
|
||||
.setDescription('> There have been no excluded roles');
|
||||
|
||||
return interaction.send({ embeds: [noExcludedRoles] });
|
||||
}
|
||||
|
||||
const excludedRolesEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Excluded Roles')
|
||||
|
||||
let des = '';
|
||||
for (let i = 0; i < GuildDB.excludedRoles.length; i++) {
|
||||
des += `\n> <@&${GuildDB.excludedRoles[i]}>`;
|
||||
}
|
||||
excludedRolesEmbed.setDescription(des);
|
||||
|
||||
return interaction.send({ embeds: [excludedRolesEmbed] });
|
||||
|
||||
}
|
||||
|
||||
case 'reset':
|
||||
@@ -579,24 +692,67 @@ module.exports = {
|
||||
return interaction.send({ embeds: [promptReset], components: [optReset], flags: (1 << 6) });
|
||||
|
||||
case 'view':
|
||||
const channelsInfo = GuildDB.customChannelStatus ? '\n╚➤ \`/channels\` to view' : '';
|
||||
const channelColor = GuildDB.customChannelStatus ? '+ ' : '- ';
|
||||
let botAdminRoles = '';
|
||||
for (let i = 0; i < GuildDB.botAdminRoles.length; i++) {
|
||||
botAdminRoles += `\n╚➤ <@&${GuildDB.botAdminRoles[i]}>`;
|
||||
}
|
||||
const botAdminRoleColor = GuildDB.hasBotAdmin ? `+ ` : '- ';
|
||||
const excludedRolesColor = GuildDB.excludedRoles.length > 0 ? `+ ` : '- ';
|
||||
const excludedRolesInfo = GuildDB.excludedRoles.length > 0 ? '\n╚➤ \`/excluded\` to view' : '';
|
||||
|
||||
// wrappers
|
||||
const w = "\`\`\`";
|
||||
const a = "ansi\n";
|
||||
const f = "fix\n";
|
||||
const m = "arm\n"
|
||||
const g = "[2;32m";
|
||||
const r = "[2;31m";
|
||||
|
||||
// boolean display
|
||||
const autoRestart = GuildDB.autoRestart ? `${g}true` : `${r}false`;
|
||||
const showKillfeedCoords = GuildDB.showKillfeedCoords ? `${g}true` : `${r}false`;
|
||||
const showKillfeedWeapon = GuildDB.showKillfeedWeapon ? `${g}true` : `${r}false`;
|
||||
const purchaseUAV = GuildDB.purchaseUAV ? `${g}true` : `${r}false`;
|
||||
const purchaseEMP = GuildDB.purchaseEMP ? `${g}true` : `${r}false`;
|
||||
const adminRoles = GuildDB.hasBotAdmin ? `${g}true` : `${r}false`
|
||||
const excludedRoles = GuildDB.hasExcludedRoles ? `${g}true` : `${r}false`;
|
||||
|
||||
// Role / channel display
|
||||
const NONE = `${w}${m}none${w}`;
|
||||
const channelsInfo = GuildDB.customChannelStatus ? '\`</channels:1225869620813107246>\` to view' : NONE;
|
||||
const killfeedChannel = client.exists(GuildDB.killfeedChannel) ? `<#${GuildDB.killfeedChannel}>` : NONE;
|
||||
const connectionLogs = client.exists(GuildDB.connectionLogsChannel) ? `<#${GuildDB.connectionLogsChannel}>` : NONE;
|
||||
const activePlayers = client.exists(GuildDB.activePlayersChannel) ? `<#${GuildDB.activePlayersChannel}>` : NONE;
|
||||
const welcomeChannel = client.exists(GuildDB.welcomeChannel) ? `<#${GuildDB.welcomeChannel}>` : NONE;
|
||||
const linkedGTRole = client.exists(GuildDB.linkedGamertagRole) ? `<@&${GuildDB.linkedGamertagRole}>` : NONE;
|
||||
const memberRole = client.exists(GuildDB.memberRole) ? `<@&${GuildDB.memberRole}>` : NONE;
|
||||
|
||||
// value display
|
||||
const incomeLimiter = `${GuildDB.incomeLimiter} hours`;
|
||||
const startingBalance = `$${GuildDB.startingBalance.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`;
|
||||
const uavPrice = `$${GuildDB.uavPrice.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`;
|
||||
const empPrice = `$${GuildDB.empPrice.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`;
|
||||
const combatLogTimer = `${GuildDB.combatLogTimer} minutes`;
|
||||
|
||||
// Ugly below but kinda nice above
|
||||
const settingsEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Current Guild Configurations')
|
||||
.addFields(
|
||||
{ name: 'Guild ID', value: `\`\`\`arm\n${GuildDB.serverID}\`\`\``, inline: true },
|
||||
{ name: 'Has Allowed Channels?', value: `\`\`\`diff\n${channelColor}${GuildDB.customChannelStatus}\`\`\`${channelsInfo}`, inline: true },
|
||||
{ name: 'Has bot admin role?', value: `\`\`\`diff\n${botAdminRoleColor}${client.exists(GuildDB.botAdmin)}\`\`\`${botAdminRoles}`, inline: true },
|
||||
{ name: 'Excluded roles?', value: `\`\`\`diff\n${excludedRolesColor}${GuildDB.excludedRoles.length > 0}\`\`\`${excludedRolesInfo}` },
|
||||
{ name: 'Guild ID', value: `${w}${f}${GuildDB.serverID}${w}`, inline: true },
|
||||
{ name: 'Server Name', value: `${w}${f}${GuildDB.serverName}${w}`, inline: true },
|
||||
{ name: 'Auto Restart', value: `${w}${a}${autoRestart}${w}`, inline: true },
|
||||
{ name: 'UAVs Enabled', value: `${w}${a}${purchaseUAV}${w}`, inline: true },
|
||||
{ name: 'EMPs Enabled', value: `${w}${a}${purchaseEMP}${w}`, inline: true },
|
||||
{ name: 'Show Killfeed Coords', value: `${w}${a}${showKillfeedCoords}${w}`, inline: true },
|
||||
{ name: 'Show Killfeed Weapons', value: `${w}${a}${showKillfeedWeapon}${w}`, inline: true },
|
||||
{ name: 'Has Admin Rols', value: `${w}${a}${adminRoles}${w}`, inline: true },
|
||||
{ name: 'Has Excluded Roles', value: `${w}${a}${excludedRoles}${w}`, inline: true },
|
||||
{ name: 'Allowed Channels', value: `${channelsInfo}`, inline: true },
|
||||
{ name: 'Killfeed Channel', value: `${killfeedChannel}`, inline: true },
|
||||
{ name: 'Connection Logs Channel', value: `${connectionLogs}`, inline: true },
|
||||
{ name: 'Player List Channel', value: `${activePlayers}`, inline: true },
|
||||
{ name: 'Welcome Channel', value: `${welcomeChannel}`, inline: true },
|
||||
{ name: 'Linked Gamertag Role', value: `${linkedGTRole}`, inline: true },
|
||||
{ name: 'Member Role', value: `${memberRole}`, inline: true },
|
||||
{ name: 'Income Limiter', value: `${w}${f}${incomeLimiter}${w}`, inline: true },
|
||||
{ name: 'Starting Balance', value: `${w}${f}${startingBalance}${w}`, inline: true },
|
||||
{ name: 'UAV Price', value: `${w}${f}${uavPrice}${w}`, inline: true },
|
||||
{ name: 'EMP Price', value: `${w}${f}${empPrice}${w}`, inline: true },
|
||||
{ name: 'Combat Log Timer', value: `${w}${f}${combatLogTimer}${w}`, inline: true },
|
||||
);
|
||||
|
||||
return interaction.send({ embeds: [settingsEmbed] });
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
|
||||
module.exports = {
|
||||
name: "debug",
|
||||
debug: true,
|
||||
global: false,
|
||||
description: "debugging...",
|
||||
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 (!client.config.Admins.includes(interaction.member.user.id)) return interaction.send({ content: 'Only developers can access this command.', flags: (1 << 6) })
|
||||
|
||||
return interaction.send({ content: `Hello ${interaction.member.user.id}, you are my creator!!` })
|
||||
},
|
||||
},
|
||||
Interactions: {}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
|
||||
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, PermissionsBitField } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
|
||||
@@ -80,10 +80,10 @@ module.exports = {
|
||||
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
|
||||
}
|
||||
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
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.' });
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = {
|
||||
let noExcludes = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('Excluded Roles')
|
||||
.setDescription('> There have been no configured channels');
|
||||
.setDescription('> There have been no excluded roles');
|
||||
|
||||
return interaction.send({ embeds: [noExcludes] });
|
||||
}
|
||||
|
||||
+6
-7
@@ -146,13 +146,12 @@ module.exports = {
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setTitle('DayZ Reforger Bot Statistics')
|
||||
.addFields(
|
||||
{ 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 },
|
||||
{ name: 'Guilds', value: `\`\`\`${totalGuilds}\`\`\``, inline: true },
|
||||
{ name: 'Users', value: `\`\`\`${totalUsers}\`\`\``, 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 },
|
||||
);
|
||||
|
||||
return interaction.send({ embeds: [stats] })
|
||||
|
||||
@@ -31,15 +31,16 @@ module.exports = {
|
||||
return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) });
|
||||
}
|
||||
|
||||
const data = await FetchServerSettings(GuildDB.Nitrado, client, 'commands/player-list.js'); // Fetch server status
|
||||
await interaction.deferReply();
|
||||
|
||||
const data = await FetchServerSettings(GuildDB.Nitrado, client, 'commands/player-list.js'); // Fetch server status
|
||||
const e = data && data !== 1; // Check if data exists
|
||||
|
||||
const hostname = e ? data.data.gameserver.settings.config.hostname : 'N/A';
|
||||
const map = Missions[data.data.gameserver.settings.config.mission];
|
||||
const map = e ? Missions[data.data.gameserver.settings.config.mission] : 'N/A';
|
||||
const status = e ? data.data.gameserver.status : 'N/A';
|
||||
const slots = e ? data.data.gameserver.slots : 'N/A';
|
||||
const playersOnline = data.data.gameserver.query.player_current;
|
||||
const playersOnline = e ? data.data.gameserver.query.player_current : 'N/A';
|
||||
|
||||
const Statuses = {
|
||||
"started": {emoji: "🟢", text: "Active"},
|
||||
@@ -47,8 +48,8 @@ module.exports = {
|
||||
"restarting": {emoji: "↻", text: "Restarting"},
|
||||
};
|
||||
|
||||
const emojiStatus = Statuses[status].emoji || "❓";
|
||||
const textStatus = Statuses[status].text || "Unknown Status";
|
||||
const emojiStatus = e ? Statuses[status].emoji : "❓";
|
||||
const textStatus = e ? Statuses[status].text : "Unknown Status";
|
||||
|
||||
let activePlayers = await client.dbo.collection("players").find({"connected": true}).toArray();
|
||||
|
||||
@@ -74,7 +75,7 @@ module.exports = {
|
||||
.setTitle(`Players Online:`)
|
||||
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
||||
|
||||
return interaction.send({ embeds: [serverEmbed, activePlayersEmbed] });
|
||||
return interaction.editReply({ embeds: [serverEmbed, activePlayersEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField } = require('discord.js');
|
||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||
const { addUser } = require('../database/user');
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
@@ -29,10 +29,10 @@ module.exports = {
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true;
|
||||
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
|
||||
|
||||
|
||||
+42
-5
@@ -1,7 +1,7 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
|
||||
const { PermissionsBitField, 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 = {
|
||||
@@ -26,6 +26,18 @@ module.exports = {
|
||||
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",
|
||||
@@ -96,10 +108,10 @@ module.exports = {
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
const permissions = new PermissionsBitField(interaction.member.permissions).toArray();
|
||||
let canUseCommand = false;
|
||||
|
||||
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
|
||||
if (permissions.includes("ManageGuild")) canUseCommand = true;
|
||||
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.' });
|
||||
|
||||
@@ -180,7 +192,31 @@ module.exports = {
|
||||
|
||||
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);
|
||||
|
||||
@@ -286,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) => {
|
||||
|
||||
+2
-1
File diff suppressed because one or more lines are too long.
@@ -37,6 +37,7 @@ module.exports = {
|
||||
factionArmbands: guild.server.factionArmbands,
|
||||
usedArmbands: guild.server.usedArmbands,
|
||||
excludedRoles: guild.server.excludedRoles,
|
||||
hasExcludedRoles: guild.server.excludedRoles.length > 0 ? true : false,
|
||||
botAdminRoles: guild.server.botAdminRoles,
|
||||
|
||||
alarms: guild.server.alarms,
|
||||
|
||||
Generated
+68
-31
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "12.7.1",
|
||||
"version": "13.3.25",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dayzr-bot",
|
||||
"version": "12.7.1",
|
||||
"version": "13.3.25",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^1.1.0",
|
||||
@@ -1604,10 +1604,18 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"node_modules/ip": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz",
|
||||
"integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ=="
|
||||
"node_modules/ip-address": {
|
||||
"version": "9.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
||||
"integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jsbn": "1.1.0",
|
||||
"sprintf-js": "^1.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 12"
|
||||
}
|
||||
},
|
||||
"node_modules/is-arrayish": {
|
||||
"version": "0.3.2",
|
||||
@@ -1625,6 +1633,12 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/jsbn": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
||||
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/kuler": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
|
||||
@@ -1809,15 +1823,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/socks": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz",
|
||||
"integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==",
|
||||
"version": "2.8.3",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz",
|
||||
"integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ip": "^2.0.0",
|
||||
"ip-address": "^9.0.5",
|
||||
"smart-buffer": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.13.0",
|
||||
"node": ">= 10.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
}
|
||||
},
|
||||
@@ -1830,6 +1845,12 @@
|
||||
"memory-pager": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/sprintf-js": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",
|
||||
"integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/stack-trace": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
|
||||
@@ -1921,9 +1942,10 @@
|
||||
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA=="
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "5.28.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",
|
||||
"integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==",
|
||||
"version": "5.28.5",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz",
|
||||
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
},
|
||||
@@ -1999,9 +2021,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.13.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz",
|
||||
"integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==",
|
||||
"version": "8.18.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
||||
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
@@ -3323,10 +3346,14 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"ip": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz",
|
||||
"integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ=="
|
||||
"ip-address": {
|
||||
"version": "9.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
||||
"integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==",
|
||||
"requires": {
|
||||
"jsbn": "1.1.0",
|
||||
"sprintf-js": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"is-arrayish": {
|
||||
"version": "0.3.2",
|
||||
@@ -3338,6 +3365,11 @@
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg=="
|
||||
},
|
||||
"jsbn": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
||||
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A=="
|
||||
},
|
||||
"kuler": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
|
||||
@@ -3470,11 +3502,11 @@
|
||||
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg=="
|
||||
},
|
||||
"socks": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz",
|
||||
"integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==",
|
||||
"version": "2.8.3",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz",
|
||||
"integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==",
|
||||
"requires": {
|
||||
"ip": "^2.0.0",
|
||||
"ip-address": "^9.0.5",
|
||||
"smart-buffer": "^4.2.0"
|
||||
}
|
||||
},
|
||||
@@ -3487,6 +3519,11 @@
|
||||
"memory-pager": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"sprintf-js": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",
|
||||
"integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="
|
||||
},
|
||||
"stack-trace": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
|
||||
@@ -3558,9 +3595,9 @@
|
||||
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA=="
|
||||
},
|
||||
"undici": {
|
||||
"version": "5.28.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",
|
||||
"integrity": "sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==",
|
||||
"version": "5.28.5",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz",
|
||||
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==",
|
||||
"requires": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
}
|
||||
@@ -3618,9 +3655,9 @@
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "8.13.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz",
|
||||
"integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==",
|
||||
"version": "8.18.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
||||
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
|
||||
"requires": {}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "13.3.2",
|
||||
"version": "13.4.3",
|
||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
+46
-21
@@ -6,11 +6,12 @@ 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, GetRemoteDir } = require('../util/NitradoAPI');
|
||||
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
||||
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
||||
const { decrypt } = require('../util/Cryptic');
|
||||
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||
|
||||
// Data structures imports
|
||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||
@@ -66,12 +67,15 @@ class DayzRBot extends Client {
|
||||
|
||||
this.db;
|
||||
this.dbo;
|
||||
|
||||
this.databaseConnected = false;
|
||||
this.arInterval = arInterval;
|
||||
this.arIntervalIds = new Map();
|
||||
this.playerSessions = new Map();
|
||||
this.logHistory = new Map();
|
||||
this.alarmPingQueue = new Map();
|
||||
this.playerListMsgIds = new Map();
|
||||
|
||||
this.initialize();
|
||||
this.LoadCommandsAndInteractionHandlers();
|
||||
this.LoadEvents();
|
||||
@@ -99,18 +103,16 @@ class DayzRBot extends Client {
|
||||
// Free unused armbands for related commands
|
||||
if (['armbands', 'claim', 'factions'].includes(command)) {
|
||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||
const guild = client.guilds.cache.get(GuildDB.serverID);
|
||||
const guild = this.guilds.cache.get(GuildDB.serverID);
|
||||
const role = guild.roles.cache.find(role => role.id == factionID);
|
||||
if (!role) {
|
||||
let query = {
|
||||
$pull: { 'server.usedArmbands': data.armband },
|
||||
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
||||
};
|
||||
await client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
this.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||
if (err) return this.sendInternalError(interaction, err);
|
||||
});
|
||||
} else {
|
||||
newFactionArmbands[`${factionID}`] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,17 +217,25 @@ class DayzRBot extends Client {
|
||||
const maxEmbed = 10;
|
||||
|
||||
this.alarmPingQueue.forEach(queue => {
|
||||
queue.forEach((data, channel_id) => {
|
||||
queue.forEach(async (data, channel_id) => {
|
||||
const channel = this.GetChannel(channel_id);
|
||||
if (!channel) return;
|
||||
data.forEach((embeds, role) => {
|
||||
|
||||
const NAME = "DayZ.R Zone Alert";
|
||||
const webhook = await GetWebhook(this, NAME, channel_id);
|
||||
|
||||
data.forEach(async (embeds, role) => {
|
||||
let embedArrays = [];
|
||||
while (embeds.length > 0);
|
||||
while (embeds.length > 0)
|
||||
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] });
|
||||
let content = { embeds: embedArrays[i] };
|
||||
if (role != '-no-role-ping-') content.content = `<@&${role}>`;
|
||||
WebhookSend(this, webhook, content);
|
||||
|
||||
// if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
||||
// else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -308,6 +318,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,31 +328,38 @@ 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}]`);
|
||||
});
|
||||
}
|
||||
|
||||
GuildDB.Nitrado.Mission = Missions[settings.settings.config.mission];
|
||||
|
||||
if (settings.game_specific.log_files.length == 0) return; // Ignore if no log files on Nitrado server
|
||||
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]}`;
|
||||
let filenames = await GetRemoteDir(NitradoCred, c, `${settings.game_specific.path}config`);
|
||||
filenames = filenames.sort((a, b) => a.modified_at - b.modified_at)
|
||||
filenames = filenames.filter(path => path.path.includes(".ADM"))
|
||||
filenames = filenames.map(path => path.path)
|
||||
const filename = filenames[filenames.length - 1];
|
||||
|
||||
// Ensure Player List is logged for next update
|
||||
const playerListEnabled = parseInt(settings.settings.config.adminLogPlayerList)
|
||||
if (!playerListEnabled) PostServerSettings(NitradoCred, c, "config", "adminLogPlayerList", '1')
|
||||
|
||||
await DownloadNitradoFile(NitradoCred, c, path, `./logs/${NitradoCred.ServerID}-logs.ADM`).then(async (status) => {
|
||||
await DownloadNitradoFile(NitradoCred, c, filename, `./logs/${NitradoCred.ServerID}-logs.ADM`).then(async (status) => {
|
||||
if (status == 1) return c.error(`Failed to Download Nitrado Log Files - [${NitradoCred.ServerID}]`);
|
||||
await c.readLogs(GuildDB).then(async () => {
|
||||
HandleExpiredUAVs(c, GuildDB);
|
||||
@@ -381,7 +399,9 @@ class DayzRBot extends Client {
|
||||
this.databaseConnected = true;
|
||||
} catch (err) {
|
||||
databaselogs.attempts++;
|
||||
let db = (mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]).endsWith("/") ? mongoURI.slice(0, -1) : mongoURI;
|
||||
databaselogs.connected = false;
|
||||
let db = mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1];
|
||||
db = db.includes("/") ? db.split("/")[0] : db;
|
||||
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
||||
failed = true;
|
||||
}
|
||||
@@ -396,6 +416,7 @@ class DayzRBot extends Client {
|
||||
// Wait for MongoDB to connect
|
||||
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||
|
||||
if (!this.databaseConnected) return;
|
||||
let guilds = await this.dbo.collection("guilds").find({}).toArray();
|
||||
|
||||
/*
|
||||
@@ -420,7 +441,9 @@ class DayzRBot extends Client {
|
||||
}
|
||||
this.logHistory.set(guilds[i].Nitrado.ServerID, guilds[i].server.lastLog); // Using Nitrado Server ID over guild ID in case of future support for multiple nitrado servers in a single guild
|
||||
this.playerSessions.set(guilds[i].Nitrado.ServerID, new Map()); // Same reason here as named above.
|
||||
this.log(`[${guilds[i].server.serverID}] Initialized existing Nitrado`);
|
||||
this.alarmPingQueue.set(guilds[i].server.serverID, new Map()); // Initialize alarm queue to be empty
|
||||
this.playerListMsgIds.set(guilds[i].server.serverID, ""); // Initialize player list message ids
|
||||
this.log(`[${guilds[i].server.serverID}] Initialized existing Nitrado Server: (${guilds[i].Nitrado.ServerID})`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,7 +453,9 @@ class DayzRBot extends Client {
|
||||
if (guild.autoRestart) this.arIntervalIds.set(guildId, setInterval(CheckServerStatus, this.arInterval, Nitrado, this))
|
||||
this.logHistory.set(Nitrado.ServerID, guild.lastLog);
|
||||
this.playerSessions.set(Nitrado.ServerID, new Map());
|
||||
this.log(`[${guild.serverID}] Initialized new Nitrado`);
|
||||
this.alarmPingQueue.set(guildId, new Map());
|
||||
this.playerListMsgIds.set(guildId, "");
|
||||
this.log(`[${guildId}] Initialized new Nitrado`);
|
||||
}
|
||||
|
||||
exists(n) { return typeof(n) == 'number' ? !isNaN(n) : null != n && undefined != n && "" != n }
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { nearest } = require('../database/destinations');
|
||||
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||
|
||||
module.exports = {
|
||||
|
||||
SendConnectionLogs: async (client, guild, data) => {
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return;
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
@@ -14,6 +16,9 @@ module.exports = {
|
||||
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
||||
.setDescription(`**${data.connected ? 'Connect' : 'Disconnect'} Event - <t:${unixTime}>\n${data.player} ${data.connected ? 'Connected' : 'Disconnected'}**`);
|
||||
|
||||
const NAME = "DayZ.R Admin Logs";
|
||||
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||
|
||||
if (!data.connected) {
|
||||
if (data.lastConnectionDate != null) {
|
||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
||||
@@ -22,17 +27,20 @@ module.exports = {
|
||||
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
||||
}
|
||||
|
||||
if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
||||
// if (client.exists(channel)) await channel.send({ embeds: [connectionLog] });
|
||||
await WebhookSend(client, webhook, {embeds: [connectionLog]});
|
||||
},
|
||||
|
||||
DetectCombatLog: async (client, guild, data) => {
|
||||
if (!client.exists(data.lastDamageDate)) return;
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return; // Ensure channel exists
|
||||
|
||||
const newDt = await client.getDateEST(data.time);
|
||||
const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
||||
|
||||
// If diff is greater than 5 minutes, not a combat log
|
||||
// If diff is greater than configured time in minutes, not a combat log
|
||||
// or if death after last combat
|
||||
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||
@@ -42,9 +50,6 @@ module.exports = {
|
||||
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
||||
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
||||
|
||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||
if (!channel) return;
|
||||
|
||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
||||
|
||||
@@ -52,8 +57,12 @@ module.exports = {
|
||||
.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]})**\n${destination}`);
|
||||
|
||||
if (client.exists(guild.adminRole)) channel.send({ content: `<@&${guild.adminRole}>` });
|
||||
const NAME = "DayZ.R Admin Logs";
|
||||
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||
|
||||
return channel.send({ embeds: [combatLog] });
|
||||
let content = { embeds: [combatLog] };
|
||||
if (client.exists(guild.adminRole)) content.content = `<@&${guild.adminRole}>`;
|
||||
WebhookSend(client, webhook, content);
|
||||
// return channel.send({ embeds: [combatLog] });
|
||||
}
|
||||
};
|
||||
+30
-6
@@ -2,6 +2,7 @@ const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { nearest } = require('../database/destinations');
|
||||
const { GetGuild } = require('../database/guild');
|
||||
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||
|
||||
// Private functions (only called locally)
|
||||
|
||||
@@ -20,6 +21,10 @@ const ExpireEvent = async(client, guild, e) => {
|
||||
}
|
||||
|
||||
const HandlePlayerTrackEvent = async (client, guild, e) => {
|
||||
if (!client.exists(e.channel)) return ExpireEvent(client, guild, e); // Expire event since it has invalid channel.
|
||||
const channel = client.GetChannel(e.channel);
|
||||
if (!channel) return;
|
||||
|
||||
let player = await client.dbo.collection("players").findOne({"gamertag": e.gamertag});
|
||||
|
||||
let newDt = await client.getDateEST(player.time);
|
||||
@@ -31,10 +36,15 @@ const HandlePlayerTrackEvent = async (client, guild, e) => {
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setDescription(`**${e.name} Event**\n${e.gamertag} was located at **[${player.pos[0]}, ${player.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${player.pos[0]};${player.pos[1]})** at <t:${unixTime}>\n${destination}`);
|
||||
|
||||
if (!client.exists(e.channel)) return ExpireEvent(client, guild, e); // Expire event since it has invalid channel.
|
||||
const channel = client.GetChannel(e.channel);
|
||||
if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] });
|
||||
else channel.send({ embeds: [trackEvent] });
|
||||
const NAME = "DayZ.R Player Tracker";
|
||||
const webhook = await GetWebhook(client, NAME, e.channel);
|
||||
|
||||
let content = { embeds: [trackEvent] };
|
||||
if (client.exists(guild.adminRole)) content.content = `<@&${e.role}>`;
|
||||
WebhookSend(client, webhook, content);
|
||||
|
||||
// if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] });
|
||||
// else channel.send({ embeds: [trackEvent] });
|
||||
|
||||
let now = new Date();
|
||||
let diff = ((now - e.creationDate) / 1000) / 60;
|
||||
@@ -157,6 +167,7 @@ module.exports = {
|
||||
|
||||
if (distance < alarm.radius) {
|
||||
const channel = client.GetChannel(alarm.channel);
|
||||
if (!channel) continue;
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||
@@ -166,7 +177,13 @@ module.exports = {
|
||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.killer}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for killing **${data.victim}**.__`)
|
||||
.addFields({ name: '**Location**', value: `**[${data.killerPOS[0]}, ${data.killerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.killerPOS[0]};${data.killerPOS[1]})**`, inline: false })
|
||||
|
||||
channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||
const NAME = "DayZ.R Zone Alert";
|
||||
const webhook = await GetWebhook(client, NAME, alarm.channel);
|
||||
|
||||
let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] };
|
||||
WebhookSend(client, webhook, content);
|
||||
|
||||
// channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||
|
||||
BanPlayer(client, data.killer);
|
||||
break;
|
||||
@@ -198,6 +215,7 @@ module.exports = {
|
||||
|
||||
if (distance < alarm.radius) {
|
||||
const channel = client.GetChannel(alarm.channel);
|
||||
if (!channel) return;
|
||||
|
||||
let newDt = await client.getDateEST(info.time);
|
||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||
@@ -207,7 +225,13 @@ module.exports = {
|
||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${info.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for **placing a fireplace**.__`)
|
||||
.addFields({ name: '**Location**', value: `**[${info.playerPOS[0]}, ${info.playerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.playerPOS[0]};${info.playerPOS[1]})**`, inline: false })
|
||||
|
||||
channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||
const NAME = "DayZ.R Zone Alert";
|
||||
const webhook = await GetWebhook(client, NAME, alarm.channel);
|
||||
|
||||
let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] };
|
||||
WebhookSend(client, webhook, content);
|
||||
|
||||
// channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] });
|
||||
|
||||
BanPlayer(client, info.player);
|
||||
break;
|
||||
|
||||
+29
-5
@@ -5,6 +5,7 @@ const { nearest } = require('../database/destinations');
|
||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||
const { calculateNewCombatRating } = require('./CombatRatingHandler');
|
||||
const { weapons, weaponClassOf } = require('../database/weapons');
|
||||
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||
|
||||
const Templates = {
|
||||
Killed: 1,
|
||||
@@ -80,6 +81,7 @@ module.exports = {
|
||||
|
||||
HandleKillfeed: async (NitradoServerID, client, guild, line) => {
|
||||
|
||||
const NAME = "DayZ.R Killfeed";
|
||||
const channel = client.GetChannel(guild.killfeedChannel);
|
||||
|
||||
const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
||||
@@ -133,6 +135,11 @@ module.exports = {
|
||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, NitradoServerID);
|
||||
victimStat.deaths++;
|
||||
victimStat.deathStreak++;
|
||||
victimStat.worstDeathStreak = victimStat.deathStreak > victimStat.worstDeathStreak ? victimStat.deathStreak : victimStat.worstDeathStreak;
|
||||
victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0
|
||||
victimStat.killStreak = 0;
|
||||
victimStat.lastDeathDate = newDt;
|
||||
|
||||
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
||||
@@ -144,9 +151,14 @@ module.exports = {
|
||||
.setColor(client.config.Colors.Default)
|
||||
.setDescription(`**Death Event** - <t:${unixTime}>\n**${info.victim}** ${killMessage} a **${cod}.**${coord}`);
|
||||
|
||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||
await UpdatePlayer(client, victimStat);
|
||||
return
|
||||
|
||||
if (!channel) return;
|
||||
const webhook = await GetWebhook(client, NAME, guild.killfeedChannel);
|
||||
WebhookSend(client, webhook, { embeds: [killEvent]});
|
||||
|
||||
// if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||
return;
|
||||
}
|
||||
|
||||
KillInAlarm(client, guild.serverID, info); // check if kill happened in a no kill zone
|
||||
@@ -252,7 +264,12 @@ module.exports = {
|
||||
const killData = `\n> **__Kill Data__**\n> Weapon: \` ${info.weapon} \`\n> Distance: \` ${info.distance}m \`\n> Body Part: \` ${info.bodyPart != undefined ? info.bodyPart.split('(')[0] : 'N/A'} \`\n> Damage: \` ${info.damage != undefined ? info.damage : 'N/A'} \``;
|
||||
const killerStatsView = `\n**Killer Rating** (${kdiff >= 0 ? '+' : ''}${kdiff}) ${killerStat.combatRating}\n${killerStat.KDR.toFixed(2)} K/D - ${killerStat.kills} Kill${(killerStat.kills == 0 || killerStat.kills > 1) ? 's':''} - Killstreak: ${killerStat.killStreak}`;
|
||||
const victimStatsView = `\n**Victim Rating** (${vdiff >= 0 ? '+' : ''}${vdiff}) ${victimStat.combatRating}\n${victimStat.KDR.toFixed(2)} K/D - ${victimStat.deaths} Death${victimStat.deaths == 0 || victimStat.deaths>1?'s':''} - Deathstreak: ${victimStat.deathStreak}`;
|
||||
const coord = showCoords ? `\n***Location [${info.victimPOS[0]}, ${info.victimPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.victimPOS[0]};${info.victimPOS[1]})***\n${destination}` : '';
|
||||
|
||||
const map = guild.Nitrado.Mission == "Chernarus" ? "chernarusplus" :
|
||||
guild.Nitrado.Mission == "Livonia" ? "livonia" :
|
||||
"sakhal";
|
||||
|
||||
const coord = showCoords ? `\n***Location [${info.victimPOS[0]}, ${info.victimPOS[1]}](https://www.izurvive.com/${map}/#location=${info.victimPOS[0]};${info.victimPOS[1]})***\n${destination}` : '';
|
||||
|
||||
let killEvent = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Default)
|
||||
@@ -263,8 +280,15 @@ module.exports = {
|
||||
killEvent.setThumbnail(weapons[weaponClass][weapon])
|
||||
}
|
||||
|
||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||
if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||
if (!channel) return;
|
||||
|
||||
const webhook = await GetWebhook(client, NAME, guild.killfeedChannel);
|
||||
|
||||
WebhookSend(client, webhook, { embeds: [killEvent] });
|
||||
if (client.exists(receivedBounty) && client.exists(channel)) WebhookSend(client, webhook, { content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||
|
||||
// if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
||||
// if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+19
-7
@@ -5,8 +5,7 @@ const { getDefaultPlayer } = require('../database/player');
|
||||
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||
const { UpdatePlayer, insertPVPstats, createWeaponStats } = require('../database/player')
|
||||
const { Missions } = require('../database/destinations');
|
||||
|
||||
let lastSendMessage;
|
||||
const { GetWebhook, WebhookSend, WebhookMessageEdit } = require("../util/WebhookHandler");
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -34,6 +33,7 @@ module.exports = {
|
||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||
const newDt = await client.getDateEST(info.time);
|
||||
|
||||
playerStat.gamertag = info.player; // update username if changed
|
||||
playerStat.lastConnectionDate = newDt;
|
||||
playerStat.connected = true;
|
||||
if (!client.exists(playerStat.connections)) playerStat.connections = 0;
|
||||
@@ -88,6 +88,7 @@ module.exports = {
|
||||
} else sessionTimeSeconds = 0;
|
||||
if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0;
|
||||
|
||||
playerStat.gamertag = info.player; // update username if changed
|
||||
playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds;
|
||||
playerStat.lastSessionTime = sessionTimeSeconds;
|
||||
playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime;
|
||||
@@ -133,6 +134,7 @@ module.exports = {
|
||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
||||
|
||||
playerStat.gamertag = info.player; // update username if changed
|
||||
playerStat.lastPos = playerStat.pos;
|
||||
playerStat.pos = info.pos;
|
||||
playerStat.lastTime = playerStat.time;
|
||||
@@ -173,9 +175,12 @@ module.exports = {
|
||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||
if (!client.exists(attackerStat)) attackerStat = getDefaultPlayer(info.attacker, info.attackerID, NitradoServerID);
|
||||
|
||||
playerStat.gamertag = info.player; // update username if changed
|
||||
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
||||
playerStat.lastHitBy = info.attacker;
|
||||
|
||||
attackerStat.gamertag = info.attacker; // update username if changed
|
||||
|
||||
if (!client.exists(playerStat.shotsLanded)) playerStat = insertPVPstats(playerStat);
|
||||
if (!client.exists(attackerStat.shotsLanded)) attackerStat = insertPVPstats(attackerStat);
|
||||
|
||||
@@ -208,6 +213,7 @@ module.exports = {
|
||||
|
||||
if (!client.exists(guild.activePlayersChannel)) return;
|
||||
const channel = client.GetChannel(guild.activePlayersChannel);
|
||||
if (!channel) return;
|
||||
|
||||
const data = await FetchServerSettings(nitrado_cred, client, 'HandleActivePlayersList'); // Fetch server status
|
||||
const e = data && data !== 1; // Check if data exists
|
||||
@@ -227,7 +233,8 @@ module.exports = {
|
||||
const emojiStatus = Statuses[status].emoji || "❓";
|
||||
const textStatus = Statuses[status].text || "Unknown Status";
|
||||
|
||||
let activePlayers = await client.dbo.collection("players").find({"nitradoServerID": nitrado_cred.ServerID}).toArray().filter(player => player.connected);
|
||||
let activePlayers = await client.dbo.collection("players").find({ "nitradoServerID": parseInt(nitrado_cred.ServerID) }).toArray();
|
||||
activePlayers = activePlayers.filter(player => player.connected);
|
||||
|
||||
let des = activePlayers.length > 0 ? `` : `**No Players Online**`;
|
||||
for (let i = 0; i < activePlayers.length; i++) {
|
||||
@@ -251,10 +258,15 @@ module.exports = {
|
||||
.setTitle(`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
|
||||
const NAME = "DayZ.R Admin Logs";
|
||||
const webhook = await GetWebhook(client, NAME, guild.activePlayersChannel);
|
||||
|
||||
return channel.send({ embeds: [serverEmbed, activePlayersEmbed] }).then(sentMessage =>
|
||||
lastSendMessage = sentMessage
|
||||
);
|
||||
let id = client.playerListMsgIds.get(guild.serverID);
|
||||
if (id == "") {
|
||||
id = await WebhookSend(client, webhook, { embeds: [serverEmbed, activePlayersEmbed] }).id;
|
||||
client.playerListMsgIds.set(guild.serverID, id);
|
||||
} else {
|
||||
WebhookMessageEdit(client, webhook, id, { embeds: [serverEmbed, activePlayersEmbed] });
|
||||
}
|
||||
}
|
||||
};
|
||||
+14
-7
@@ -63,7 +63,12 @@ const HandlePlayerBan = async (nitrado_cred, client, gamertag, ban) => {
|
||||
}
|
||||
}
|
||||
|
||||
const GetRemoteDir = async (nitrado_cred, client, dir="") => {
|
||||
// Public functions (called externally)
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
||||
GetRemoteDir: async (nitrado_cred, client, dir="") => {
|
||||
const dirParam = client.exists(dir) ? `?dir=${dir}` : "";
|
||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||
try {
|
||||
@@ -87,11 +92,7 @@ const GetRemoteDir = async (nitrado_cred, client, dir="") => {
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||
}
|
||||
}
|
||||
|
||||
// Public functions (called externally)
|
||||
|
||||
module.exports = {
|
||||
},
|
||||
|
||||
DownloadNitradoFile: async(nitrado_cred, client, filename, outputDir) => {
|
||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||
@@ -176,6 +177,7 @@ module.exports = {
|
||||
|
||||
if (!res.ok) {
|
||||
client.error(`Failed to get Nitrado server stats (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: ${fetcher} via FetchServerSettings`);
|
||||
if (res.status == 401) return 1; // return immediately if unauthorized
|
||||
if (retries === 2) return 1; // Return error status on the second failed status code.
|
||||
} else {
|
||||
const data = await res.json();
|
||||
@@ -301,5 +303,10 @@ module.exports = {
|
||||
if (uploaded == 1) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
NitradoCredentialStatus: {
|
||||
FAILED: "FAILED",
|
||||
OK: "OK",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord.js');
|
||||
|
||||
const createWebhook = async (client, channel_id, name, avatar) => {
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
return await rest.post(Routes.channelWebhooks(channel_id), {
|
||||
body: {
|
||||
name: name,
|
||||
avatar: avatar
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
GetWebhook: async (client, webhookName, channel_id) => {
|
||||
// Get all webhooks from configured channel
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
const webhooks = await rest.get(Routes.channelWebhooks(channel_id));
|
||||
|
||||
let webhook = null;
|
||||
if (webhooks.length == 0) {
|
||||
// If no webhook exists, create new webhook with given name for this channel
|
||||
webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData);
|
||||
} else {
|
||||
// Check existing webhooks for one with given name
|
||||
let exists = false;
|
||||
for (let i = 0; i < webhooks.length; i++) {
|
||||
if (webhooks[i].name == webhookName) {
|
||||
webhook = webhooks[i];
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!exists) webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData);
|
||||
}
|
||||
|
||||
return webhook;
|
||||
},
|
||||
|
||||
WebhookSend: async (client, webhook, content) => {
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
return await rest.post(Routes.webhook(webhook.id, webhook.token), {
|
||||
body: content,
|
||||
query: makeURLSearchParams({ wait: true })
|
||||
});
|
||||
},
|
||||
|
||||
WebhookMessageEdit: async (client, webhook, message_id, content) => {
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
return rest.patch(Routes.webhookMessage(webhook.id, webhook.token, message_id), {
|
||||
body: content
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user