Compare commits
153
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72922dc3a3 | ||
|
|
d1550ff7b5 | ||
|
|
dd983cf9f2 | ||
|
|
dfa36f2e4b | ||
|
|
8d822a352a | ||
|
|
eea202e131 | ||
|
|
64c3ecf6bc | ||
|
|
5fb88a0a09 | ||
|
|
a3a0e978f9 | ||
|
|
8274f8e0da | ||
|
|
9e1f3ca371 | ||
|
|
360fd450eb | ||
|
|
a536bc1045 | ||
|
|
5859c07571 | ||
|
|
5e0a45554f | ||
|
|
d4cf9ec613 | ||
|
|
35a1dac081 | ||
|
|
862686bb07 | ||
|
|
b8197e18d2 | ||
|
|
c0f59cc040 | ||
|
|
caf43aac4e | ||
|
|
bbe0fe5961 | ||
|
|
2cb409a36a | ||
|
|
7f675f4185 | ||
|
|
3c6faf7f75 | ||
|
|
64be8a5558 | ||
|
|
52c946bee5 | ||
|
|
14a8833f0d | ||
|
|
30acabde1d | ||
|
|
49e31ff44a | ||
|
|
f32d82b633 | ||
|
|
ea578abf79 | ||
|
|
fbc31dcc7f | ||
|
|
414491c707 | ||
|
|
b0bd181a27 | ||
|
|
108055e2fe | ||
|
|
ca2a9dd1ef | ||
|
|
15cfb60c62 | ||
|
|
03f5c51177 | ||
|
|
12d0302526 | ||
|
|
34ba4f84c2 | ||
|
|
417c38cfad | ||
|
|
49021e3ad3 | ||
|
|
daa87574e1 | ||
|
|
2c4d5bbe10 | ||
|
|
bda392b57c | ||
|
|
52636e9131 | ||
|
|
8b9ff28395 | ||
|
|
d5315056b5 | ||
|
|
3b8d28e536 | ||
|
|
7d8096b3d6 | ||
|
|
a88eb72f64 | ||
|
|
f46c5d0ef6 | ||
|
|
8450111b5c | ||
|
|
04b0fac552 | ||
|
|
5d5767dc3f | ||
|
|
efde626f1a | ||
|
|
485b1ee219 | ||
|
|
f0520eae8c | ||
|
|
a022484831 | ||
|
|
0af1e51f50 | ||
|
|
fe7dc7d2f4 | ||
|
|
c3232f8267 | ||
|
|
ad7c449d05 | ||
|
|
ccf1b0fa56 | ||
|
|
2774cabdd2 | ||
|
|
b284ded053 | ||
|
|
e4fc2d2302 | ||
|
|
abdf469b34 | ||
|
|
9ab1a43238 | ||
|
|
7c2373e03e | ||
|
|
46356adcd9 | ||
|
|
55c8a9ee7f | ||
|
|
71d03ffa72 | ||
|
|
639a2ecbb4 | ||
|
|
dfe384c9b8 | ||
|
|
0a78c92d63 | ||
|
|
d805918454 | ||
|
|
3b56c013cf | ||
|
|
c88a98f3b5 | ||
|
|
17ce345101 | ||
|
|
66660657da | ||
|
|
0823f7bf7c | ||
|
|
65534ea96e | ||
|
|
7cb2996af4 | ||
|
|
747cf04769 | ||
|
|
970abfac9f | ||
|
|
c5324ae627 | ||
|
|
621c847c81 | ||
|
|
a53efbd4f2 | ||
|
|
46c4a55fac | ||
|
|
84887b9368 | ||
|
|
162b57f46b | ||
|
|
8b7cba3b6f | ||
|
|
8fcd7196f8 | ||
|
|
e2d4f321da | ||
|
|
7a0bf8ced4 | ||
|
|
886fd6aff8 | ||
|
|
665abad887 | ||
|
|
37dd14ea84 | ||
|
|
c6c5cec7ce | ||
|
|
c8f555b6d1 | ||
|
|
3406440a31 | ||
|
|
bc0336b47a | ||
|
|
4b9d813ca3 | ||
|
|
e8d086de1d | ||
|
|
eb7f454cbb | ||
|
|
ee0ae4cdbf | ||
|
|
87d14c5d29 | ||
|
|
18fb91914c | ||
|
|
95ec4c5f1e | ||
|
|
9d44dcf158 | ||
|
|
e7ced1f9d2 | ||
|
|
77c4c9d555 | ||
|
|
43adfa7a57 | ||
|
|
3299892922 | ||
|
|
8723d8ca41 | ||
|
|
e50441aeac | ||
|
|
c43121d92f | ||
|
|
9d3f203587 | ||
|
|
b06a3e69e3 | ||
|
|
e27fff585a | ||
|
|
a862da7e36 | ||
|
|
6c4a85dced | ||
|
|
0bc4da3166 | ||
|
|
7a8c23810a | ||
|
|
cd31797dfc | ||
|
|
f8a7ea824f | ||
|
|
19f56f890c | ||
|
|
d88af57447 | ||
|
|
4980df99fc | ||
|
|
22d4dd1db4 | ||
|
|
58339d9983 | ||
|
|
6735c40daa | ||
|
|
6b5e5c70bf | ||
|
|
777180638f | ||
|
|
f95dbcd134 | ||
|
|
f4e13cbff2 | ||
|
|
5d229f717a | ||
|
|
961df69cb4 | ||
|
|
77a7654f1a | ||
|
|
94d66258fd | ||
|
|
bb05381fcc | ||
|
|
62c3243f10 | ||
|
|
e3fa17fec6 | ||
|
|
160979e6e7 | ||
|
|
ea60c4a459 | ||
|
|
7a324ce769 | ||
|
|
c7552c463c | ||
|
|
4bc9c06e0a | ||
|
|
ee51fa1030 | ||
|
|
c2bf5bb883 | ||
|
|
aa35d2d2cd |
No files matched your search
+12
-4
@@ -1,8 +1,16 @@
|
|||||||
|
# Discord Bot Token
|
||||||
token='Your Discord Bot token'
|
token='Your Discord Bot token'
|
||||||
|
|
||||||
|
# MongoDB Information
|
||||||
mongoURI='Your mongodb URI'
|
mongoURI='Your mongodb URI'
|
||||||
dbo='Your mongodb database'
|
dbo='Your mongodb database'
|
||||||
SERVER_ID='Your Nitrado server ID'
|
|
||||||
USER_ID='Your Nitrado user ID'
|
# Encryption
|
||||||
AUTH_KEY='Your Nitrado Auth Token'
|
key='Secret Encryption Key',
|
||||||
GuildID='Your Discord Guild ID'
|
iv='Secret Initialization Vector',
|
||||||
|
|
||||||
|
# Other Bot Configuration
|
||||||
Dev=PROD. # or DEV.
|
Dev=PROD. # or DEV.
|
||||||
|
|
||||||
|
# Note: "PROD." downloads Nitrado logs every 5 minutes, "DEV." checks every 15 seconds.
|
||||||
|
# Any other value for Dev will not allow the bot to run.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
github: SowinskiBraeden
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Execute command '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
+1
-3
@@ -4,12 +4,10 @@ node_modules/*
|
|||||||
# Testing/dev related
|
# Testing/dev related
|
||||||
*_test.js
|
*_test.js
|
||||||
dev-*.js
|
dev-*.js
|
||||||
|
commands/debug.js
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs/*
|
logs/*
|
||||||
|
|
||||||
# env
|
# env
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# Admin Script backups
|
|
||||||
admin/backup/*
|
|
||||||
+181
-2
@@ -1,11 +1,32 @@
|
|||||||
<!-- CONTRIBUTING -->
|
<!-- CONTRIBUTING -->
|
||||||
## Contributing
|
# Contributing
|
||||||
|
|
||||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
||||||
|
|
||||||
If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the tag "enhancement".
|
If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the `enhancement` tag.
|
||||||
Don't forget to give the project a star! Thanks again!
|
Don't forget to give the project a star! Thanks again!
|
||||||
|
|
||||||
|
***Explore the docs »***
|
||||||
|
* [README](#readme)
|
||||||
|
* [License](#license)
|
||||||
|
* [General Contributing Guidelines](#general-contributing-guidlines)
|
||||||
|
* [Creating A New Command](#creating-a-new-command)
|
||||||
|
* [Handling Non Command Interactions](#handling-non-command-interactions)
|
||||||
|
*
|
||||||
|
|
||||||
|
## README
|
||||||
|
|
||||||
|
Before you get started contributing, it would be an excellent idea to checkout the `README.md` file!
|
||||||
|
[» README](/README.md)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[» License](/LICENSE)
|
||||||
|
|
||||||
|
## General Contributing Guidlines
|
||||||
|
|
||||||
|
When you are ready to start work on your own feature and would like to push it to the main repository. Follow these guidelines.
|
||||||
|
|
||||||
1. Clone the Project
|
1. Clone the Project
|
||||||
2. Create your Feature Branch (`git checkout -b update/AmazingFeature`)
|
2. Create your Feature Branch (`git checkout -b update/AmazingFeature`)
|
||||||
3. Commit your Changes (`git commit -m 'update/your-update'`) please use the following for your commits:
|
3. Commit your Changes (`git commit -m 'update/your-update'`) please use the following for your commits:
|
||||||
@@ -17,3 +38,161 @@ Don't forget to give the project a star! Thanks again!
|
|||||||
5. Open a Pull Request
|
5. Open a Pull Request
|
||||||
|
|
||||||
Do keep in mind of the [package.json](/package.json) version. Version structure is as follows: `(major).(minor).(patch)`
|
Do keep in mind of the [package.json](/package.json) version. Version structure is as follows: `(major).(minor).(patch)`
|
||||||
|
|
||||||
|
## Creating A New Command
|
||||||
|
|
||||||
|
If you're simply looking to add a new command and not make significant changes to the backend of the bot. Here is a simple guideline to create a new command.
|
||||||
|
|
||||||
|
1. Create a new command file in the `/commands` folder.
|
||||||
|
2. Name this file as the name of the command. E.g. `new-command.js`
|
||||||
|
3. Use the following template to start your command file:
|
||||||
|
```javascript
|
||||||
|
const { EmbedBuilder } = require('discord.js'); // Not required, but encouraged to use embeds to reply to commands.
|
||||||
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; // Not required but recommended for clear cmd options.
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "new-command", // Insert your command name here, I encourage that you use hyphens `-` to seperate words.
|
||||||
|
debug: false, // Do not change this
|
||||||
|
global: false, // Do not change this
|
||||||
|
description: "My command Description", // Describe your command
|
||||||
|
usage: "", // Insert command parameters here E.g. useage: "[cmd param 1] [cmd param 2]"
|
||||||
|
options: [
|
||||||
|
// Below example of a command option
|
||||||
|
{
|
||||||
|
name: "cmd_param_1",
|
||||||
|
description: "What this parameter is for",
|
||||||
|
value: "cmd_param_1_default", // Default value of this parameter
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
SlashCommand: { // Do not change the name of this funciton
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {require("../structures/DayzRBot")} client
|
||||||
|
* @param {import("discord.js").Message} message
|
||||||
|
* @param {string[]} args
|
||||||
|
* @param {*} param3
|
||||||
|
*/
|
||||||
|
run: async (client, interaction, args, { GuildDB }, start) => { // Do not change the name of this function, or change the parameters.
|
||||||
|
|
||||||
|
// Do your command stuff here ...
|
||||||
|
|
||||||
|
/*
|
||||||
|
Optionally if your command will take longer than 3 seconds to do its stuff
|
||||||
|
You can easily defer your interaction reply as seen below:
|
||||||
|
|
||||||
|
await interaction.deferReply({ optional_data_here });
|
||||||
|
|
||||||
|
If you use the deferReply, in order to update the message when the command is complete, use the following:
|
||||||
|
|
||||||
|
return interaction.editReply({ return_data_here })
|
||||||
|
*/
|
||||||
|
|
||||||
|
// If you do not use defer reply, you can use this to complete your command interaction.
|
||||||
|
return interaction.send({ embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setDescription("Hooray! Your command is complete.")
|
||||||
|
]
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
That is all you need to do to add your new command to the bot, do keep in mind the bot will need to be restarted to load any new commands.
|
||||||
|
All commands are automatically loaded from the `/commands` folder when the bot is started.
|
||||||
|
|
||||||
|
## Handling Non Command Interactions
|
||||||
|
|
||||||
|
Adding additional interactions to your command? Buttons, Select Menus, etc? You can easily handle those interactions by doing the following.
|
||||||
|
|
||||||
|
1. Create an `Interactions` object within your command file. E.g. my new command `/commands/greet.js` will have the following:
|
||||||
|
```javascript
|
||||||
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, } = require('discord.js'); // Some additional imported definitions for our button.
|
||||||
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "greet",
|
||||||
|
debug: false,
|
||||||
|
global: false,
|
||||||
|
description: "Greet a name",
|
||||||
|
usage: "",
|
||||||
|
options: [{
|
||||||
|
name: "name",
|
||||||
|
description: "Name to greet",
|
||||||
|
value: "name", // Default value of this parameter
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: true,
|
||||||
|
}],
|
||||||
|
SlashCommand: {
|
||||||
|
|
||||||
|
run: async (client, interaction, args, { GuildDB }, start) => {
|
||||||
|
// Here is a simple example of this command using a button.
|
||||||
|
|
||||||
|
let name = args[0].value
|
||||||
|
|
||||||
|
/*
|
||||||
|
Here are the button options, Hello and GoodBye.
|
||||||
|
The custom ID for each button is VERY IMPORTANT,
|
||||||
|
this is how we know what non-cmd interaction to
|
||||||
|
call, and the values we choose to pass.
|
||||||
|
|
||||||
|
E.g.
|
||||||
|
The first part of the custom ID is Greet, the name
|
||||||
|
of our non-cmd interaction handler.
|
||||||
|
|
||||||
|
SEPERATING THE VALUES ARE HYPHENS "-"
|
||||||
|
|
||||||
|
Next value is in this example, hello or goodbye
|
||||||
|
depending on the button.
|
||||||
|
|
||||||
|
The final value is the variable name we want to
|
||||||
|
pass to our non-cmd interaciton.
|
||||||
|
*/
|
||||||
|
const opt = new ActionRowBuilder()
|
||||||
|
.addComponents(
|
||||||
|
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`Greet-hello-${name}`)
|
||||||
|
.setLabel("Hello")
|
||||||
|
.setStyle(ButtonStyle.Success),
|
||||||
|
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`Greet-goodbye-${name}`)
|
||||||
|
.setLabel("GoodBye")
|
||||||
|
.setStyle(ButtonStyle.Secondary)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
// The cmd-interaction sends the two button options to the user to click. That is the end of our CMD-INTERACTION.
|
||||||
|
return interaction.send({ components: [opt] });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Below is my Interactions object that will define any non-cmd interactions this command will use.
|
||||||
|
Interactions: {
|
||||||
|
|
||||||
|
// Here I defined my Greet interaciton, this interaction is a NON-CMD interaction and will be called by our buttons from our cmd-interaction above.
|
||||||
|
// It is very important the name of our non-cmd interaction matches the name we call in our Button's custom ID.
|
||||||
|
Greet: {
|
||||||
|
// The handler I've written connects our button interaction to this function, and passes the following variables to this run function.
|
||||||
|
run: async (client, interaction, GuildDB) => {
|
||||||
|
|
||||||
|
// Here is the code we'll write to complete our button interaction.
|
||||||
|
|
||||||
|
let greeting = interaction.customId.split('-')[1]; // Get either hello or goodbye as our greeting
|
||||||
|
let name = interaction.customId.split('-')[2]; // Get the name from the interaction id.
|
||||||
|
|
||||||
|
let phrase = `${greeting} ${name}!`;
|
||||||
|
|
||||||
|
// We clear the buttons away, and send our phrase with our greeting from the buttons.
|
||||||
|
return interaction.update({ content: phrase, components: [] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is all you need to do to create a non-cmd interaction for buttons, menus, etc.
|
||||||
@@ -62,17 +62,23 @@ The bot requires minimal setup to get started.
|
|||||||
2. Rename `.env.example` to `.env`
|
2. Rename `.env.example` to `.env`
|
||||||
3. Enter desired values into `.env`
|
3. Enter desired values into `.env`
|
||||||
```
|
```
|
||||||
token='Your Discord Bot token'
|
# Discord Bot Token
|
||||||
mongoURI='Your mongodb URI'
|
token='Your Discord Bot token'
|
||||||
dbo='Your mongodb database'
|
|
||||||
SERVER_ID='Your Nitrado server ID'
|
# MongoDB Information
|
||||||
USER_ID='Your Nitrado user ID'
|
mongoURI='Your mongodb URI'
|
||||||
AUTH_KEY='Your Nitrado Auth Token'
|
dbo='Your mongodb database'
|
||||||
GuildID='Your Discord Guild ID'
|
|
||||||
|
# Encryption
|
||||||
|
key='Secret Encryption Key',
|
||||||
|
iv='Secret Initialization Vector',
|
||||||
|
|
||||||
|
# Other Bot Configuration
|
||||||
|
Dev=PROD. # or DEV.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|
||||||
Braeden Sowinski - [@BraedenSowinski](https://twitter.com/BraedenSowinski) - sowinskibraeden@gmail.com - @mcdazzzled on Discord
|
Braeden Sowinski - [@BraedenSowinski](https://twitter.com/BraedenSowinski) - braeden@sowinski.dev - @mcdazzzled on Discord
|
||||||
|
|
||||||
Project Link: [https://github.com/SowinskiBraeden/dayz-reforger](https://github.com/SowinskiBraeden/dayz-reforger)
|
Project Link: [https://github.com/SowinskiBraeden/dayz-reforger](https://github.com/SowinskiBraeden/dayz-reforger)
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 13.x.x | :white_check_mark: |
|
||||||
|
| 5.x.x | :x: |
|
||||||
|
| < 5.0 | :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Use this section to tell people how to report a vulnerability.
|
||||||
|
|
||||||
|
To report a volnerability you can either open an issue or contact me braeden@sowinski.dev. I will review the reported vulnerability and contact you
|
||||||
|
if I have any questions or clarifications.
|
||||||
|
|
||||||
|
Thank you for helping to keep our repository safe to use for the community!
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
require('dotenv').config({ path: '../.env' });
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const MongoClient = require('mongodb').MongoClient;
|
|
||||||
const guildId = process.env.GuildID;
|
|
||||||
const URI = process.env.mongoURI;
|
|
||||||
const dbo = process.env.dbo;
|
|
||||||
const NitradoServerID = process.env.SERVER_ID;
|
|
||||||
const client = new MongoClient(URI);
|
|
||||||
|
|
||||||
/*
|
|
||||||
!WARNING!
|
|
||||||
|
|
||||||
THIS SCRIPT IS MEANT ONLY FOR BOT ADMINISTRATORS WHO ARE RUNNING THE BOT + DATABASE
|
|
||||||
|
|
||||||
This script will migrate all playerstats from the guildSettings document in the "guilds" collection,
|
|
||||||
to their own collection as their own documents in the new "players" collection.
|
|
||||||
|
|
||||||
Only run this once you have bot version ^12.0.0 or higher.
|
|
||||||
*/
|
|
||||||
|
|
||||||
async function migrate() {
|
|
||||||
const package = await JSON.parse(fs.readFileSync('../package.json'));
|
|
||||||
const version = package.version.split('.').map(v => parseInt(v));
|
|
||||||
|
|
||||||
// Ensure version is 12.0.4 or higher.
|
|
||||||
if (version[0] < 12, version[2] < 4) throw new Error('Bot version does not meet requirements: v^12.0.4');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Get the database and collection on which to run the operation
|
|
||||||
const database = client.db(dbo);
|
|
||||||
const players = database.collection("players");
|
|
||||||
const guilds = database.collection("guilds");
|
|
||||||
|
|
||||||
// Get current guild settings + player stats
|
|
||||||
let guild = await guilds.findOne({"server.serverID": guildId});
|
|
||||||
|
|
||||||
// Create backup dir
|
|
||||||
const dir = __dirname + '/backup';
|
|
||||||
if (!fs.existsSync(dir)){
|
|
||||||
fs.mkdirSync(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure new required values are inserted into player stat.
|
|
||||||
guild.server.playerstats.map(stat => stat.nitradoServerID = NitradoServerID);
|
|
||||||
guild.server.playerstats.map(stat => stat.bountiesLength = stat.bounties.length);
|
|
||||||
|
|
||||||
// write JSON to file
|
|
||||||
fs.writeFileSync(`${dir}/player_stats_backup.json`, JSON.stringify(guild.server.playerstats, null, 2));
|
|
||||||
console.log(`A backup of playerstats was successfully created in ./backup/player_stats_backup.json in case of a fatal error.`);
|
|
||||||
|
|
||||||
// Move player stats to new collection.
|
|
||||||
const result = await players.insertMany(guild.server.playerstats, { ordered: true });
|
|
||||||
console.log(`${result.insertedCount} documents were inserted to "players" collections.`);
|
|
||||||
|
|
||||||
// Removes player stats from guild settings.
|
|
||||||
delete guild.server.playerstats;
|
|
||||||
|
|
||||||
// Update guild settings with removed player stats.
|
|
||||||
await guilds.updateOne({"server.serverID": guildId}, {$set: guild});
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`An error occured while attempting to migrate player stats: ${err}`)
|
|
||||||
} finally {
|
|
||||||
await client.close();
|
|
||||||
console.log(`Successfully migrated player stats into the "players" collection.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
migrate()
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
const DayzR = require('./src/DayzRBot');
|
||||||
|
const config = require('./config/config');
|
||||||
|
const { GatewayIntentBits } = require('discord.js');
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require('fs');
|
||||||
|
const { HandleActivePlayersList } = require('./util/LogsHandler');
|
||||||
|
|
||||||
|
// Log all uncaught exceptions before killing process.
|
||||||
|
process.on('uncaughtException', async (error) => {
|
||||||
|
console.trace(error);
|
||||||
|
let d = new Date();
|
||||||
|
// Asynchronously write the error message to a log file using Promises
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
||||||
|
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
||||||
|
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
||||||
|
if (logErr) {
|
||||||
|
console.error('Error writing uncaughtException to log file:', logErr);
|
||||||
|
reject(logErr);
|
||||||
|
process.exit()
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Now gracefully close the program
|
||||||
|
process.exit()
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
||||||
|
client.build()
|
||||||
+58
-32
@@ -17,7 +17,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
options: [{
|
options: [{
|
||||||
name: "gamertag-link",
|
name: "gamertag-link",
|
||||||
description: "link a gamertag for a user",
|
description: "Link a gamertag for a user",
|
||||||
value: "gamertag-link",
|
value: "gamertag-link",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -36,7 +36,7 @@ module.exports = {
|
|||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
name: "gamertag-unlink",
|
name: "gamertag-unlink",
|
||||||
description: "unlink a gamertag for a user",
|
description: "Unlink a gamertag for a user",
|
||||||
value: "gamertag-unlink",
|
value: "gamertag-unlink",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -60,7 +60,7 @@ module.exports = {
|
|||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
name: "bounty-clear",
|
name: "bounty-clear",
|
||||||
description: "clear a bounty off a player",
|
description: "Clear a bounty off a player",
|
||||||
value: "bounty-clear",
|
value: "bounty-clear",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -72,50 +72,49 @@ module.exports = {
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "add-money",
|
name: "money",
|
||||||
description: "Add money to user",
|
description: "Add/Remove money to a user",
|
||||||
value: "add",
|
value: "money",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommandGroup,
|
||||||
options: [
|
options: [{
|
||||||
{
|
name: "add",
|
||||||
|
description: "Add money to user",
|
||||||
|
value: "add",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
options: [{
|
||||||
name: "amount",
|
name: "amount",
|
||||||
description: "The amount to add to balance",
|
description: "The amount to add to balance",
|
||||||
value: "amount",
|
value: "amount",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 0.01,
|
min_value: 0.01,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
name: "to",
|
name: "to",
|
||||||
description: "User to alter balance",
|
description: "User to alter balance",
|
||||||
value: "to",
|
value: "to",
|
||||||
type: CommandOptions.User,
|
type: CommandOptions.User,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}],
|
||||||
]
|
}, {
|
||||||
},
|
name: "remove",
|
||||||
{
|
description: "Remove money from a user",
|
||||||
name: "remove-money",
|
value: "remove",
|
||||||
description: "Remove or remove money from a user",
|
type: CommandOptions.SubCommand,
|
||||||
value: "remove",
|
options: [{
|
||||||
type: CommandOptions.SubCommand,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: "amount",
|
name: "amount",
|
||||||
description: "The amount to add to balance",
|
description: "The amount to remove from balance",
|
||||||
value: "amount",
|
value: "amount",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 0.01,
|
min_value: 0.01,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
name: "from",
|
name: "from",
|
||||||
description: "User to alter balance",
|
description: "User to alter balance",
|
||||||
value: "from",
|
value: "from",
|
||||||
type: CommandOptions.User,
|
type: CommandOptions.User,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}]
|
||||||
]
|
}]
|
||||||
}],
|
}],
|
||||||
SlashCommand: {
|
SlashCommand: {
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +134,14 @@ module.exports = {
|
|||||||
|
|
||||||
if (args[0].name == 'gamertag-link') {
|
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});
|
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 \`.`)] });
|
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 \`.`)] });
|
||||||
|
|
||||||
@@ -181,6 +188,14 @@ module.exports = {
|
|||||||
|
|
||||||
} else if (args[0].name == 'gamertag-unlink') {
|
} 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});
|
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.`)] });
|
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.`)] });
|
||||||
|
|
||||||
@@ -266,6 +281,14 @@ module.exports = {
|
|||||||
|
|
||||||
} else if (args[0].name == 'bounty-clear') {
|
} 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});
|
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 `.')] });
|
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 `.')] });
|
||||||
|
|
||||||
@@ -279,9 +302,9 @@ module.exports = {
|
|||||||
|
|
||||||
return interaction.send({ embeds: [clearedBounty] });
|
return interaction.send({ embeds: [clearedBounty] });
|
||||||
|
|
||||||
} else if (args[0].name == 'add-money' || args[0].name == 'remove-money') {
|
} else if (args[0].name == 'money') {
|
||||||
|
|
||||||
const targetUserID = args[0].options[1].value;
|
const targetUserID = args[0].options[0].options[1].value;
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
@@ -295,16 +318,19 @@ module.exports = {
|
|||||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
}
|
}
|
||||||
|
|
||||||
let newBalance = args[0].name == 'add-money'
|
if (!client.exists(banking.guilds[GuildDB.serverID].balance)) banking.guilds[GuildDB.serverID].balance = GuildDB.startingBalance;
|
||||||
? banking.guilds[GuildDB.serverID].balance + args[0].options[0].value
|
|
||||||
: banking.guilds[GuildDB.serverID].balance - args[0].options[0].value;
|
const add = args[0].options[0].name == 'add';
|
||||||
|
let newBalance = add
|
||||||
|
? banking.guilds[GuildDB.serverID].balance + args[0].options[0].options[0].value
|
||||||
|
: banking.guilds[GuildDB.serverID].balance - args[0].options[0].options[0].value;
|
||||||
|
|
||||||
client.dbo.collection("users").updateOne({"user.userID":targetUserID},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => {
|
client.dbo.collection("users").updateOne({"user.userID":targetUserID},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
const successEmbed = new EmbedBuilder()
|
const successEmbed = new EmbedBuilder()
|
||||||
.setDescription(`Successfully ${args[0].name == 'add-money' ? 'added' : 'removed'} **$${args[0].options[0].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** ${args[0].name == 'add-money' ? 'to' : 'from'} <@${targetUserID}>'s balance`)
|
.setDescription(`Successfully ${add ? 'added' : 'removed'} **$${args[0].options[0].options[0].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** ${add ? 'to' : 'from'} <@${targetUserID}>'s balance`)
|
||||||
.setColor(client.config.Colors.Green);
|
.setColor(client.config.Colors.Green);
|
||||||
|
|
||||||
return interaction.send({ embeds: [successEmbed] });
|
return interaction.send({ embeds: [successEmbed] });
|
||||||
|
|||||||
+123
-186
@@ -2,11 +2,34 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelect
|
|||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||||
|
|
||||||
|
const generateAlarmMenus = (alarms, customId, placeholder, description) => {
|
||||||
|
let alarmComponents = [];
|
||||||
|
const max = 25;
|
||||||
|
let id = 1;
|
||||||
|
|
||||||
|
for (let i = 0; i < alarms.length; i += max) {
|
||||||
|
let currentAlarmComponents = new StringSelectMenuBuilder()
|
||||||
|
.setCustomId(`${customId}-${id}`)
|
||||||
|
.setPlaceholder(placeholder);
|
||||||
|
alarms.slice(i, i + max).forEach(alarm => {
|
||||||
|
currentAlarmComponents.addOptions({
|
||||||
|
label: alarm.name,
|
||||||
|
description: description,
|
||||||
|
value: alarm.name,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
alarmComponents.push(new ActionRowBuilder().addComponents(currentAlarmComponents));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return alarmComponents;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "alarm",
|
name: "alarm",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "Create a Zone Ping Alarm",
|
description: "Manage an Alarm",
|
||||||
usage: "[command] [options]",
|
usage: "[command] [options]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
@@ -37,7 +60,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "radius",
|
name: "radius",
|
||||||
description: "Radius of Zone Alarm",
|
description: "Radius of Alarm",
|
||||||
value: "radius",
|
value: "radius",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 25.00,
|
min_value: 25.00,
|
||||||
@@ -45,14 +68,14 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "name",
|
name: "name",
|
||||||
description: "Zone Alarm Name",
|
description: "Alarm Name",
|
||||||
value: "name",
|
value: "name",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "channel",
|
name: "channel",
|
||||||
description: "The channel to configure",
|
description: "Alarm Channel",
|
||||||
value: "channel",
|
value: "channel",
|
||||||
type: CommandOptions.Channel,
|
type: CommandOptions.Channel,
|
||||||
channel_types: [0], // Restrict to text channel
|
channel_types: [0], // Restrict to text channel
|
||||||
@@ -60,7 +83,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "role",
|
name: "role",
|
||||||
description: "Role to Ping on Zone Alarm",
|
description: "Role to Ping on Alarm",
|
||||||
value: "role",
|
value: "role",
|
||||||
type: CommandOptions.Role,
|
type: CommandOptions.Role,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -74,7 +97,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "show-player-coords",
|
name: "show-player-coords",
|
||||||
description: "Show a players coords when in the zone",
|
description: "Show a players coords when in the radius of the Alarm?",
|
||||||
value: true,
|
value: true,
|
||||||
type: CommandOptions.Boolean,
|
type: CommandOptions.Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -83,18 +106,18 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "delete",
|
name: "delete",
|
||||||
description: "Delete a Zone Alarm",
|
description: "Delete an Alarm",
|
||||||
value: "delete",
|
value: "delete",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "add-player",
|
name: "add-player",
|
||||||
description: "Add Player to be Ignored in a Zone Alarm Pings",
|
description: "Add player to be ignored list of an Alarm",
|
||||||
value: "add-player",
|
value: "add-player",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "gamertag",
|
name: "gamertag",
|
||||||
description: "Gamertag of Player to Ignore",
|
description: "Gamertag of player to ignore",
|
||||||
value: "gamertag",
|
value: "gamertag",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.String,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -102,12 +125,12 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "remove-player",
|
name: "remove-player",
|
||||||
description: "Remove a Player from being Ignored in a Zone Alarm Pings",
|
description: "Remove a player from the ignored list of an Alarm",
|
||||||
value: "remove-player",
|
value: "remove-player",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "gamertag",
|
name: "gamertag",
|
||||||
description: "Gamertag of Player to Ignore",
|
description: "Gamertag of player to ignore",
|
||||||
value: "gamertag",
|
value: "gamertag",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.String,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -115,24 +138,24 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "disable",
|
name: "disable",
|
||||||
description: "Disable an Zone Alarm",
|
description: "Disable an Alarm",
|
||||||
value: "disable",
|
value: "disable",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "enable",
|
name: "enable",
|
||||||
description: "Enable an Zone Alarm",
|
description: "Enable an Alarm",
|
||||||
value: "enable",
|
value: "enable",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mute",
|
name: "mute",
|
||||||
description: "Toggle mute on this alarm",
|
description: "Mute the role ping of an Alarm",
|
||||||
value: "mute",
|
value: "mute",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "toggle",
|
name: "toggle",
|
||||||
description: "Turn on or off role pings for this alarm",
|
description: "Turn on/off role pings for this alarm",
|
||||||
value: false,
|
value: false,
|
||||||
type: CommandOptions.Boolean,
|
type: CommandOptions.Boolean,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -145,7 +168,7 @@ module.exports = {
|
|||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "rule",
|
name: "rule",
|
||||||
description: "Rule to Add to an Alarm",
|
description: "Select a rule to add to an Alarm",
|
||||||
value: "rule",
|
value: "rule",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.String,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -158,7 +181,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "remove-rule",
|
name: "remove-rule",
|
||||||
description: "Remove a Rule from an Alarm",
|
description: "Remove a rule from an Alarm",
|
||||||
value: "remove-rule",
|
value: "remove-rule",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
@@ -177,12 +200,12 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "move-origin",
|
name: "move-origin",
|
||||||
description: "Move an alarms origin to new coordinates",
|
description: "Move the origin of an Alarm",
|
||||||
value: "move-origin",
|
value: "move-origin",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "x-coord",
|
name: "x-coord",
|
||||||
description: "X Coordinate of the origin",
|
description: "X Coordinate of the new origin",
|
||||||
value: "x-coord",
|
value: "x-coord",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 0.01,
|
min_value: 0.01,
|
||||||
@@ -190,7 +213,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "y-coord",
|
name: "y-coord",
|
||||||
description: "Y Coordinate of the origin",
|
description: "Y Coordinate of the new origin",
|
||||||
value: "y-coord",
|
value: "y-coord",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 0.01,
|
min_value: 0.01,
|
||||||
@@ -214,10 +237,18 @@ module.exports = {
|
|||||||
if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) 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.' });
|
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].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.')] })
|
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.')] })
|
||||||
|
|
||||||
let exists = undefined == GuildDB.alarms.find(alarm => alarm.name = args[0].options[3].value) ? true : false;
|
let exists = GuildDB.alarms.find(alarm => alarm.name == args[0].options[3].value);
|
||||||
if (exists) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Invalid Name**\nAn alarm already exists with this name.')]});
|
if (exists) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Invalid Name**\nAn alarm already exists with this name.')]});
|
||||||
|
|
||||||
let alarm = {
|
let alarm = {
|
||||||
@@ -252,156 +283,111 @@ module.exports = {
|
|||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to Delete.')] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to Delete.')] });
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
const alarmComponents = generateAlarmMenus(
|
||||||
.setCustomId(`DeleteAlarmSelect-${interaction.member.user.id}`)
|
GuildDB.alarms,
|
||||||
.setPlaceholder(`Select an Alarm to Delete.`)
|
`DeleteAlarmSelect`,
|
||||||
|
`Select an Alarm to delete.`,
|
||||||
|
`Delete this alarm`
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Delete this Alarm`,
|
|
||||||
value: GuildDB.alarms[i].name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
|
|
||||||
} else if (args[0].name == 'add-player' || args[0].name == 'remove-player') {
|
} else if (args[0].name == 'add-player' || args[0].name == 'remove-player') {
|
||||||
|
|
||||||
let add = args[0].name == 'add-player';
|
const add = args[0].name == 'add-player';
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription(`**Notice:** No Existing Alarms to ${add?'Add':'Remove'} Player ${add?'to':'from'}.`)] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription(`**Notice:** No Existing Alarms to ${add?'Add':'Remove'} Player ${add?'to':'from'}.`)] });
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
const alarmComponents = generateAlarmMenus(
|
||||||
.setCustomId(`ManageAlarmIgnored-${add?'add':'remove'}-${args[0].options[0].value}-${interaction.member.user.id}`)
|
GuildDB.alarms,
|
||||||
.setPlaceholder(`Select an Alarm to ${add?'Add':'Remove'} Player ${add?'to':'from'}.`)
|
`ManageAlarmIgnored-${add?'add':'remove'}-${args[0].options[0].value}`,
|
||||||
|
`Select an Alarm to ${add?'add':'remove'} player ${add?'to':'from'}.`,
|
||||||
|
`${add?'Add':'Remove'} player ${add?'to':'from'} this Alarm`
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `${add?'Add':'Remove'} Player ${add?'to':'from'} this Alarm`,
|
|
||||||
value: GuildDB.alarms[i].name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt] });
|
|
||||||
} else if (args[0].name == 'set-rule' || args[0].name == 'remove-rule') {
|
} else if (args[0].name == 'set-rule' || args[0].name == 'remove-rule') {
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
||||||
|
|
||||||
let id = `ManageRule-${args[0].name=='set-rule'?'add':'remove'}${args[0].name=='set-rule'?`-${args[0].options[0].value}`:''}-${interaction.member.user.id}`
|
const alarmComponents = generateAlarmMenus(
|
||||||
|
GuildDB.alarms,
|
||||||
|
`ManageRule-${args[0].name=='set-rule'?'add':'remove'}${args[0].name=='set-rule'?`-${args[0].options[0].value}`:''}`,
|
||||||
|
`Select an Alarm to configure.`,
|
||||||
|
`Configure this alarm`
|
||||||
|
);
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
.setCustomId(id)
|
|
||||||
.setPlaceholder(`Select an Alarm to configure.`)
|
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Configure this Alarm`,
|
|
||||||
value: GuildDB.alarms[i].name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
|
|
||||||
} else if (args[0].name == 'enable' || args[0].name == 'disable') {
|
} else if (args[0].name == 'enable' || args[0].name == 'disable') {
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
const disable = args[0].name == 'disable';
|
||||||
|
const message = disable ? 'disable' : 'enable';
|
||||||
|
|
||||||
let disable = args[0].name == 'disable' ? true : false;
|
if (GuildDB.alarms.length == 0) return interaction.send({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`**Notice:**\n> No Existing Alarms to ${message}.`)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
if (!GuildDB.alarms.some(alarm => alarm.disabled != disable)) return interaction.send({
|
||||||
.setCustomId(`EnableOrDisableAlarm-${disable ? 'disable' : 'enable'}-${interaction.member.user.id}`)
|
embeds: [
|
||||||
.setPlaceholder(`Select an Alarm to ${disable ? 'disable' : 'enable'}.`);
|
new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`**Notice:**\n> There are no alarms to ${message}.`)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
const alarmComponents = generateAlarmMenus(
|
||||||
if (disable && !GuildDB.alarms[i].disabled) {
|
GuildDB.alarms,
|
||||||
alarms.addOptions({
|
`EnableOrDisableAlarm-${message}`,
|
||||||
label: GuildDB.alarms[i].name,
|
`Select an Alarm to ${message}`,
|
||||||
description: `Disable this alarm`,
|
`Configure this alarm`
|
||||||
value: GuildDB.alarms[i].name,
|
);
|
||||||
})
|
|
||||||
} else if (!disable && GuildDB.alarms[i].disabled) {
|
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Enable this alarm`,
|
|
||||||
value: GuildDB.alarms[i].name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
|
|
||||||
} else if (args[0].name == 'rename') {
|
} else if (args[0].name == 'rename') {
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:**\n> No Existing Alarms to configure.')] });
|
||||||
|
|
||||||
let disable = args[0].name == 'disable' ? true : false;
|
const alarmComponents = generateAlarmMenus(
|
||||||
|
GuildDB.alarms,
|
||||||
|
`RenameAlarm-${args[0].options[0].value}`,
|
||||||
|
`Select an Alarm to rename.`,
|
||||||
|
`Rename this alarm`
|
||||||
|
);
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
.setCustomId(`RenameAlarm-${args[0].options[0].value}-${interaction.member.user.id}`)
|
|
||||||
.setPlaceholder(`Select an Alarm to rename.`);
|
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Rename this alarm`,
|
|
||||||
value: GuildDB.alarms[i].name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
|
|
||||||
} else if (args[0].name == 'move-origin') {
|
} else if (args[0].name == 'move-origin') {
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
const alarmComponents = generateAlarmMenus(
|
||||||
.setCustomId(`MoveOrigin-${args[0].options[0].value}-${args[0].options[1].value}-${interaction.member.user.id}`)
|
GuildDB.alarms,
|
||||||
.setPlaceholder(`Select an Alarm to move.`);
|
`MoveOrigin-${args[0].options[0].value}-${args[0].options[1].value}`,
|
||||||
|
`Select an Alarm to move.`,
|
||||||
|
`Move this alarm`
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Move the Origin of this Alarm`,
|
|
||||||
value: GuildDB.alarms[i].name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
|
|
||||||
} else if (args[0].name == 'mute') {
|
} else if (args[0].name == 'mute') {
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] });
|
||||||
|
|
||||||
let alarms = new StringSelectMenuBuilder()
|
const alarmComponents = generateAlarmMenus(
|
||||||
.setCustomId(`MuteAlarm-${args[0].options[0].value ? 1 : 0}-${interaction.member.user.id}`)
|
GuildDB.alarms,
|
||||||
.setPlaceholder(`Select an Alarm to mute.`);
|
`MuteAlarm-${args[0].options[0].value ? 1 : 0}`,
|
||||||
|
`Select an Alarm to mute.`,
|
||||||
|
`Mute this alarm`
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < GuildDB.alarms.length; i++) {
|
return interaction.send({ components: alarmComponents, flags: (1 << 6) });
|
||||||
alarms.addOptions({
|
|
||||||
label: GuildDB.alarms[i].name,
|
|
||||||
description: `Mute the role pings of this Alarm`,
|
|
||||||
value: GuildDB.alarms[i].name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opt = new ActionRowBuilder().addComponents(alarms);
|
|
||||||
|
|
||||||
return interaction.send({ components: [opt], flags: (1 << 6) });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -419,11 +405,11 @@ module.exports = {
|
|||||||
const opt = new ActionRowBuilder()
|
const opt = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(`DeleteAlarm-yes-${alarm.name}-${interaction.member.user.id}`)
|
.setCustomId(`DeleteAlarm-yes-${alarm.name}`)
|
||||||
.setLabel("Yes")
|
.setLabel("Yes")
|
||||||
.setStyle(ButtonStyle.Danger),
|
.setStyle(ButtonStyle.Danger),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(`DeleteAlarm-no-${alarm.name}-${interaction.member.user.id}`)
|
.setCustomId(`DeleteAlarm-no-${alarm.name}`)
|
||||||
.setLabel("No")
|
.setLabel("No")
|
||||||
.setStyle(ButtonStyle.Success)
|
.setStyle(ButtonStyle.Success)
|
||||||
)
|
)
|
||||||
@@ -461,13 +447,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
ManageAlarmIgnored: {
|
ManageAlarmIgnored: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
|
|
||||||
@@ -500,13 +479,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
ManageRule: {
|
ManageRule: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
|
|
||||||
@@ -551,13 +523,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
DeleteAlarmRule: {
|
DeleteAlarmRule: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.customId.split('-')[1]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.customId.split('-')[1]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
|
|
||||||
@@ -584,16 +549,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
EnableOrDisableAlarm: {
|
EnableOrDisableAlarm: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
let disable = interaction.customId.split('-')[1] == 'disable' ? true : false;
|
let disable = interaction.customId.split('-')[1] == 'disable';
|
||||||
alarm.disabled = disable;
|
alarm.disabled = disable;
|
||||||
GuildDB.alarms[alarmIndex] = alarm
|
GuildDB.alarms[alarmIndex] = alarm
|
||||||
|
|
||||||
@@ -607,7 +565,7 @@ module.exports = {
|
|||||||
|
|
||||||
let successEmbed = new EmbedBuilder()
|
let successEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Green)
|
.setColor(client.config.Colors.Green)
|
||||||
.setDescription(`**Success:** Successfully ${disable ? 'disabled' : 'enabled'} the Alarm **${interaction.values[0]}**`);
|
.setDescription(`**Success:**\n> Successfully ${disable ? 'disabled' : 'enabled'} the Alarm **${interaction.values[0]}**`);
|
||||||
|
|
||||||
return interaction.update({ embeds: [successEmbed], components: [] });
|
return interaction.update({ embeds: [successEmbed], components: [] });
|
||||||
}
|
}
|
||||||
@@ -615,13 +573,6 @@ module.exports = {
|
|||||||
|
|
||||||
MoveOrigin: {
|
MoveOrigin: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
let origin = [parseFloat(interaction.customId.split('-')[1]), parseFloat(interaction.customId.split('-')[2])];
|
let origin = [parseFloat(interaction.customId.split('-')[1]), parseFloat(interaction.customId.split('-')[2])];
|
||||||
@@ -646,13 +597,6 @@ module.exports = {
|
|||||||
|
|
||||||
RenameAlarm: {
|
RenameAlarm: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
let oldName = alarm.name;
|
let oldName = alarm.name;
|
||||||
@@ -677,13 +621,6 @@ module.exports = {
|
|||||||
|
|
||||||
MuteAlarm: {
|
MuteAlarm: {
|
||||||
run: async(client, interaction, GuildDB) => {
|
run: async(client, interaction, GuildDB) => {
|
||||||
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
|
||||||
return interaction.reply({
|
|
||||||
content: "This menu is not for you",
|
|
||||||
flags: (1 << 6)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
||||||
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
let alarmIndex = GuildDB.alarms.indexOf(alarm);
|
||||||
let mute = parseInt(interaction.customId.split('-')[1]);
|
let mute = parseInt(interaction.customId.split('-')[1]);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module.exports = {
|
|||||||
name: "armbands",
|
name: "armbands",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "View a list of armbads",
|
description: "View a list of armbads and what their image",
|
||||||
usage: "",
|
usage: "",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ module.exports = {
|
|||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "balance",
|
name: "balance",
|
||||||
description: "View your bank balance and count your cash",
|
description: "View your bank balance",
|
||||||
value: "balance",
|
value: "balance",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -28,7 +28,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "transfer",
|
name: "transfer",
|
||||||
description: "Transfer directly to users bank",
|
description: "Transfer money to another user",
|
||||||
value: "transfer",
|
value: "transfer",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [
|
options: [
|
||||||
|
|||||||
+15
-8
@@ -33,14 +33,14 @@ module.exports = {
|
|||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
name: "anonymous",
|
name: "anonymous",
|
||||||
description: "Make this bounty anonymous",
|
description: "Make this bounty anonymous (does not show your name)",
|
||||||
value: false,
|
value: false,
|
||||||
type: CommandOptions.Boolean,
|
type: CommandOptions.Boolean,
|
||||||
required: false
|
required: false
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
name: "pay",
|
name: "pay",
|
||||||
description: "Pay off your bounty (double price)",
|
description: "Pay off your bounty",
|
||||||
value: "pay",
|
value: "pay",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
}, {
|
}, {
|
||||||
@@ -59,6 +59,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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;
|
let banking;
|
||||||
if (args[0].name == 'set' || args[0].name == 'pay') {
|
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);
|
banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
@@ -104,7 +112,7 @@ module.exports = {
|
|||||||
setBy: (anonymous && !anonymous.value) ? interaction.member.user.id : null,
|
setBy: (anonymous && !anonymous.value) ? interaction.member.user.id : null,
|
||||||
value: args[0].options[1].value,
|
value: args[0].options[1].value,
|
||||||
});
|
});
|
||||||
playerStat.bountiesLength++;
|
playerStat.bountiesLength = playerStat.bounties.length; // Will ensure bounties length = # of bounties, even if bountiesLength does not exists in player stat.
|
||||||
|
|
||||||
await UpdatePlayer(client, playerStat, interaction);
|
await UpdatePlayer(client, playerStat, interaction);
|
||||||
|
|
||||||
@@ -117,7 +125,7 @@ module.exports = {
|
|||||||
|
|
||||||
} else if (args[0].name == 'pay') {
|
} else if (args[0].name == 'pay') {
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"gamertag": interaction.member.user.id});
|
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** Your user ID could not be found, contact an Admin.')] });
|
if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** Your user ID could not be found, contact an Admin.')] });
|
||||||
|
|
||||||
if (playerStat.bounties.length == 0) {
|
if (playerStat.bounties.length == 0) {
|
||||||
@@ -143,7 +151,7 @@ module.exports = {
|
|||||||
|
|
||||||
const newBalance = banking.guilds[GuildDB.serverID].balance - (totalBounty * 2);
|
const newBalance = banking.guilds[GuildDB.serverID].balance - (totalBounty * 2);
|
||||||
|
|
||||||
client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => {
|
await client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -160,10 +168,9 @@ module.exports = {
|
|||||||
|
|
||||||
} else if (args[0].name == 'view') {
|
} else if (args[0].name == 'view') {
|
||||||
|
|
||||||
// TODO: only get players with boutnies.length greater than 0
|
const activeBounties = await client.dbo.collection("players").find({
|
||||||
const activeBounties = await dbo.collection("players").find({
|
|
||||||
"bountiesLength": { $gt: 0 }
|
"bountiesLength": { $gt: 0 }
|
||||||
});
|
}).toArray();
|
||||||
|
|
||||||
let bountiesEmbed = new EmbedBuilder()
|
let bountiesEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
options: [{
|
options: [{
|
||||||
name: "faction_role",
|
name: "faction_role",
|
||||||
description: "Claim an armband for this faction role.",
|
description: "Claim an armband for this faction role",
|
||||||
value: "faction_role",
|
value: "faction_role",
|
||||||
type: CommandOptions.Role,
|
type: CommandOptions.Role,
|
||||||
required: true,
|
required: true,
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
const { insertPVPstats } = require('../database/player');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "compare-rating",
|
||||||
|
debug: false,
|
||||||
|
global: false,
|
||||||
|
description: "Compare combat ratings between yourself and another player",
|
||||||
|
usage: "[user or gamertag]",
|
||||||
|
permissions: {
|
||||||
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
member: [],
|
||||||
|
},
|
||||||
|
options: [{
|
||||||
|
name: "discord",
|
||||||
|
description: "Discord user to lookup stats",
|
||||||
|
value: "discord",
|
||||||
|
type: CommandOptions.User,
|
||||||
|
required: false,
|
||||||
|
}, {
|
||||||
|
name: "gamertag",
|
||||||
|
description: "Gamertag to lookup stats",
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: false,
|
||||||
|
}],
|
||||||
|
SlashCommand: {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {require("../structures/DayzRBot")} client
|
||||||
|
* @param {import("discord.js").Message} message
|
||||||
|
* @param {string[]} args
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
if (!discord && !gamertag) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`Please provide a Discord User or Gamertag`)] });
|
||||||
|
|
||||||
|
let leaderboard = await client.dbo.collection("players").aggregate([
|
||||||
|
{ $sort: { 'combatRating': -1 } }
|
||||||
|
]).toArray();
|
||||||
|
|
||||||
|
let comp;
|
||||||
|
if (discord) comp = leaderboard.find(s => s.discordID == discord);
|
||||||
|
if (gamertag) comp = leaderboard.find(s => s.gamertag == gamertag);
|
||||||
|
let self = leaderboard.find(s => s.discordID == interaction.member.user.id);
|
||||||
|
|
||||||
|
if (!client.exists(comp)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
||||||
|
if (!client.exists(self)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** You haven't linked your gamertag and your stats cannot be found.`)] });
|
||||||
|
|
||||||
|
let lbPosSelf = leaderboard.indexOf(self) + 1;
|
||||||
|
let lbPosComp = leaderboard.indexOf(comp) + 1;
|
||||||
|
|
||||||
|
let selfData = self.combatRatingHistory;
|
||||||
|
let compData = comp.combatRatingHistory;
|
||||||
|
if (selfData.length == 1) selfData.push(self.combatRating) // Make array 2 long for a straight line in the graph
|
||||||
|
if (compData.length == 1) compData.push(comp.combatRating) // Make array 2 long for a straight line in the graph
|
||||||
|
let selfDataMax = Math.max(...selfData);
|
||||||
|
let compDataMax = Math.max(...compData);
|
||||||
|
|
||||||
|
if (!client.exists(self.highestCombatRating) || self.highestCombatRating < selfDataMax) self.highestCombatRating = selfDataMax;
|
||||||
|
if (!client.exists(comp.highestCombatRating) || comp.highestCombatRating < compDataMax) comp.highestCombatRating = compDataMax;
|
||||||
|
|
||||||
|
let tag = comp.discordID != "" ? `<@${comp.discordID}>` : comp.gamertag;
|
||||||
|
|
||||||
|
let statsEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`<@${interaction.member.user.id}> vs ${tag} Combat Rating`)
|
||||||
|
.addFields(
|
||||||
|
{ name: `${self.gamertag}'s Combat Rating Stats`, value: `> Leaderboard Pos: # ${lbPosSelf}\n> Rating: ${self.combatRating}`, inline: false },
|
||||||
|
{ name: `${comp.gamertag}'s Combat Rating Stats`, value: `> Leaderboard Pos: # ${lbPosComp}\n> Rating: ${comp.combatRating}`, inline: false },
|
||||||
|
{ name: 'Rating Difference', value: `${Math.abs(self.combatRating - comp.combatRating)}`, inline: false },
|
||||||
|
);
|
||||||
|
|
||||||
|
const dataMax = Math.max(selfDataMax, compDataMax);
|
||||||
|
const dataMin = Math.min(Math.min(...selfData), Math.min(...compData))
|
||||||
|
|
||||||
|
const len = Math.max(selfData.length, compData.length);
|
||||||
|
const diff = Math.abs(selfData.length - compData.length);
|
||||||
|
if (selfData.length < compData.length) selfData.unshift(...(new Array(diff).fill(null, 0, diff)));
|
||||||
|
if (compData.length < selfData.length) compData.unshift(...(new Array(diff).fill(null, 0, diff)));
|
||||||
|
|
||||||
|
const chart = {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: new Array(len).fill(' ', 0, len),
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
data: selfData,
|
||||||
|
label: `${self.gamertag}'s Combat Ratings`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: compData,
|
||||||
|
label: `${comp.gamertag}'s Combat Ratings`,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
// Gives comfortable margin to the top of the y-axis
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
fontStyle: 'bold',
|
||||||
|
// max: Math.round(dataMax / 10) * 10 + 10,
|
||||||
|
// min: Math.round(dataMin / 10) * 10,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
// Gives a margin to the right of the whole graph
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
|
const chartURL = `https://quickchart.io/chart?c=${encodedChart}&bkg=${encodeURIComponent("#ded8d7")}`;
|
||||||
|
|
||||||
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [statsEmbed] });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
+406
-98
@@ -14,6 +14,53 @@ module.exports = {
|
|||||||
member: ["MANAGE_GUILD"],
|
member: ["MANAGE_GUILD"],
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: "killfeed",
|
||||||
|
description: "Configure the killfeed",
|
||||||
|
value: "killfeed",
|
||||||
|
type: CommandOptions.SubCommandGroup,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "channel",
|
||||||
|
description: "Configure the killfeed channel",
|
||||||
|
value: "channel",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
options: [{
|
||||||
|
name: "channel",
|
||||||
|
description: "The channel to configure",
|
||||||
|
value: "channel",
|
||||||
|
type: CommandOptions.Channel,
|
||||||
|
required: true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "show_coords",
|
||||||
|
description: "Show the coordinates of the victim in the killfeed channel.",
|
||||||
|
value: "show_coords",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
options: [{
|
||||||
|
name: "configuration",
|
||||||
|
description: "True or False",
|
||||||
|
value: false,
|
||||||
|
type: CommandOptions.Boolean,
|
||||||
|
required: true,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "show_weapon",
|
||||||
|
description: "Show the image of the weapon in the killfeed",
|
||||||
|
value: "show_weapon",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
options: [{
|
||||||
|
name: "configuration",
|
||||||
|
description: "True or False",
|
||||||
|
value: false,
|
||||||
|
type: CommandOptions.Boolean,
|
||||||
|
required: true,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "allowed_channels",
|
name: "allowed_channels",
|
||||||
description: "Set channels you're allowed to use the bot in",
|
description: "Set channels you're allowed to use the bot in",
|
||||||
@@ -48,11 +95,23 @@ module.exports = {
|
|||||||
required: true,
|
required: true,
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "clear",
|
||||||
|
description: "Clears all configured channels",
|
||||||
|
value: "clear",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "view",
|
||||||
|
description: "View configured allowed channels",
|
||||||
|
value: "view",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "set_channel",
|
name: "set_channel",
|
||||||
description: "Set one of the desired channels",
|
description: "Configure a channel",
|
||||||
value: "set_channel",
|
value: "set_channel",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options:[
|
options:[
|
||||||
@@ -79,7 +138,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "linked_gt_role",
|
name: "linked_gt_role",
|
||||||
description: "Access Role to give to users",
|
description: "Role for users with linked gamertags",
|
||||||
value: "linked_gt_role",
|
value: "linked_gt_role",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -92,7 +151,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "member_role",
|
name: "member_role",
|
||||||
description: "Role to give users when they join.",
|
description: "Role for users who join the server",
|
||||||
value: "member_role",
|
value: "member_role",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -107,31 +166,46 @@ module.exports = {
|
|||||||
name: "bot_admin_role",
|
name: "bot_admin_role",
|
||||||
description: "Set/remove bot admin role",
|
description: "Set/remove bot admin role",
|
||||||
value: "bot_admin_role",
|
value: "bot_admin_role",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommandGroup,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "action",
|
name: "add",
|
||||||
description: "Add or remove a role from the exclude list.",
|
description: "Configure role to be bot admin",
|
||||||
value: "action",
|
value: "add",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.SubCommand,
|
||||||
choices: [
|
options: [{
|
||||||
{ name: 'add', value: 'add' }, { name: 'remove', value: 'remove' },
|
name: "role",
|
||||||
],
|
description: "Role to confiure",
|
||||||
required: true,
|
value: "role",
|
||||||
|
type: CommandOptions.Role,
|
||||||
|
required: true,
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "role",
|
name: "remove",
|
||||||
description: "Role to configure",
|
description: "Remove configured role as bot admin",
|
||||||
value: "role",
|
value: "remove",
|
||||||
type: CommandOptions.Role,
|
type: CommandOptions.SubCommand,
|
||||||
required: true,
|
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: "Discord Server's dedicated admin role",
|
description: "Admin role to ping in admin logs channel",
|
||||||
value: "admin_role",
|
value: "admin_ping_role",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
name: "role",
|
name: "role",
|
||||||
@@ -143,26 +217,41 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "exclude",
|
name: "exclude",
|
||||||
description: "Exclude roles from users to use to claim a flag.",
|
description: "Exclude roles that can be used to claim armbands",
|
||||||
value: "exclude",
|
value: "exclude",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommandGroup,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "action",
|
name: "add",
|
||||||
description: "Add or remove a role from the exclude list.",
|
description: "Configure role to be excluded",
|
||||||
value: "action",
|
value: "add",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.SubCommand,
|
||||||
choices: [
|
options: [{
|
||||||
{ name: 'add', value: 'add' }, { name: 'remove', value: 'remove' },
|
name: "role",
|
||||||
],
|
description: "Role to confiure",
|
||||||
required: true,
|
value: "role",
|
||||||
|
type: CommandOptions.Role,
|
||||||
|
required: true,
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "role",
|
name: "remove",
|
||||||
description: "The role to manage",
|
description: "Remove configured role thats excluded",
|
||||||
value: "role",
|
value: "remove",
|
||||||
type: CommandOptions.Role,
|
type: CommandOptions.SubCommand,
|
||||||
required: true,
|
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,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -180,7 +269,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "starting_balance",
|
name: "starting_balance",
|
||||||
description: "Set the starting balance",
|
description: "Set the starting balance of a new user",
|
||||||
value: "starting_balance",
|
value: "starting_balance",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -188,7 +277,7 @@ module.exports = {
|
|||||||
description: "The amount to set the starting balance",
|
description: "The amount to set the starting balance",
|
||||||
value: "amount",
|
value: "amount",
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
min_value: 0.01,
|
min_value: 1.00,
|
||||||
required: true,
|
required: true,
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
@@ -222,7 +311,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "income_role",
|
name: "income_role",
|
||||||
description: "Add/update a role to earn income on /collect-income command",
|
description: "Set/remove roles to recieve income",
|
||||||
value: "set_income_role",
|
value: "set_income_role",
|
||||||
type: CommandOptions.SubCommandGroup,
|
type: CommandOptions.SubCommandGroup,
|
||||||
options: [
|
options: [
|
||||||
@@ -266,7 +355,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "income_limiter",
|
name: "income_limiter",
|
||||||
description: "Change the number of hours to wait before collecting income",
|
description: "Change the number of hours to wait before collecting next income",
|
||||||
value: "income_limiter",
|
value: "income_limiter",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -274,24 +363,13 @@ module.exports = {
|
|||||||
description: "Number of hours till income can be collected",
|
description: "Number of hours till income can be collected",
|
||||||
value: 168.00, // 1 week
|
value: 168.00, // 1 week
|
||||||
type: CommandOptions.Float,
|
type: CommandOptions.Float,
|
||||||
|
min_value: 1.00,
|
||||||
required: true,
|
required: true,
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "show_killfeed_coords",
|
|
||||||
description: "Show the coordinates of the killer or victim in the killfeed channel.",
|
|
||||||
value: "show_killfeed_coords",
|
|
||||||
type: CommandOptions.SubCommand,
|
|
||||||
options: [{
|
|
||||||
name: "configuration",
|
|
||||||
description: "True or False",
|
|
||||||
value: false,
|
|
||||||
type: CommandOptions.Boolean,
|
|
||||||
required: true,
|
|
||||||
}]
|
|
||||||
}, {
|
|
||||||
name: "combat-log-timer",
|
name: "combat-log-timer",
|
||||||
description: "Adjust log timeout for combat prevention. (0 disables combat log)",
|
description: "Adjust number of minutes to detect combat logs (0 disables combat log)",
|
||||||
value: "combat-log-timer",
|
value: "combat-log-timer",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -328,6 +406,19 @@ module.exports = {
|
|||||||
required: true,
|
required: true,
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "welcome_message_server_name",
|
||||||
|
description: "Configure the server name in the welcome message",
|
||||||
|
value: "welcome_message_server_name",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
options: [{
|
||||||
|
name: "name",
|
||||||
|
description: "Server name to include in welcome message",
|
||||||
|
value: "name",
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: true,
|
||||||
|
}]
|
||||||
|
}
|
||||||
],
|
],
|
||||||
SlashCommand: {
|
SlashCommand: {
|
||||||
/**
|
/**
|
||||||
@@ -348,9 +439,10 @@ module.exports = {
|
|||||||
switch(args[0].name) {
|
switch(args[0].name) {
|
||||||
|
|
||||||
case 'allowed_channels':
|
case 'allowed_channels':
|
||||||
const channelid = args[0].options[0].options[0].value;
|
const channels_config = args[0].options[0].name;
|
||||||
|
const channelid = ['add', 'remove'].includes(channels_config) ? args[0].options[0].options[0].value : null;
|
||||||
|
|
||||||
if (args[0].options[0].name == 'add') {
|
if (channels_config == 'add') {
|
||||||
const channelAdd = client.GetChannel(channelid);
|
const channelAdd = client.GetChannel(channelid);
|
||||||
|
|
||||||
const newChannelErrorEmbed = new EmbedBuilder().setColor(client.config.Colors.Red)
|
const newChannelErrorEmbed = new EmbedBuilder().setColor(client.config.Colors.Red)
|
||||||
@@ -369,7 +461,7 @@ module.exports = {
|
|||||||
.setDescription(`**Success:** Set <#${channelid}> as an allowed channel.`);
|
.setDescription(`**Success:** Set <#${channelid}> as an allowed channel.`);
|
||||||
|
|
||||||
return interaction.send({ embeds: [successAddChannelEmbed] });
|
return interaction.send({ embeds: [successAddChannelEmbed] });
|
||||||
} else if (args[0].options[0].name=='remove') {
|
} else if (channels_config == 'remove') {
|
||||||
|
|
||||||
const errorChannelNotAvailable = new EmbedBuilder()
|
const errorChannelNotAvailable = new EmbedBuilder()
|
||||||
.setDescription(`**Error Notice:** <#${channelid}> is not in allowed channels.`)
|
.setDescription(`**Error Notice:** <#${channelid}> is not in allowed channels.`)
|
||||||
@@ -384,22 +476,74 @@ module.exports = {
|
|||||||
const optRemoveChannel = new ActionRowBuilder()
|
const optRemoveChannel = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(`RemoveAllowedChannels-yes-${interaction.member.user.id}`)
|
.setCustomId(`RemoveAllowedChannels-yes-${channelid}-${interaction.member.user.id}`)
|
||||||
.setLabel("Yes")
|
.setLabel("Yes")
|
||||||
.setStyle(ButtonStyle.Danger),
|
.setStyle(ButtonStyle.Danger),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(`RemoveAllowedChannels-no-${interaction.member.user.id}`)
|
.setCustomId(`RemoveAllowedChannels-no-${channelid}-${interaction.member.user.id}`)
|
||||||
.setLabel("No")
|
.setLabel("No")
|
||||||
.setStyle(ButtonStyle.Success)
|
.setStyle(ButtonStyle.Success)
|
||||||
)
|
)
|
||||||
|
|
||||||
return interaction.send({ embeds: [promptRemoveChannel], components: [optRemoveChannel], flags: (1 << 6) });
|
return interaction.send({ embeds: [promptRemoveChannel], components: [optRemoveChannel], flags: (1 << 6) });
|
||||||
|
|
||||||
|
} else if (channels_config == 'clear') {
|
||||||
|
|
||||||
|
const errorNoAllowedChannels = new EmbedBuilder()
|
||||||
|
.setDescription(`**Error Notice:**\n> No allowed channels configured to clear`)
|
||||||
|
.setColor(client.config.Colors.Red)
|
||||||
|
|
||||||
|
if (GuildDB.allowedChannels.length == 0) return interaction.send({ embeds: [errorNoAllowedChannels] });
|
||||||
|
|
||||||
|
const promptClearChannels = new EmbedBuilder()
|
||||||
|
.setTitle(`Are you sure you want to clear all configured channels from allowed channels?`)
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
|
||||||
|
const optClearChannels = new ActionRowBuilder()
|
||||||
|
.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`ClearAllowedChannels-yes-${interaction.member.user.id}`)
|
||||||
|
.setLabel("Yes")
|
||||||
|
.setStyle(ButtonStyle.Danger),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`ClearAllowedChannels-no-${interaction.member.user.id}`)
|
||||||
|
.setLabel("No")
|
||||||
|
.setStyle(ButtonStyle.Success)
|
||||||
|
)
|
||||||
|
|
||||||
|
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':
|
case 'bot_admin_role':
|
||||||
if (args[0].options[0].value == 'add') {
|
const bot_admin_config = args[0].options[0].name;
|
||||||
const botAdminRoleId = args[0].options[1].value;
|
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) => {
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$push: {"server.botAdminRoles": botAdminRoleId}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
@@ -411,7 +555,7 @@ module.exports = {
|
|||||||
|
|
||||||
return interaction.send({ embeds: [successSetBotAdminRoleEmbed] });
|
return interaction.send({ embeds: [successSetBotAdminRoleEmbed] });
|
||||||
|
|
||||||
} else if (args[0].options[0].value== 'remove') {
|
} else if (bot_admin_config == 'remove') {
|
||||||
|
|
||||||
if (!GuildDB.botAdminRoles.includes(botAdminRoleId)) {
|
if (!GuildDB.botAdminRoles.includes(botAdminRoleId)) {
|
||||||
const nonAdminRoleEmbed = new EmbedBuilder()
|
const nonAdminRoleEmbed = new EmbedBuilder()
|
||||||
@@ -438,9 +582,33 @@ module.exports = {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return interaction.send({ embeds: [promptRemoveAdminRole], components: [optRemoveAdminRole], flags: (1 << 6) });
|
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] });
|
||||||
|
}
|
||||||
|
|
||||||
|
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_role':
|
case 'admin_ping_role':
|
||||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.adminRole": args[0].options[0].value}}, (err, res) => {
|
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);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
@@ -452,27 +620,54 @@ module.exports = {
|
|||||||
return interaction.send({ embeds: [successSetAdminRoleEmbed] });
|
return interaction.send({ embeds: [successSetAdminRoleEmbed] });
|
||||||
|
|
||||||
case 'exclude':
|
case 'exclude':
|
||||||
if (args[0].options[0].value == 'add') {
|
const exclude_config = args[0].options[0].name;
|
||||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$push: {'server.excludedRoles': args[0].options[1].value}}, (err, res) => {
|
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);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
})
|
})
|
||||||
|
|
||||||
const successExcludeEmbed = new EmbedBuilder()
|
const successExcludeEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Green)
|
.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] });
|
return interaction.send({ embeds: [successExcludeEmbed] });
|
||||||
|
|
||||||
} else if (args[0].options[0].value == 'remove') {
|
} else if (exclude_config == 'remove') {
|
||||||
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$pull: {'server.excludedRoles': args[0].options[1].value}}, (err, res) => {
|
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$pull: {'server.excludedRoles': exclude_roleid}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
})
|
})
|
||||||
|
|
||||||
const successRemoveExcludeEmbed = new EmbedBuilder()
|
const successRemoveExcludeEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Green)
|
.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] });
|
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':
|
case 'reset':
|
||||||
@@ -496,24 +691,67 @@ module.exports = {
|
|||||||
return interaction.send({ embeds: [promptReset], components: [optReset], flags: (1 << 6) });
|
return interaction.send({ embeds: [promptReset], components: [optReset], flags: (1 << 6) });
|
||||||
|
|
||||||
case 'view':
|
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()
|
const settingsEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setTitle('Current Guild Configurations')
|
.setTitle('Current Guild Configurations')
|
||||||
.addFields(
|
.addFields(
|
||||||
{ name: 'Guild ID', value: `\`\`\`arm\n${GuildDB.serverID}\`\`\``, inline: true },
|
{ name: 'Guild ID', value: `${w}${f}${GuildDB.serverID}${w}`, inline: true },
|
||||||
{ name: 'Has Allowed Channels?', value: `\`\`\`diff\n${channelColor}${GuildDB.customChannelStatus}\`\`\`${channelsInfo}`, inline: true },
|
{ name: 'Server Name', value: `${w}${f}${GuildDB.serverName}${w}`, inline: true },
|
||||||
{ name: 'Has bot admin role?', value: `\`\`\`diff\n${botAdminRoleColor}${client.exists(GuildDB.botAdmin)}\`\`\`${botAdminRoles}`, inline: true },
|
{ name: 'Auto Restart', value: `${w}${a}${autoRestart}${w}`, inline: true },
|
||||||
{ name: 'Excluded roles?', value: `\`\`\`diff\n${excludedRolesColor}${GuildDB.excludedRoles.length > 0}\`\`\`${excludedRolesInfo}` },
|
{ 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] });
|
return interaction.send({ embeds: [settingsEmbed] });
|
||||||
@@ -532,19 +770,6 @@ module.exports = {
|
|||||||
|
|
||||||
return interaction.send({ embeds: [successSetChannelEmbed] });
|
return interaction.send({ embeds: [successSetChannelEmbed] });
|
||||||
|
|
||||||
case 'show_killfeed_coords':
|
|
||||||
const showKillfeedCoordsConfiguration = args[0].options[0].value ? 1 : 0;
|
|
||||||
|
|
||||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedCoords": showKillfeedCoordsConfiguration}}, (err, res) => {
|
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
|
|
||||||
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
|
||||||
.setDescription(`Successfully configured the killfeed to ${showKillfeedCoordsConfiguration ? 'show' : 'not show'} coordinates.`)
|
|
||||||
.setColor(client.config.Colors.Green);
|
|
||||||
|
|
||||||
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
|
||||||
|
|
||||||
case 'linked_gt_role':
|
case 'linked_gt_role':
|
||||||
const linked_gt_role = args[0].options[0].value;
|
const linked_gt_role = args[0].options[0].value;
|
||||||
|
|
||||||
@@ -724,6 +949,65 @@ module.exports = {
|
|||||||
|
|
||||||
return interaction.send({ embeds: [successToggleEMPpurchaseEmbed] });
|
return interaction.send({ embeds: [successToggleEMPpurchaseEmbed] });
|
||||||
|
|
||||||
|
case 'killfeed':
|
||||||
|
const killfeed_configuration = args[0].options[0].name;
|
||||||
|
|
||||||
|
if (killfeed_configuration == 'channel') {
|
||||||
|
|
||||||
|
const channel = args[0].options[0].options[0].value;
|
||||||
|
|
||||||
|
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID},{$set: {'server.killfeedChannel': channel}}, (err, res) => {
|
||||||
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const successConfigureKillfeedChannel = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setDescription(`Successfully configured the killfeed channel to <#${channel}>`);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [successConfigureKillfeedChannel] });
|
||||||
|
|
||||||
|
} else if (killfeed_configuration == 'show_coords') {
|
||||||
|
const showKillfeedCoordsConfiguration = args[0].options[0].options[0].value ? 1 : 0;
|
||||||
|
|
||||||
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedCoords": showKillfeedCoordsConfiguration}}, (err, res) => {
|
||||||
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
||||||
|
.setDescription(`Successfully configured the killfeed to ${showKillfeedCoordsConfiguration ? 'show' : 'not show'} coordinates.`)
|
||||||
|
.setColor(client.config.Colors.Green);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
||||||
|
|
||||||
|
} else if (killfeed_configuration == 'show_weapon') {
|
||||||
|
|
||||||
|
const showKillfeedWeaponConfiguration = args[0].options[0].options[0].value ? 1 : 0;
|
||||||
|
|
||||||
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.showKillfeedWeapon": showKillfeedWeaponConfiguration}}, (err, res) => {
|
||||||
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const successConfigureShowKillfeedCoords = new EmbedBuilder()
|
||||||
|
.setDescription(`Successfully configured the killfeed to ${showKillfeedWeaponConfiguration ? 'show' : 'not show'} weapon icons.`)
|
||||||
|
.setColor(client.config.Colors.Green);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [successConfigureShowKillfeedCoords] });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'welcome_message_server_name':
|
||||||
|
const server_name = args[0].options[0].value;
|
||||||
|
|
||||||
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.serverName":server_name}}, (err, res) => {
|
||||||
|
if (err) return client.sendInternalError(interacion, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const succcessUpdateServerName = new EmbedBuilder()
|
||||||
|
.setDescription(`Successfully configured the server name to **${server_name}** in the welcome message.`)
|
||||||
|
.setColor(client.config.Colors.Green);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [succcessUpdateServerName] });
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return client.sendInternalError(interaction, 'There was an error parsing the config command');
|
return client.sendInternalError(interaction, 'There was an error parsing the config command');
|
||||||
}
|
}
|
||||||
@@ -734,8 +1018,8 @@ module.exports = {
|
|||||||
|
|
||||||
RemoveAllowedChannels: {
|
RemoveAllowedChannels: {
|
||||||
run: async (client, interaction, GuildDB) => {
|
run: async (client, interaction, GuildDB) => {
|
||||||
if (!queryString.endsWith(interaction.member.user.id)) {
|
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
||||||
return ButtonInteraction.reply({
|
return interaction.reply({
|
||||||
content: "This button is not for you",
|
content: "This button is not for you",
|
||||||
flags: (1 << 6)
|
flags: (1 << 6)
|
||||||
})
|
})
|
||||||
@@ -743,14 +1027,38 @@ module.exports = {
|
|||||||
let action = ''
|
let action = ''
|
||||||
if (interaction.customId.split('-')[1]=='yes') {
|
if (interaction.customId.split('-')[1]=='yes') {
|
||||||
action = 'removed';
|
action = 'removed';
|
||||||
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, (err, res) => {
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": interaction.customId.split('-')[2]}}, (err, res) => {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
});
|
});
|
||||||
} else if (interaction.customId.split('-')[1]=='no') action = 'kept';
|
} else if (interaction.customId.split('-')[1]=='no') action = 'kept';
|
||||||
|
|
||||||
const successEmbed = new EmbedBuilder()
|
const successEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Green)
|
.setColor(client.config.Colors.Green)
|
||||||
.setTitle(`Success: You ${action} the channel.`)
|
.setTitle(`**Success**\n> Successfullly ${action} the channel.`)
|
||||||
|
|
||||||
|
return interaction.update({ embeds: [successEmbed], components: [] });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
ClearAllowedChannels: {
|
||||||
|
run: async (client, interaction, GuildDB) => {
|
||||||
|
if (!interaction.customId.endsWith(interaction.member.user.id)) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: "This buttpm is not for you",
|
||||||
|
flags: (1 << 6)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let action;
|
||||||
|
if (interaction.customId.split('-')[1] == 'yes') {
|
||||||
|
action = 'cleared';
|
||||||
|
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set:{"server.allowedChannels":[]}}, (err, res) => {
|
||||||
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
|
})
|
||||||
|
} else if (interaction.customId.split('-')[1] == 'no') action = 'kept';
|
||||||
|
|
||||||
|
const successEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setTitle(`**Success**\n> Successfully ${action} all configured channels.`);
|
||||||
|
|
||||||
return interaction.update({ embeds: [successEmbed], components: [] });
|
return interaction.update({ embeds: [successEmbed], components: [] });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +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: [{
|
|
||||||
name: 'sync-logs',
|
|
||||||
description: 'download the Nitrado logs and run checks now',
|
|
||||||
value: 'sync-logs',
|
|
||||||
type: CommandOptions.SubCommand,
|
|
||||||
}, {
|
|
||||||
name: 'server-connection-stats',
|
|
||||||
description: 'view player connection stats',
|
|
||||||
value: 'server-connection-stats',
|
|
||||||
type: CommandOptions.SubCommand,
|
|
||||||
}],
|
|
||||||
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) })
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].name == 'server-connection-stats') {
|
|
||||||
let statsEmbed = new EmbedBuilder()
|
|
||||||
.setColor(client.config.Colors.Default)
|
|
||||||
.setTitle(`Server connection stats`);
|
|
||||||
|
|
||||||
statsEmbed.addFields({ name: 'All time Unique connections', value: `> ${stats.length}`, inline: false });
|
|
||||||
|
|
||||||
let month3 = new Date().setMonth(new Date().getMonth() - 3);
|
|
||||||
let month3Players = await client.dbo.collection("players").find({"lastConnectDate": {$gt: month3}});
|
|
||||||
statsEmbed.addFields({ name: 'Unique connections in the last 3 months', value: `> ${month3Players.length}`, inline: false });
|
|
||||||
|
|
||||||
let month = new Date().setMonth(new Date().getMonth() - 1);
|
|
||||||
let monthlyPlayers = await client.dbo.collection("players").find({"lastConnectDate": {$gt: month}});
|
|
||||||
statsEmbed.addFields({ name: 'Unique connections in the last month', value: `> ${monthlyPlayers.length}`, inline: false });
|
|
||||||
|
|
||||||
let week = new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000)
|
|
||||||
let weeklyPlayers = await client.dbo.collection("players").find({"lastConnectDate": {$gt: week}});
|
|
||||||
statsEmbed.addFields({ name: 'Unique connections in the last week', value: `> ${weeklyPlayers.length}`, inline: false });
|
|
||||||
|
|
||||||
let today = new Date(new Date().getTime() - 1 * 24 * 60 * 60 * 1000)
|
|
||||||
let dailyPlayers = await client.dbo.collection("players").find({"lastConnectDate": {$gt: today}});
|
|
||||||
statsEmbed.addFields({ name: 'Unique connections in the last 24 hours', value: `> ${dailyPlayers.length}`, inline: false });
|
|
||||||
|
|
||||||
return interaction.send({ embeds: [statsEmbed] });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Interactions: {}
|
|
||||||
}
|
|
||||||
+13
-5
@@ -14,7 +14,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
options: [{
|
options: [{
|
||||||
name: "player-track",
|
name: "player-track",
|
||||||
description: "track a player and announce location",
|
description: "Track a player and announce location",
|
||||||
value: "player-track",
|
value: "player-track",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
options: [{
|
options: [{
|
||||||
@@ -26,7 +26,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "time",
|
name: "time",
|
||||||
description: "duration of tracking",
|
description: "Duration of tracking",
|
||||||
value: "time",
|
value: "time",
|
||||||
type: CommandOptions.Integer,
|
type: CommandOptions.Integer,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -37,14 +37,14 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "event-name",
|
name: "event-name",
|
||||||
description: "name of the event",
|
description: "Name of the event",
|
||||||
value: "event-name",
|
value: "event-name",
|
||||||
type: CommandOptions.String,
|
type: CommandOptions.String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "channel",
|
name: "channel",
|
||||||
description: "channel to host event",
|
description: "Channel to post tracking data",
|
||||||
value: "channel",
|
value: "channel",
|
||||||
type: CommandOptions.Channel,
|
type: CommandOptions.Channel,
|
||||||
channel_types: [0], // Restrict to text channel
|
channel_types: [0], // Restrict to text channel
|
||||||
@@ -58,7 +58,7 @@ module.exports = {
|
|||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
name: "delete",
|
name: "delete",
|
||||||
description: "delete an active event",
|
description: "Delete an active event",
|
||||||
value: "delete",
|
value: "delete",
|
||||||
type: CommandOptions.SubCommand
|
type: CommandOptions.SubCommand
|
||||||
}],
|
}],
|
||||||
@@ -72,6 +72,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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);
|
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||||
let canUseCommand = false;
|
let canUseCommand = false;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module.exports = {
|
|||||||
let noExcludes = new EmbedBuilder()
|
let noExcludes = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setTitle('Excluded Roles')
|
.setTitle('Excluded Roles')
|
||||||
.setDescription('> There have been no configured channels');
|
.setDescription('> There have been no excluded roles');
|
||||||
|
|
||||||
return interaction.send({ embeds: [noExcludes] });
|
return interaction.send({ embeds: [noExcludes] });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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});
|
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 \`.`)] });
|
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 \`.`)] });
|
||||||
|
|
||||||
@@ -87,7 +95,7 @@ module.exports = {
|
|||||||
|
|
||||||
playerStat.discordID = interaction.member.user.id;
|
playerStat.discordID = interaction.member.user.id;
|
||||||
|
|
||||||
await UpdatePlayer(client, player, interaction);
|
await UpdatePlayer(client, playerStat, interaction);
|
||||||
|
|
||||||
let member = interaction.guild.members.cache.get(interaction.member.user.id);
|
let member = interaction.guild.members.cache.get(interaction.member.user.id);
|
||||||
if (client.exists(GuildDB.linkedGamertagRole)) {
|
if (client.exists(GuildDB.linkedGamertagRole)) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js');
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js');
|
||||||
|
const { UpdatePlayer } = require('../database/player');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "gamertag-unlink",
|
name: "gamertag-unlink",
|
||||||
@@ -20,6 +21,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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});
|
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.`)] });
|
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.`)] });
|
||||||
|
|
||||||
|
|||||||
+26
-21
@@ -1,5 +1,6 @@
|
|||||||
const { EmbedBuilder } = require("discord.js");
|
const { EmbedBuilder } = require("discord.js");
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
const package = require("../package");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "help",
|
name: "help",
|
||||||
@@ -27,13 +28,13 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "support",
|
name: "support",
|
||||||
description: "Get support for Applicatz",
|
description: "Get support for Application",
|
||||||
value: "support",
|
value: "support",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "credits",
|
name: "credits",
|
||||||
description: "DayZR Bot Credits",
|
description: "DayZ.R Bot Credits",
|
||||||
value: "credits",
|
value: "credits",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
},
|
},
|
||||||
@@ -53,14 +54,8 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
run: async (client, interaction, args, start) => {
|
run: async (client, interaction, args, {GuildDB}, start) => {
|
||||||
if (args[0].name == 'version') {
|
if (args[0].name == 'commands') {
|
||||||
const versionEmbed = new EmbedBuilder()
|
|
||||||
.setTitle(`Current DayZR Bot Version`)
|
|
||||||
.setDescription(client.config.Version);
|
|
||||||
|
|
||||||
return interaction.send({ embeds: [versionEmbed] });
|
|
||||||
} else if (args[0].name == 'commands') {
|
|
||||||
let Commands = client.commands.filter((cmd) => {
|
let Commands = client.commands.filter((cmd) => {
|
||||||
return !cmd.debug
|
return !cmd.debug
|
||||||
}).map((cmd) =>
|
}).map((cmd) =>
|
||||||
@@ -111,9 +106,9 @@ module.exports = {
|
|||||||
} else if (args[0].name == 'support') {
|
} else if (args[0].name == 'support') {
|
||||||
const supportEmbed = new EmbedBuilder()
|
const supportEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**__DayZR Bot Support__**
|
.setDescription(`**__DayZ.R Bot Support__**
|
||||||
|
|
||||||
Are you experiencing troubles with the DayZR Bot?
|
Are you experiencing troubles with the DayZ.R Bot?
|
||||||
Do you have questions or concerns?
|
Do you have questions or concerns?
|
||||||
Do you require help to use the bot?
|
Do you require help to use the bot?
|
||||||
Do you have a feature you'd like to see?
|
Do you have a feature you'd like to see?
|
||||||
@@ -129,7 +124,8 @@ module.exports = {
|
|||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setTitle('DayzRBot Credits')
|
.setTitle('DayzRBot Credits')
|
||||||
.setDescription(`
|
.setDescription(`
|
||||||
**Bot Author:** McDazzzled#5307
|
**Bot Author:** mcdazzzled
|
||||||
|
**Github:** https://github.com/SowinskiBraeden/dayz-reforger
|
||||||
|
|
||||||
${client.config.SupportServer}
|
${client.config.SupportServer}
|
||||||
`);
|
`);
|
||||||
@@ -137,17 +133,26 @@ module.exports = {
|
|||||||
return interaction.send({ embeds: [creditsEmbed] })
|
return interaction.send({ embeds: [creditsEmbed] })
|
||||||
} else if (args[0].name == 'stats') {
|
} else if (args[0].name == 'stats') {
|
||||||
const end = new Date().getTime();
|
const end = new Date().getTime();
|
||||||
|
|
||||||
|
const totalGuilds = await client.shard.fetchClientValues("guilds.cache.size").then(results => {
|
||||||
|
return results.reduce((acc, guildCount) => acc + guildCount, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalUsers = await client.shard.broadcastEval(c => {
|
||||||
|
c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||||
|
}).then(data => data.reduce((acc, memberCount) => acc + memberCount, 0));
|
||||||
|
|
||||||
const stats = new EmbedBuilder()
|
const stats = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setTitle('DayzRBot Statistics')
|
.setTitle('DayZ Reforger Bot Statistics')
|
||||||
.addFields(
|
.addFields(
|
||||||
{ name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true },
|
{ name: 'Guilds', value: `\`\`\`${totalGuilds}\`\`\``, inline: true },
|
||||||
{ name: 'Users', value: `${client.users.cache.size}`, inline: true },
|
{ name: 'Users', value: `\`\`\`${totalUsers}\`\`\``, inline: true },
|
||||||
{ name: 'Latency', value: `${end - start}ms`, inline: true },
|
{ name: 'Latency', value: `\`\`\`${end - start}ms\`\`\``, inline: true },
|
||||||
{ name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, 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: 'Bot Version', value: `\`\`\`${client.config.Dev} v${client.config.Version}\`\`\``, inline: true },
|
||||||
{ name: 'Discord Version', value: 'Discord.js v^14.8.0', inline: true },
|
{ name: 'Discord Version', value: `\`\`\`Discord.js ${package.dependencies["discord.js"]}\`\`\``, inline: true },
|
||||||
)
|
);
|
||||||
|
|
||||||
return interaction.send({ embeds: [stats] })
|
return interaction.send({ embeds: [stats] })
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-6
@@ -5,7 +5,7 @@ module.exports = {
|
|||||||
name: "leaderboard",
|
name: "leaderboard",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "View server statistics leaderboard",
|
description: "View server stats leaderboard",
|
||||||
usage: "[category] [limit]",
|
usage: "[category] [limit]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
@@ -30,10 +30,13 @@ module.exports = {
|
|||||||
{ name: "Longest Kill", value: "longestKill" },
|
{ name: "Longest Kill", value: "longestKill" },
|
||||||
{ name: "KDR", value: "KDR" },
|
{ name: "KDR", value: "KDR" },
|
||||||
{ name: "Server Connections", value: "connections" },
|
{ name: "Server Connections", value: "connections" },
|
||||||
|
{ name: "Shots Landed", value: "shotsLanded" },
|
||||||
|
{ name: "Times Shot", value: "timesShot" },
|
||||||
|
{ name: "Combat Rating", value: "combatRating" },
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
name: "limit",
|
name: "limit",
|
||||||
description: "leaderboard limit",
|
description: "Leaderboard limit",
|
||||||
value: "limit",
|
value: "limit",
|
||||||
type: CommandOptions.Integer,
|
type: CommandOptions.Integer,
|
||||||
min_value: 1,
|
min_value: 1,
|
||||||
@@ -49,6 +52,15 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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 category = args[0].value;
|
||||||
const limit = args[1].value;
|
const limit = args[1].value;
|
||||||
|
|
||||||
@@ -81,7 +93,10 @@ module.exports = {
|
|||||||
category == 'totalSessionTime' ? "Total Time Played" :
|
category == 'totalSessionTime' ? "Total Time Played" :
|
||||||
category == 'longestSessionTime' ? "Longest Game Session" :
|
category == 'longestSessionTime' ? "Longest Game Session" :
|
||||||
category == 'KDR' ? "Kill Death Ratio" :
|
category == 'KDR' ? "Kill Death Ratio" :
|
||||||
category == 'connections' ? "Times Connected" : 'N/A Error';
|
category == 'connections' ? "Times Connected" :
|
||||||
|
category == 'shotsLanded' ? "Shots Landed" :
|
||||||
|
category == 'timesShot' ? "Times Shot" :
|
||||||
|
category == 'combatRating' ? "Combat Rating" : 'N/A Error';
|
||||||
|
|
||||||
leaderboardEmbed.setTitle(`**${title} - DayZ Reforger**`);
|
leaderboardEmbed.setTitle(`**${title} - DayZ Reforger**`);
|
||||||
|
|
||||||
@@ -100,16 +115,19 @@ module.exports = {
|
|||||||
category == 'totalSessionTime' ? `**Total:** ${client.secondsToDhms(leaderboard[i].totalSessionTime)}\n> **Last Session:** ${client.secondsToDhms(leaderboard[i].lastSessionTime)}` :
|
category == 'totalSessionTime' ? `**Total:** ${client.secondsToDhms(leaderboard[i].totalSessionTime)}\n> **Last Session:** ${client.secondsToDhms(leaderboard[i].lastSessionTime)}` :
|
||||||
category == 'longestSessionTime' ? `**Longest Game Session:** ${client.secondsToDhms(leaderboard[i].longestSessionTime)}` :
|
category == 'longestSessionTime' ? `**Longest Game Session:** ${client.secondsToDhms(leaderboard[i].longestSessionTime)}` :
|
||||||
category == 'KDR' ? `**KDR: ${leaderboard[i].KDR.toFixed(2)}**` :
|
category == 'KDR' ? `**KDR: ${leaderboard[i].KDR.toFixed(2)}**` :
|
||||||
category == 'connection' ? `**Connections: ${leaderboard[i].connections}**` : 'N/A Error';
|
category == 'connection' ? `**Connections: ${leaderboard[i].connections}**` :
|
||||||
|
category == 'combatRating' ? `**Combat Rating:** ${leaderboard[i].combatRating}` :
|
||||||
|
category == 'shotsLanded' ? `**Shots Landed:** ${leaderboard[i].shotsLanded}` :
|
||||||
|
category == 'timesShot' ? `**Times Shot:** ${leaderboard[i].timesShot}` : 'N/A Error';
|
||||||
|
|
||||||
if (category == 'money') des += `**${i+1}.** <@${leaderboard[i].user.userID}> - **${stats}**\n`
|
if (category == 'money') des += `**${i+1}.** <@${leaderboard[i].user.userID}> - **${stats}**\n`
|
||||||
else if (category == 'totalSessionTime' || category == 'longestSessionTime') {
|
else if (category == 'totalSessionTime' || category == 'longestSessionTime' || category == 'combatRating') {
|
||||||
tag = leaderboard[i].discordID != "" ? `<@${leaderboard[i].discordID}>` : leaderboard[i].gamertag;
|
tag = leaderboard[i].discordID != "" ? `<@${leaderboard[i].discordID}>` : leaderboard[i].gamertag;
|
||||||
des += `**${i+1}.** ${tag}\n> ${stats}\n\n`;
|
des += `**${i+1}.** ${tag}\n> ${stats}\n\n`;
|
||||||
} else leaderboardEmbed.addFields({ name: `**${i+1}. ${leaderboard[i].gamertag}**`, value: `**${stats}**`, inline: true });
|
} else leaderboardEmbed.addFields({ name: `**${i+1}. ${leaderboard[i].gamertag}**`, value: `**${stats}**`, inline: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (['money', 'totalSessionTime', 'longestSessionTime'].includes(category)) leaderboardEmbed.setDescription(des);
|
if (['money', 'totalSessionTime', 'longestSessionTime', 'combatRating'].includes(category)) leaderboardEmbed.setDescription(des);
|
||||||
|
|
||||||
return interaction.send({ embeds: [leaderboardEmbed] });
|
return interaction.send({ embeds: [leaderboardEmbed] });
|
||||||
},
|
},
|
||||||
|
|||||||
+16
-1
@@ -1,4 +1,5 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { nearest } = require('../database/destinations');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "location",
|
name: "location",
|
||||||
@@ -19,15 +20,29 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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) || !client.exists(GuildDB.Nitrado.Mission)) {
|
||||||
|
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});
|
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) });
|
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) });
|
||||||
|
if (!client.exists(playerStat.time)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** There is no location saved to your gamertag yet. Make sure you've logged into the server for more than **5 minutes.**`)], flags: (1 << 6)});
|
||||||
|
|
||||||
|
console.log(true);
|
||||||
|
|
||||||
let newDt = await client.getDateEST(playerStat.time);
|
let newDt = await client.getDateEST(playerStat.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
|
const destination = nearest(playerStat.pos, GuildDB.Nitrado.Mission);
|
||||||
|
|
||||||
let lastLocation = new EmbedBuilder()
|
let lastLocation = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Location - <t:${unixTime}>**\nYour last location was detected at **[${playerStat.pos[0]}, ${playerStat.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${playerStat.pos[0]};${playerStat.pos[1]})**`)
|
.setDescription(`**Location - <t:${unixTime}>**\nYour last location was detected at **[${playerStat.pos[0]}, ${playerStat.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${playerStat.pos[0]};${playerStat.pos[1]})**\n${destination}`)
|
||||||
|
|
||||||
return interaction.send({ embeds: [lastLocation], flags: (1 << 6) });
|
return interaction.send({ embeds: [lastLocation], flags: (1 << 6) });
|
||||||
},
|
},
|
||||||
|
|||||||
+9
-1
@@ -5,7 +5,7 @@ module.exports = {
|
|||||||
name: "lookup",
|
name: "lookup",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "Search for a users discord or gamertag",
|
description: "Search for a user's Discord or Gamertag",
|
||||||
usage: "[option] [parameter]",
|
usage: "[option] [parameter]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
@@ -46,6 +46,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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') {
|
if (args[0].name == 'discord') {
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value});
|
let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value});
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: "ping",
|
|
||||||
debug: true,
|
|
||||||
global: true,
|
|
||||||
description: "Test bot activity",
|
|
||||||
usage: "",
|
|
||||||
permissions: {
|
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
||||||
member: [],
|
|
||||||
},
|
|
||||||
options: [],
|
|
||||||
SlashCommand: {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {require("../structures/DayzRBot")} client
|
|
||||||
* @param {import("discord.js").Message} message
|
|
||||||
* @param {string[]} args
|
|
||||||
* @param {*} param3
|
|
||||||
*/
|
|
||||||
run: async (client, interaction, args, { GuildDB }, start) => {
|
|
||||||
const end = new Date().getTime();
|
|
||||||
const pingEmbed = new EmbedBuilder()
|
|
||||||
.setDescription(`🏓 **Pong!** Bot ping: ${end - start}ms`)
|
|
||||||
.setColor(client.config.Colors.Default);
|
|
||||||
|
|
||||||
return interaction.send({ embeds: [pingEmbed] });
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
+45
-4
@@ -1,3 +1,5 @@
|
|||||||
|
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||||
|
const { Missions } = require('../database/destinations');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -21,19 +23,58 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }, start) => {
|
run: async (client, interaction, args, { GuildDB }, start) => {
|
||||||
|
|
||||||
let activePlayers = await client.dbo.collection("players").find({"connected": true});
|
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 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 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 Statuses = {
|
||||||
|
"started": {emoji: "🟢", text: "Active"},
|
||||||
|
"stopped": {emoji: "🔴", text: "Stopped"},
|
||||||
|
"restarting": {emoji: "↻", text: "Restarting"},
|
||||||
|
};
|
||||||
|
|
||||||
|
const emojiStatus = Statuses[status].emoji || "❓";
|
||||||
|
const textStatus = Statuses[status].text || "Unknown Status";
|
||||||
|
|
||||||
|
let activePlayers = await client.dbo.collection("players").find({"connected": true}).toArray();
|
||||||
|
|
||||||
let des = activePlayers.length > 0 ? `` : `**No Players Online**`;
|
let des = activePlayers.length > 0 ? `` : `**No Players Online**`;
|
||||||
for (let i = 0; i < activePlayers.length; i++) {
|
for (let i = 0; i < activePlayers.length; i++) {
|
||||||
des += `**- ${activePlayers[i].gamertag}**\n`;
|
des += `**- ${activePlayers[i].gamertag}**\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nodes = activePlayers.length === 0;
|
||||||
|
const serverEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setTitle(`Online List - \` ${playersOnline === undefined ? activePlayers.length : playersOnline} \` Player${playersOnline !== 1 ? 's' : ''} Online`)
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Server:', value: `\` ${hostname} \``, inline: false },
|
||||||
|
{ name: 'Map:', value: `\` ${map} \``, inline: true },
|
||||||
|
{ name: 'Status:', value: `\` ${emojiStatus} ${textStatus} \``, inline: true },
|
||||||
|
{ name: 'Slots:', value: `\` ${slots} \``, inline: true }
|
||||||
|
);
|
||||||
|
|
||||||
const activePlayersEmbed = new EmbedBuilder()
|
const activePlayersEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setTitle(`Online List - ${activePlayers.length} Player${(activePlayers.length>1||activePlayers.length==0)?'s':''} Online`)
|
.setTimestamp()
|
||||||
.setDescription(des);
|
.setTitle(`Players Online:`)
|
||||||
|
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
||||||
|
|
||||||
return interaction.send({ embeds: [activePlayersEmbed] });
|
return interaction.send({ embeds: [serverEmbed, activePlayersEmbed] });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
+196
-33
@@ -1,5 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
const { insertPVPstats } = require('../database/player');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "player-stats",
|
name: "player-stats",
|
||||||
@@ -30,6 +31,9 @@ module.exports = {
|
|||||||
{ name: "Longest Kill", value: "longestKill" },
|
{ name: "Longest Kill", value: "longestKill" },
|
||||||
{ name: "KDR", value: "KDR" },
|
{ name: "KDR", value: "KDR" },
|
||||||
{ name: "Server Connections", value: "connections" },
|
{ name: "Server Connections", value: "connections" },
|
||||||
|
{ name: "Shots Landed", value: "shotsLanded" },
|
||||||
|
{ name: "Times Shot", value: "timesShot" },
|
||||||
|
{ name: "Combat Rating", value: "combatRating" }
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
name: "discord",
|
name: "discord",
|
||||||
@@ -52,16 +56,20 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }, start) => {
|
run: async (client, interaction, args, { GuildDB }, start) => {
|
||||||
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;
|
|
||||||
|
|
||||||
let playerStat;
|
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) {
|
||||||
if (!discord && gamertag) {
|
const warnNitradoNotInitialized = new EmbedBuilder()
|
||||||
playerStat = await client.dbo.collection("players").findOne({"gamertag": gamertag});
|
.setColor(client.config.Colors.Yellow)
|
||||||
if (playerStat == undefined) 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 \`.`)] });
|
.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;
|
||||||
|
let self = !discord && !gamertag; // searching for self if both discord and gamertag are undefined;
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
let leaderboard;
|
let leaderboard;
|
||||||
let leaderboardPos;
|
let leaderboardPos;
|
||||||
@@ -72,18 +80,11 @@ module.exports = {
|
|||||||
{ $sort: { [`user.guilds.${GuildDB.serverID}.balance`]: -1 } }
|
{ $sort: { [`user.guilds.${GuildDB.serverID}.balance`]: -1 } }
|
||||||
]).toArray();
|
]).toArray();
|
||||||
|
|
||||||
if (discord) { // If searching by discord
|
if (discord) query = leaderboard.find(u => u.user.userID == discord); // Searching by discord user
|
||||||
query = leaderboard.find(u => u.user.userID == discord);
|
if (gamertag) query = leaderboard.find(u => u.user.userID == playerStat.discordID); // Searching by gamertag
|
||||||
|
if (self) query = leaderboard.find(u => u.user.userID == interaction.member.user.id); // Searching for self
|
||||||
|
|
||||||
} else if (gamertag) { // If searching by gamertag
|
if (!client.exists(query)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
||||||
if (playerStat.discordID == "") return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Unlinked** No Discord User has linked to the gamertag \` ${gamertag} \`.`)] });
|
|
||||||
query = leaderboard.find(u => u.user.userID == playerStat.discordID);
|
|
||||||
|
|
||||||
} else { // If searching for self
|
|
||||||
query = leaderboard.find(u => u.user.userID == interaction.member.user.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
|
||||||
leaderboardPos = leaderboard.indexOf(query);
|
leaderboardPos = leaderboard.indexOf(query);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -92,17 +93,11 @@ module.exports = {
|
|||||||
{ $sort: { [`${category}`]: -1 } }
|
{ $sort: { [`${category}`]: -1 } }
|
||||||
]).toArray();
|
]).toArray();
|
||||||
|
|
||||||
if (discord) { // If searching by discord
|
if (discord) query = leaderboard.find(s => s.discordID == discord); // Searching by discord user
|
||||||
query = leaderboard.find(s => s.discordID == discord);
|
if (gamertag) query = leaderboard.find(s => s.gamertag == gamertag); // Searching by gamertag
|
||||||
|
if (self) query = leaderboard.find(s => s.discordID == interaction.member.user.id); // Searching for self
|
||||||
|
|
||||||
} else if (gamertag ) { // If searching by gamertag
|
if (!client.exists(query)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
||||||
query = leaderboard.find(s => s.gamertag == gamertag);
|
|
||||||
|
|
||||||
} else { // If searching for self
|
|
||||||
query = leaderboard.find(s => s.discordID == interaction.member.user.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
|
||||||
leaderboardPos = leaderboard.indexOf(query);
|
leaderboardPos = leaderboard.indexOf(query);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -119,7 +114,10 @@ module.exports = {
|
|||||||
category == 'totalSessionTime' ? "Total Time Played" :
|
category == 'totalSessionTime' ? "Total Time Played" :
|
||||||
category == 'longestSessionTime' ? "Longest Game Session" :
|
category == 'longestSessionTime' ? "Longest Game Session" :
|
||||||
category == 'KDR' ? "Kill Death Ratio" :
|
category == 'KDR' ? "Kill Death Ratio" :
|
||||||
category == 'connections' ? "Times Connected" : 'N/A Error';
|
category == 'connections' ? "Times Connected" :
|
||||||
|
category == 'shotsLanded' ? "Shots Landed" :
|
||||||
|
category == 'timesShot' ? "Times Shot" :
|
||||||
|
category == 'combatRating' ? "Combat Rating" : 'N/A Error';
|
||||||
|
|
||||||
let statsEmbed = new EmbedBuilder()
|
let statsEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default);
|
.setColor(client.config.Colors.Default);
|
||||||
@@ -130,7 +128,6 @@ module.exports = {
|
|||||||
|
|
||||||
statsEmbed.setDescription(`${tag}'s ${title}`);
|
statsEmbed.setDescription(`${tag}'s ${title}`);
|
||||||
|
|
||||||
let des = ``;
|
|
||||||
let stats = category == 'kills' ? `${query.kills} Kill${(query.kills>1||query.kills==0)?'s':''}` :
|
let stats = category == 'kills' ? `${query.kills} Kill${(query.kills>1||query.kills==0)?'s':''}` :
|
||||||
category == 'killStreak' ? `${query.killStreak} Player Killstreak` :
|
category == 'killStreak' ? `${query.killStreak} Player Killstreak` :
|
||||||
category == 'bestKillStreak' ? `${query.bestKillStreak} Player Killstreak` :
|
category == 'bestKillStreak' ? `${query.bestKillStreak} Player Killstreak` :
|
||||||
@@ -140,20 +137,186 @@ module.exports = {
|
|||||||
category == 'longestKill' ? `${query.longestKill}m` :
|
category == 'longestKill' ? `${query.longestKill}m` :
|
||||||
category == 'money' ? `$${(query.user.guilds[GuildDB.serverID].balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}` :
|
category == 'money' ? `$${(query.user.guilds[GuildDB.serverID].balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}` :
|
||||||
category == 'KDR' ? `${query.KDR.toFixed(2)} KDR` :
|
category == 'KDR' ? `${query.KDR.toFixed(2)} KDR` :
|
||||||
category == 'connections' ? `${query.connections} connections` : 'N/A Error';
|
category == 'connections' ? `${query.connections} connections` :
|
||||||
|
category == 'combatRating' ? `${query.combatRating}` : 'N/A Error';
|
||||||
|
|
||||||
statsEmbed.addFields({ name: 'Leaderboard Position', value: `# ${leaderboardPos}`, inline: true });
|
statsEmbed.addFields({ name: 'Leaderboard Position', value: `# ${leaderboardPos}`, inline: true });
|
||||||
|
|
||||||
if (category == 'total_time_played') {
|
if ((category == 'shotsLanded' || category == 'timesShot') && !client.exists(query.shotsLanded)) query = insertPVPstats(query);
|
||||||
|
|
||||||
|
if (category == 'totalSessionTime') {
|
||||||
statsEmbed.addFields(
|
statsEmbed.addFields(
|
||||||
{ name: 'Total Time Played', value: client.secondsToDhms(query.totalSessionTime), inline: true },
|
{ name: 'Total Time Played', value: client.secondsToDhms(query.totalSessionTime), inline: true },
|
||||||
{ name: 'Last Session Time', value: client.secondsToDhms(query.lastSessionTime), inline: true }
|
{ name: 'Last Session Time', value: client.secondsToDhms(query.lastSessionTime), inline: true }
|
||||||
);
|
);
|
||||||
} else if (category == 'longest_time_played') {
|
} else if (category == 'longestSessionTime') {
|
||||||
statsEmbed.addFields(
|
statsEmbed.addFields(
|
||||||
{ name: 'Longest Game Session', value: client.secondsToDhms(query.longestSessionTime), inline: true },
|
{ name: 'Longest Game Session', value: client.secondsToDhms(query.longestSessionTime), inline: true },
|
||||||
{ name: 'Last Session Time', value: client.secondsToDhms(query.lastSessionTime), inline: true }
|
{ name: 'Last Session Time', value: client.secondsToDhms(query.lastSessionTime), inline: true }
|
||||||
);
|
);
|
||||||
|
} else if (category == 'shotsLanded') {
|
||||||
|
statsEmbed.addFields(
|
||||||
|
{ name: 'Total Shots Landed', value: `${query.shotsLanded}`, inline: true },
|
||||||
|
{ name: 'View Weapon stats', value: `</weapon-stats:1169369568104415262>`, inline: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const chart = {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Head', 'Torso', 'Left Arm', 'Right Arm', 'Left Leg', 'Right Leg'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Shots Landed',
|
||||||
|
data: [
|
||||||
|
query.shotsLandedPerBodyPart.Head,
|
||||||
|
query.shotsLandedPerBodyPart.Torso,
|
||||||
|
query.shotsLandedPerBodyPart.LeftArm,
|
||||||
|
query.shotsLandedPerBodyPart.RightArm,
|
||||||
|
query.shotsLandedPerBodyPart.LeftLeg,
|
||||||
|
query.shotsLandedPerBodyPart.RightLeg,
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
yAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
xAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}`;
|
||||||
|
|
||||||
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
|
} else if (category == 'timesShot') {
|
||||||
|
statsEmbed.addFields(
|
||||||
|
{ name: 'Total Times Shot', value: `${query.timesShot}`, inline: true },
|
||||||
|
{ name: 'View Weapon stats', value: `</weapon-stats:1169369568104415262>`, inline: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
const chart = {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Head', 'Torso', 'Left Arm', 'Right Arm', 'Left Leg', 'Right Leg'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Times Shot',
|
||||||
|
data: [
|
||||||
|
query.timesShotPerBodyPart.Head,
|
||||||
|
query.timesShotPerBodyPart.Torso,
|
||||||
|
query.timesShotPerBodyPart.LeftArm,
|
||||||
|
query.timesShotPerBodyPart.RightArm,
|
||||||
|
query.timesShotPerBodyPart.LeftLeg,
|
||||||
|
query.timesShotPerBodyPart.RightLeg,
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
yAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
xAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}`;
|
||||||
|
|
||||||
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
|
} else if (category == 'combatRating') {
|
||||||
|
|
||||||
|
let data = query.combatRatingHistory;
|
||||||
|
|
||||||
|
let dataMax = Math.max(...query.combatRatingHistory);
|
||||||
|
let dataMin = Math.min(...query.combatRatingHistory);
|
||||||
|
if (!client.exists(query.highestCombatRating) || query.highestCombatRating < dataMax) query.highestCombatRating = dataMax;
|
||||||
|
if (!client.exists(query.lowestCombatRating) || query.lowestCombatRating > dataMin) query.lowestCombatRating = dataMin;
|
||||||
|
|
||||||
|
statsEmbed.addFields(
|
||||||
|
{ name: 'Combat Rating', value: `${query.combatRating}`, inline: true },
|
||||||
|
{ name: 'Highest Rating', value: `${query.highestCombatRating}`, inline: true },
|
||||||
|
{ name: 'Lowest Rating', value: `${query.lowestCombatRating}`, inline: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data.length == 1) data.push(query.combatRating) // Make array 2 long for a straight line in the graph
|
||||||
|
|
||||||
|
const chart = {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: new Array(data.length).fill(' ', 0, data.length),
|
||||||
|
datasets: [{
|
||||||
|
data: data,
|
||||||
|
label: `Last ${data.length} Combat Ratings`,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
// Gives comfortable margin to the top of the y-axis
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
fontStyle: 'bold',
|
||||||
|
min: Math.round(Math.min(...data)/10)*10 - 10,
|
||||||
|
max: Math.round(Math.max(...data)/10)*10 + 10,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
xAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
},
|
||||||
|
// Gives a margin to the right of the whole graph
|
||||||
|
layout: {
|
||||||
|
padding: {
|
||||||
|
right: 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Labels points on the graph to show evolution of combat rating
|
||||||
|
plugins: {
|
||||||
|
datalabels: {
|
||||||
|
display: true,
|
||||||
|
align: 'top',
|
||||||
|
color: '#000',
|
||||||
|
backgroundColor: '#ccc',
|
||||||
|
borderRadius: 4,
|
||||||
|
offset: 10,
|
||||||
|
display: (context) => {
|
||||||
|
const index = context.dataIndex;
|
||||||
|
const value = context.dataset.data[index];
|
||||||
|
const min = Math.min.apply(null, context.dataset.data);
|
||||||
|
const max = Math.max.apply(null, context.dataset.data);
|
||||||
|
return (
|
||||||
|
index == 0 ||
|
||||||
|
index == context.dataset.data.length - 1 ||
|
||||||
|
value == min ||
|
||||||
|
value == max
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}`;
|
||||||
|
|
||||||
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
} else statsEmbed.addFields({ name: title, value: stats, inline: true });
|
} else statsEmbed.addFields({ name: title, value: stats, inline: true });
|
||||||
|
|
||||||
return interaction.send({ embeds: [statsEmbed] });
|
return interaction.send({ embeds: [statsEmbed] });
|
||||||
|
|||||||
@@ -1,17 +1,28 @@
|
|||||||
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, Embed } = require('discord.js');
|
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
|
||||||
const { createUser, addUser } = require('../database/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "purchase-emp",
|
name: "purchase-emp",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "EMP an Alarm to prevent any updates for 30 minutes",
|
description: "EMP an Alarm to prevent any updates for 30 or 60 minutes",
|
||||||
usage: "",
|
usage: "",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
member: ["MANAGE_GUILD"],
|
member: ["MANAGE_GUILD"],
|
||||||
},
|
},
|
||||||
options: [],
|
options: [{
|
||||||
|
name: "duration",
|
||||||
|
description: "Select the duration of the emp (30 or 60 minutes)",
|
||||||
|
value: "duration",
|
||||||
|
type: CommandOptions.Integer,
|
||||||
|
required: true,
|
||||||
|
choices: [
|
||||||
|
{ name: "30 Minutes", value: 30 },
|
||||||
|
{ name: "60 Minutes", value: 60 }
|
||||||
|
]
|
||||||
|
}],
|
||||||
SlashCommand: {
|
SlashCommand: {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -21,8 +32,18 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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')] });
|
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;
|
||||||
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|
||||||
if (!banking) {
|
if (!banking) {
|
||||||
@@ -44,7 +65,8 @@ module.exports = {
|
|||||||
return interaction.send({ embeds: [embed], flags: (1 << 6) });
|
return interaction.send({ embeds: [embed], flags: (1 << 6) });
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBalance = banking.guilds[GuildDB.serverID].balance - GuildDB.empPrice;
|
const price = duration == 30 ? GuildDB.empPrice : GuildDB.empPrice * 2;
|
||||||
|
const newBalance = banking.guilds[GuildDB.serverID].balance - price;
|
||||||
|
|
||||||
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to EMP.')], flags: (1 << 6) });
|
if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to EMP.')], flags: (1 << 6) });
|
||||||
|
|
||||||
@@ -60,8 +82,8 @@ module.exports = {
|
|||||||
if (!GuildDB.alarms[i].empExempt) {
|
if (!GuildDB.alarms[i].empExempt) {
|
||||||
alarms.addOptions({
|
alarms.addOptions({
|
||||||
label: GuildDB.alarms[i].name,
|
label: GuildDB.alarms[i].name,
|
||||||
description: `EMP this Alarm for $${GuildDB.empPrice.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0})}}`,
|
description: `EMP this Alarm for $${price.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0})}}`,
|
||||||
value: GuildDB.alarms[i].name
|
value: `${GuildDB.alarms[i].name}-${duration}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,12 +97,13 @@ module.exports = {
|
|||||||
Interactions: {
|
Interactions: {
|
||||||
EMPAlarmSelect: {
|
EMPAlarmSelect: {
|
||||||
run: async (client, interaction, GuildDB) => {
|
run: async (client, interaction, GuildDB) => {
|
||||||
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]);
|
let duration = parseInt(interaction.values[0].split('-')[1]);
|
||||||
|
let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0].split('-')[0]);
|
||||||
let alarms = GuildDB.alarms;
|
let alarms = GuildDB.alarms;
|
||||||
let alarmIndex = alarms.indexOf(alarm);
|
let alarmIndex = alarms.indexOf(alarm);
|
||||||
alarm.disabled = true;
|
alarm.disabled = true;
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
alarm.empExpire = new Date(d.getTime() += (30 * 60 * 1000));
|
alarm.empExpire = new Date(d.getTime() + (duration * 60 * 1000));
|
||||||
alarms[alarmIndex] = alarm;
|
alarms[alarmIndex] = alarm;
|
||||||
|
|
||||||
client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, {
|
client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ module.exports = {
|
|||||||
name: "purchase-uav",
|
name: "purchase-uav",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "Send a UAV to scout for 30 minutes. (500m range)",
|
description: "Send a UAV to scout for 30 minutes (500m range)",
|
||||||
usage: "[x-coord] [y-coord]",
|
usage: "[x-coord] [y-coord]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
@@ -39,6 +39,15 @@ module.exports = {
|
|||||||
* @param {*} param3
|
* @param {*} param3
|
||||||
*/
|
*/
|
||||||
run: async (client, interaction, args, { GuildDB }) => {
|
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')] });
|
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);
|
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ module.exports = {
|
|||||||
name: "reset",
|
name: "reset",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "Reset a users Banking data",
|
description: "Reset a user's bank/money",
|
||||||
usage: "[user]",
|
usage: "[user]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
|||||||
+253
-27
@@ -1,20 +1,44 @@
|
|||||||
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 CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
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 = {
|
module.exports = {
|
||||||
name: "server",
|
name: "server",
|
||||||
debug: false,
|
debug: false,
|
||||||
global: false,
|
global: false,
|
||||||
description: "DayZ Server Administrative Commands",
|
description: "Nitrado DayZ Server Administrative Commands",
|
||||||
usage: "[command] [options]",
|
usage: "[command] [options]",
|
||||||
permissions: {
|
permissions: {
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
member: [],
|
member: [],
|
||||||
},
|
},
|
||||||
options: [
|
options: [{
|
||||||
{
|
name: "initialize",
|
||||||
|
description: "Connect your Nitrado server to the bot",
|
||||||
|
value: "initialize",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "disconnect",
|
||||||
|
description: "Delete your Nitrado server from the bot database",
|
||||||
|
value: "disconnect",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "credentials-status",
|
||||||
|
description: "Check the status of your Nitrado Credentials",
|
||||||
|
value: "credentials-status",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "retry-credentials",
|
||||||
|
description: "If your credentials are marked as FAILED, try retreiving Nitrado logs again.",
|
||||||
|
value: "retry-credentials",
|
||||||
|
type: CommandOptions.SubCommand,
|
||||||
|
},
|
||||||
|
{
|
||||||
name: "ban-player",
|
name: "ban-player",
|
||||||
description: "Ban a player from the DayZ server",
|
description: "Ban a player from the DayZ server",
|
||||||
value: "ban-player",
|
value: "ban-player",
|
||||||
@@ -46,7 +70,7 @@ module.exports = {
|
|||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
}, {
|
}, {
|
||||||
name: "auto-restart",
|
name: "auto-restart",
|
||||||
description: "Enable/Disable periodic server checks and restart if stopped.",
|
description: "Enable/Disable periodic server checks and restart if stopped",
|
||||||
value: "auto-restart",
|
value: "auto-restart",
|
||||||
type: CommandOptions.SubCommand,
|
type: CommandOptions.SubCommand,
|
||||||
}, {
|
}, {
|
||||||
@@ -91,16 +115,117 @@ module.exports = {
|
|||||||
if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) 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.' });
|
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
|
||||||
|
|
||||||
if (args[0].name == 'ban-player') {
|
if (args[0].name == 'initialize') {
|
||||||
|
|
||||||
let data = await BanPlayer(client, args[0].options[0].value);
|
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);
|
||||||
|
|
||||||
|
} else if (args[0].name == 'disconnect') {
|
||||||
|
|
||||||
|
const prompt = new EmbedBuilder()
|
||||||
|
.setTitle(`Delete your Nitrado Server?`)
|
||||||
|
.setDescription('**Notice:** This will completely delete your configured Nitrado server from the bot database.')
|
||||||
|
.setColor(client.config.Colors.Yellow)
|
||||||
|
|
||||||
|
const opt = new ActionRowBuilder()
|
||||||
|
.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`DeleteNitrado-yes-${interaction.member.user.id}`)
|
||||||
|
.setLabel("Yes")
|
||||||
|
.setStyle(ButtonStyle.Danger),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`DeleteNitrado-no-${interaction.member.user.id}`)
|
||||||
|
.setLabel("No")
|
||||||
|
.setStyle(ButtonStyle.Success)
|
||||||
|
)
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Red).setDescription(`**Notice:**\nThis Discord guild has not been configured with a Nitrado DayZ server. To configure your guild, use </server initialize:1166877457559851011>`)] });
|
||||||
|
|
||||||
|
if (args[0].name == '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);
|
||||||
|
|
||||||
if (data == 1) {
|
if (data == 1) {
|
||||||
let failed = new EmbedBuilder()
|
let failed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Red)
|
.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()
|
let banned = new EmbedBuilder()
|
||||||
@@ -111,12 +236,12 @@ module.exports = {
|
|||||||
|
|
||||||
} else if (args[0].name == 'unban-player') {
|
} else if (args[0].name == 'unban-player') {
|
||||||
|
|
||||||
let data = UnbanPlayer(client, args[0].options[0].value);
|
let data = UnbanPlayer(GuildDB.Nitrado, client, args[0].options[0].value);
|
||||||
|
|
||||||
if (data == 1) {
|
if (data == 1) {
|
||||||
let failed = new EmbedBuilder()
|
let failed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Red)
|
.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] });
|
return interaction.send({ embeds: [failed] });
|
||||||
}
|
}
|
||||||
@@ -132,29 +257,26 @@ module.exports = {
|
|||||||
restart_message = 'Server being restarted by an admin.';
|
restart_message = 'Server being restarted by an admin.';
|
||||||
message = 'The server was restarted by an admin!';
|
message = 'The server was restarted by an admin!';
|
||||||
|
|
||||||
RestartServer(client, restart_message, message);
|
RestartServer(GuildDB.Nitrado, client, restart_message, message);
|
||||||
return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('The server will restart shortly.')], flags: (1 << 6) });
|
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") {
|
} else if (args[0].name == "auto-restart") {
|
||||||
msg = 'Auto server restart periodic check enabled.';
|
let msg = 'Auto server restart periodic check enabled.';
|
||||||
pref = 0;
|
let pref = 0;
|
||||||
|
|
||||||
// Enable/Disable a 10min periodic server status check.
|
// Enable/Disable a 10min periodic server status check.
|
||||||
if (!client.arIntervalId) {
|
if (!client.arIntervalIds.has(GuildDB.serverID)) {
|
||||||
client.arIntervalId = setInterval(CheckServerStatus, client.arInterval, client);
|
client.arIntervalIds.set(GuildDB.serverID, setInterval(CheckServerStatus, client.arInterval, GuildDB.Nitrado, client));
|
||||||
client.log('Enabled and starting periodic Nitrado server status check.');
|
|
||||||
pref = 1;
|
pref = 1;
|
||||||
} else {
|
} else {
|
||||||
msg = 'Auto server restart periodic check disabled.'
|
msg = 'Auto server restart periodic check disabled.'
|
||||||
clearInterval(client.arIntervalId);
|
clearInterval(client.arIntervalIds.get(GuildDB.serverID));
|
||||||
client.arIntervalId = 0;
|
|
||||||
client.log('Disabled periodic Nitrado server status check.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update DB preference
|
// Update DB preference
|
||||||
client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, {
|
client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, {
|
||||||
$set: {
|
$set: {
|
||||||
"server.autoRestart": pref
|
"server.autoRestart": pref,
|
||||||
}
|
}
|
||||||
}, function (err, res) {
|
}, function (err, res) {
|
||||||
if (err) return client.sendInternalError(interaction, err);
|
if (err) return client.sendInternalError(interaction, err);
|
||||||
@@ -166,23 +288,127 @@ module.exports = {
|
|||||||
const preference = args[0].options[0].value;
|
const preference = args[0].options[0].value;
|
||||||
await interaction.deferReply({ flags: (1 << 6) });
|
await interaction.deferReply({ flags: (1 << 6) });
|
||||||
|
|
||||||
const disableBaseDamageFailed = await DisableBaseDamage(client, preference);
|
const disableBaseDamageFailed = await DisableBaseDamage(GuildDB.Nitrado, 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) });
|
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') {
|
} else if (args[0].name == 'disable-container-damage') {
|
||||||
const preference = args[0].options[0].value;
|
const preference = args[0].options[0].value;
|
||||||
await interaction.deferReply({ flags: (1 << 6) });
|
await interaction.deferReply({ flags: (1 << 6) });
|
||||||
|
|
||||||
const disableContainerDamageFailed = await DisableContainerDamage(client, preference);
|
const disableContainerDamageFailed = await DisableContainerDamage(GuildDB.Nitrado, 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) });
|
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
|
||||||
|
Status: NitradoCredentialStatus.OK, // Indicate if these credentials dont work
|
||||||
|
};
|
||||||
|
|
||||||
|
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')
|
||||||
|
.setPlaceholder("This will be encrypted to protect your server!")
|
||||||
|
.setStyle(TextInputStyle.Short)
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
|
||||||
|
NitradoCredentials.addComponents(ServerID, UserID, Auth);
|
||||||
|
|
||||||
|
// TODO: Figure out how to remove the prompt buttons and the embed.
|
||||||
|
return interaction.showModal(NitradoCredentials);
|
||||||
|
} else {
|
||||||
|
return interaction.update({ embeds: [], components: [], content: 'Cancelled Overwriting Nitrado Server Information', flags: (1 << 6) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
DeleteNitrado: {
|
||||||
|
run: async(client, interaction, GuildDB) => {
|
||||||
|
if (!interaction.customId.endsWith(interaction.member.user.id))
|
||||||
|
return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) });
|
||||||
|
|
||||||
|
if (interaction.customId.split('-')[1] == 'yes') {
|
||||||
|
await client.dbo.collection('guilds').updateOne({ "server.serverID": GuildDB.serverID }, { $set: { "Nitrado": null } }, (err, _) => {
|
||||||
|
if (err) client.sendInternalError(interaction, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return interaction.update({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setDescription(`**Success**\n> Successfully removed your Nitrado credentials from the database.`)
|
||||||
|
],
|
||||||
|
components: [],
|
||||||
|
flags: (1 << 6)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return interaction.update({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setDescription(`**Cancelled**\n> Your Nitrado credentials were not removed from the database.`)
|
||||||
|
],
|
||||||
|
components: [],
|
||||||
|
flags: (1 << 6)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: "stats",
|
|
||||||
debug: true,
|
|
||||||
global: true,
|
|
||||||
description: "check bot statistics",
|
|
||||||
usage: "",
|
|
||||||
permissions: {
|
|
||||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
||||||
member: [],
|
|
||||||
},
|
|
||||||
options: [],
|
|
||||||
SlashCommand: {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {require("../structures/DayzRBot")} client
|
|
||||||
* @param {import("discord.js").Message} message
|
|
||||||
* @param {string[]} args
|
|
||||||
* @param {*} param3
|
|
||||||
*/
|
|
||||||
run: async (client, interaction, args, { GuildDB }, start) => {
|
|
||||||
const end = new Date().getTime();
|
|
||||||
const stats = new EmbedBuilder()
|
|
||||||
.setColor(client.config.Colors.Default)
|
|
||||||
.setTitle('DayZ Reforger Bot Statistics')
|
|
||||||
.addFields(
|
|
||||||
{ name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true },
|
|
||||||
{ name: 'Users', value: `${client.users.cache.size}`, inline: true },
|
|
||||||
{ name: 'Latency', value: `${end - start}ms`, inline: true },
|
|
||||||
{ name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, inline: true },
|
|
||||||
{ name: 'Bot Version', value: `${client.config.Dev} v${client.config.Version}`, inline: true },
|
|
||||||
{ name: 'Discord Version', value: 'Discord.js v14.8.0', inline: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
return interaction.send({ embeds: [stats] })
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
|
||||||
|
const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes;
|
||||||
|
const { weapons } = require('../database/weapons');
|
||||||
|
const { insertPVPstats, createWeaponStats } = require('../database/player');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "weapon-stats",
|
||||||
|
debug: false,
|
||||||
|
global: false,
|
||||||
|
description: "Check player weapon statistics",
|
||||||
|
usage: "[category] [user or gamertag]",
|
||||||
|
permissions: {
|
||||||
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
member: [],
|
||||||
|
},
|
||||||
|
options: [{
|
||||||
|
name: "category",
|
||||||
|
description: "Weapon category",
|
||||||
|
value: "category",
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: true,
|
||||||
|
choices: [
|
||||||
|
{ name: "Handguns", value: "handguns" },
|
||||||
|
{ name: "Shotguns", value: "shotguns" },
|
||||||
|
{ name: "Submachine Guns", value: "subMachineGuns" },
|
||||||
|
{ name: "Assault Rifles", value: "assaultRifles" },
|
||||||
|
{ name: "Battle Rifles", value: "battleRifles" },
|
||||||
|
{ name: "Bolt-action Rifles", value: "boltActionRifles" },
|
||||||
|
{ name: "Break-action Rifles", value: "breakActionRifles" },
|
||||||
|
{ name: "Lever-action Rifles", value: "leverActionRifles" },
|
||||||
|
{ name: "Marksman Rifles", value: "marksmanRifles" },
|
||||||
|
{ name: "Semi-automatic Rifles", value: "semiAutomaticRifles" },
|
||||||
|
{ name: "Other", value: "other" },
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
name: "discord",
|
||||||
|
description: "Discord user to lookup stats",
|
||||||
|
value: "discord",
|
||||||
|
type: CommandOptions.User,
|
||||||
|
required: false,
|
||||||
|
}, {
|
||||||
|
name: "gamertag",
|
||||||
|
description: "Gamertag to lookup stats",
|
||||||
|
type: CommandOptions.String,
|
||||||
|
required: false,
|
||||||
|
}],
|
||||||
|
SlashCommand: {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {require("../structures/DayzRBot")} client
|
||||||
|
* @param {import("discord.js").Message} message
|
||||||
|
* @param {string[]} args
|
||||||
|
* @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
|
||||||
|
const weaponClass = args[0].value;
|
||||||
|
|
||||||
|
let query;
|
||||||
|
|
||||||
|
// Searching by Discord
|
||||||
|
if (discord) query = await client.dbo.collection("players").findOne({"discordID": discord});
|
||||||
|
|
||||||
|
// Searching by Gamertag
|
||||||
|
if (gamertag) query = await client.dbo.collection("players").findOne({"gamertag": gamertag});
|
||||||
|
|
||||||
|
// Searching for self
|
||||||
|
if (self) query = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id});
|
||||||
|
|
||||||
|
if (!client.exists(query)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** Unable to find any records with the gamertag or user provided.`)] });
|
||||||
|
|
||||||
|
let weaponSelect = new StringSelectMenuBuilder()
|
||||||
|
.setCustomId(`ViewWeaponStats-${query.playerID}-${interaction.member.user.id}`)
|
||||||
|
.setPlaceholder(`Select an weapon to view stat.`)
|
||||||
|
|
||||||
|
for (const [name, _] of Object.entries(weapons[weaponClass])) {
|
||||||
|
weaponSelect.addOptions({
|
||||||
|
label: name,
|
||||||
|
description: `View this weapon's stats.`,
|
||||||
|
value: `${weaponClass}_${name}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const opt = new ActionRowBuilder().addComponents(weaponSelect);
|
||||||
|
|
||||||
|
return interaction.send({ components: [opt] });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Interactions: {
|
||||||
|
ViewWeaponStats: {
|
||||||
|
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 weapon = interaction.values[0].split("_")[1];
|
||||||
|
const weaponClass = interaction.values[0].split("_")[0];
|
||||||
|
const playerID = interaction.customId.split('-')[1];
|
||||||
|
let player = await client.dbo.collection("players").findOne({"playerID": playerID});
|
||||||
|
const tag = player.discordID != "" ? `<@${player.discordID}>'s` : `**${player.gamertag}'s**`;
|
||||||
|
|
||||||
|
if (!client.exists(player.shotsLanded)) player = insertPVPstats(player);
|
||||||
|
if (!client.exists(player.weaponStats[weapon])) player = createWeaponStats(player, weapon);
|
||||||
|
|
||||||
|
let stats = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`${tag} stats for the **${weapon}**`)
|
||||||
|
.setThumbnail(weapons[weaponClass][weapon])
|
||||||
|
.addFields(
|
||||||
|
{ name: `Kills`, value: `${player.weaponStats[weapon].kills}`, inline: true },
|
||||||
|
{ name: `Deaths`, value: `${player.weaponStats[weapon].deaths}`, inline: true },
|
||||||
|
{ name: `Shots Landed`, value: `${player.weaponStats[weapon].shotsLanded}`, inline: true },
|
||||||
|
{ name: `Times Shot`, value: `${player.weaponStats[weapon].timesShot}`, inline: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
const chart = {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['Head', 'Torso', 'Left Arm', 'Right Arm', 'Left Leg', 'Right Leg'],
|
||||||
|
datasets: [{
|
||||||
|
label: `Shots landed with a ${weapon}`,
|
||||||
|
data: [
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.Head,
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.Torso,
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.LeftArm,
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.RightArm,
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.LeftLeg,
|
||||||
|
player.weaponStats[weapon].shotsLandedPerBodyPart.RightLeg,
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
label: `Times Shot by a ${weapon}`,
|
||||||
|
data: [
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.Head,
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.Torso,
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.LeftArm,
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.RightArm,
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.LeftLeg,
|
||||||
|
player.weaponStats[weapon].timesShotPerBodyPart.RightLeg,
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
labels: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
yAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
xAxes: [{ ticks: { fontStyle: 'bold' } }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}`;
|
||||||
|
|
||||||
|
stats.setImage(chartURL);
|
||||||
|
|
||||||
|
return interaction.update({ components: [], embeds: [stats] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-9
File diff suppressed because one or more lines are too long.
@@ -97,7 +97,7 @@ module.exports = {
|
|||||||
url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/42/Flag_jolly_c_co.png/revision/latest?cb=20200820222641"
|
url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/42/Flag_jolly_c_co.png/revision/latest?cb=20200820222641"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "North Sahrani (KOS)",
|
name: "South Sahrani (KOS)",
|
||||||
url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a1/Flag_kos_co.png/revision/latest?cb=20200820222644"
|
url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a1/Flag_kos_co.png/revision/latest?cb=20200820222644"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+372
-2
@@ -1,5 +1,32 @@
|
|||||||
|
const { calculateVector } = require('../util/Vector');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
destinations: [
|
Missions: {
|
||||||
|
"dayzOffline.chernarusplus": "Chernarus",
|
||||||
|
"dayzOffline.enoch": "Livonia",
|
||||||
|
"dayzOffline.sakhal": "Sakhal",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Calculates the nearest location to a given coordinate
|
||||||
|
nearest: (pos, mission) => {
|
||||||
|
let tempDest;
|
||||||
|
let lastDist = 1000000;
|
||||||
|
let destination_dir;
|
||||||
|
for (let i = 0; i < destinations[mission].length; i++) {
|
||||||
|
let { distance, theta, dir } = calculateVector(pos, destinations[mission][i].coord);
|
||||||
|
if (distance < lastDist) {
|
||||||
|
tempDest = destinations[mission][i].name;
|
||||||
|
lastDist = distance;
|
||||||
|
destination_dir = dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastDist > 500 ? `${destination_dir} of ${tempDest}` : `Near ${tempDest}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A curated list of destinations across DayZ Chernarus and Livonia
|
||||||
|
const destinations = {
|
||||||
|
Chernarus: [
|
||||||
{
|
{
|
||||||
name: 'Sinystok',
|
name: 'Sinystok',
|
||||||
coord: [1481.47, 11933.38],
|
coord: [1481.47, 11933.38],
|
||||||
@@ -310,5 +337,348 @@ module.exports = {
|
|||||||
name: 'Ski Resort Peak',
|
name: 'Ski Resort Peak',
|
||||||
coord: [250.80, 11867.28],
|
coord: [250.80, 11867.28],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
Livonia: [
|
||||||
|
{
|
||||||
|
name: 'Lukow',
|
||||||
|
coord: [3575.00, 11925.00],
|
||||||
|
}, {
|
||||||
|
name: 'Brena',
|
||||||
|
coord: [6518.75, 11228.13],
|
||||||
|
}, {
|
||||||
|
name: 'Kolembrody',
|
||||||
|
coord: [8406.25, 11968.75],
|
||||||
|
}, {
|
||||||
|
name: 'Grabin',
|
||||||
|
coord: [10756.25, 11062.50],
|
||||||
|
}, {
|
||||||
|
name: 'Sitnik',
|
||||||
|
coord: [11440.63, 9543.75],
|
||||||
|
}, {
|
||||||
|
name: 'Tarnow',
|
||||||
|
coord: [9275.00, 10921.88],
|
||||||
|
}, {
|
||||||
|
name: 'Sobatka',
|
||||||
|
coord: [6250.00, 10193.75],
|
||||||
|
}, {
|
||||||
|
name: 'Gliniska',
|
||||||
|
coord: [5012.50, 9881.25],
|
||||||
|
}, {
|
||||||
|
name: 'Gliniska Airfield',
|
||||||
|
coord: [3968.75, 10278.13]
|
||||||
|
}, {
|
||||||
|
name: 'Kopa',
|
||||||
|
coord: [5545.31, 8748.44],
|
||||||
|
}, {
|
||||||
|
name: 'Olszanka',
|
||||||
|
coord: [4856.25, 7571.88],
|
||||||
|
}, {
|
||||||
|
name: 'Radacz',
|
||||||
|
coord: [4006.25, 7972.66],
|
||||||
|
}, {
|
||||||
|
name: 'Topolin',
|
||||||
|
coord: [1665.62, 7378.13],
|
||||||
|
}, {
|
||||||
|
name: 'Bielawa',
|
||||||
|
coord: [1525.00, 9700.00],
|
||||||
|
}, {
|
||||||
|
name: 'Adamow',
|
||||||
|
coord: [3081.25, 6793.75],
|
||||||
|
}, {
|
||||||
|
name: 'Muratyn',
|
||||||
|
coord: [4587.50, 6387.50],
|
||||||
|
}, {
|
||||||
|
name: 'Lipina',
|
||||||
|
coord: [5943.75, 6787.50],
|
||||||
|
}, {
|
||||||
|
name: 'Nidek',
|
||||||
|
coord: [6118.75, 8056.25],
|
||||||
|
}, {
|
||||||
|
name: 'Zapadlisko',
|
||||||
|
coord: [8093.75, 8710.94],
|
||||||
|
}, {
|
||||||
|
name: 'Krsnik Military',
|
||||||
|
coord: [7841.02, 10075.39],
|
||||||
|
}, {
|
||||||
|
name: 'Zalesie',
|
||||||
|
coord: [878.12, 5512.50],
|
||||||
|
}, {
|
||||||
|
name: 'Borek Military',
|
||||||
|
coord: [9807.81, 8500.00],
|
||||||
|
}, {
|
||||||
|
name: 'Polkrabiec',
|
||||||
|
coord: [11878.13, 6571.09],
|
||||||
|
}, {
|
||||||
|
name: 'Lembork',
|
||||||
|
coord: [8825.00, 6628.13],
|
||||||
|
}, {
|
||||||
|
name: 'Karlin',
|
||||||
|
coord: [10064.39, 6924.93],
|
||||||
|
}, {
|
||||||
|
name: 'Radunin',
|
||||||
|
coord: [7301.89, 6418.68],
|
||||||
|
}, {
|
||||||
|
name: 'Roztoka',
|
||||||
|
coord: [7650.00, 5246.88],
|
||||||
|
}, {
|
||||||
|
name: 'Sarnowek',
|
||||||
|
coord: [3287.50, 5009.38],
|
||||||
|
}, {
|
||||||
|
name: 'Huta',
|
||||||
|
coord: [5154.69, 5520.31],
|
||||||
|
}, {
|
||||||
|
name: 'Drewniki',
|
||||||
|
coord: [5834.38, 5084.38],
|
||||||
|
}, {
|
||||||
|
name: 'Nadbor',
|
||||||
|
coord: [6056.25, 4103.13],
|
||||||
|
}, {
|
||||||
|
name: 'Nadbor Military',
|
||||||
|
coord: [5625.00, 3787.50],
|
||||||
|
}, {
|
||||||
|
name: 'Max',
|
||||||
|
coord: [6448.44, 4732.81],
|
||||||
|
}, {
|
||||||
|
name: 'Wrzeszcz',
|
||||||
|
coord: [9042.19, 4385.94],
|
||||||
|
}, {
|
||||||
|
name: 'Gieraltow',
|
||||||
|
coord: [11243.75, 4332.81],
|
||||||
|
}, {
|
||||||
|
name: 'Konopki',
|
||||||
|
coord: [11460.16, 2889.84],
|
||||||
|
}, {
|
||||||
|
name: 'Swarog Military',
|
||||||
|
coord: [5017.19, 2146.88],
|
||||||
|
}, {
|
||||||
|
name: 'Hedrykow',
|
||||||
|
coord: [4487.50, 4825.00],
|
||||||
|
}, {
|
||||||
|
name: 'Polana',
|
||||||
|
coord: [3296.87, 2043.75],
|
||||||
|
}, {
|
||||||
|
name: 'Dambog',
|
||||||
|
coord: [597.27, 1138.67],
|
||||||
|
}, {
|
||||||
|
name: 'Dolnik',
|
||||||
|
coord: [11410.94, 578.12],
|
||||||
|
}, {
|
||||||
|
name: 'Widok',
|
||||||
|
coord: [10234.38, 2165.63],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Sakhal: [
|
||||||
|
{
|
||||||
|
name: 'Tochka',
|
||||||
|
coord: [3731.25, 14404.69],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Utes',
|
||||||
|
coord: [5396.25, 14539.69],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sputnik',
|
||||||
|
coord: [7738.13, 14820.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'West Uzhki',
|
||||||
|
coord: [10501.88, 14588.44],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'East Uzhki',
|
||||||
|
coord: [11251.88, 14420.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tungar',
|
||||||
|
coord: [12673.13, 14116.88],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Jasnomorsk',
|
||||||
|
coord: [6953.44, 13388.44],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Jevai',
|
||||||
|
coord: [7937.81, 13541.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tumanovo',
|
||||||
|
coord: [8444.06, 13693.13],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Severomorsk',
|
||||||
|
coord: [9570.94, 13525.31],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Orlovo',
|
||||||
|
coord: [10369.69, 13320.94],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Podgornoe',
|
||||||
|
coord: [10984.69, 13170.94],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Rybnoe',
|
||||||
|
coord: [12423.75, 12722.81],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Rudnogorsk',
|
||||||
|
coord: [13573.13, 11874.38],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Matrosovo',
|
||||||
|
coord: [14266.88, 11621.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Vajkovo',
|
||||||
|
coord: [14555.63, 9804.38],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sumnoe',
|
||||||
|
coord: [14385.00, 8866.88],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Vostok',
|
||||||
|
coord: [13908.75, 8362.50],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Aniva',
|
||||||
|
coord: [12823.13, 7370.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Juznoe',
|
||||||
|
coord: [10950.00, 6313.13],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Taranay',
|
||||||
|
coord: [9703.13, 6547.50],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Nogovo',
|
||||||
|
coord: [7681.88, 7848.75],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Airfield',
|
||||||
|
coord: [7104.38, 7325.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Dudino',
|
||||||
|
coord: [6133.13, 7286.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Bolotnoe',
|
||||||
|
coord: [5083.13, 8660.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'South Petropavlovsk-Sachalsky',
|
||||||
|
coord: [5443.13, 10001.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'North Petropavlovsk-Sachalsky',
|
||||||
|
coord: [5585.63, 11197.50],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Zupanovo',
|
||||||
|
coord: [5747.81, 12585.94],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sovetskoe',
|
||||||
|
coord: [6398.44, 12825.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Neran',
|
||||||
|
coord: [2685.00, 9251.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tugar',
|
||||||
|
coord: [1742.81, 6121.88],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Cerny Mys',
|
||||||
|
coord: [5173.13, 3828.75],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Kekra',
|
||||||
|
coord: [7066.88, 4280.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Slomanyy',
|
||||||
|
coord: [6333.75, 6453.75],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Utichy',
|
||||||
|
coord: [8563.13, 5079.38],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Elizarovo',
|
||||||
|
coord: [13395.00, 5175.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Solisko',
|
||||||
|
coord: [12693.75, 2291.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Mrak',
|
||||||
|
coord: [8480.63, 1313.44],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Ketoj',
|
||||||
|
coord: [5626.88, 1991.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Urup',
|
||||||
|
coord: [1680.00, 870.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Ayan',
|
||||||
|
coord: [1018.12, 2891.25],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Cerepacha',
|
||||||
|
coord: [813.75, 11287.50],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Odinokij Vulkan',
|
||||||
|
coord: [10020.00, 12008.44],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Pik Bolcij',
|
||||||
|
coord: [8195.63, 11675.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sakhalskaj GeoES',
|
||||||
|
coord: [8366.25, 10274.06],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Dolinovka',
|
||||||
|
coord: [9823.13, 9838.13],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Lesogorovka',
|
||||||
|
coord: [11006.25, 9729.38],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sachalag Military',
|
||||||
|
coord: [12140.63, 9757.50],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Goriachevo',
|
||||||
|
coord: [8887.50, 10018.13],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Yasnaya Polyana',
|
||||||
|
coord: [8128.13, 9150.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tichoe',
|
||||||
|
coord: [6245.63, 8655.00],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Ledanoj Greben Military',
|
||||||
|
coord: [10378.13, 8555.63],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Vysokoe',
|
||||||
|
coord: [11165.63, 7910.63],
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
+12
-3
@@ -7,17 +7,22 @@ module.exports = {
|
|||||||
if (!guild) {
|
if (!guild) {
|
||||||
guild = {}
|
guild = {}
|
||||||
guild.server = module.exports.getDefaultSettings(GuildId);
|
guild.server = module.exports.getDefaultSettings(GuildId);
|
||||||
|
guild.Nitrado = undefined;
|
||||||
if (client.databaseConnected) {
|
if (client.databaseConnected) {
|
||||||
thiclients.dbo.collection("guilds").insertOne(guild, (err, res) => {
|
client.dbo.collection("guilds").insertOne(guild, (err, res) => {
|
||||||
if (err) throw err;
|
if (err) client.error(`GetGuild Insert Error: ${err}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
serverID: GuildId,
|
serverID: GuildId,
|
||||||
|
Nitrado: guild.Nitrado,
|
||||||
|
lastLog: guild.server.lastLog,
|
||||||
|
serverName: guild.server.serverName,
|
||||||
autoRestart: guild.server.autoRestart,
|
autoRestart: guild.server.autoRestart,
|
||||||
showKillfeedCoords: guild.server.showKillfeedCoords,
|
showKillfeedCoords: guild.server.showKillfeedCoords,
|
||||||
|
showKillfeedWeapon: guild.server.showKillfeedWeapon,
|
||||||
purchaseUAV: guild.server.purchaseUAV,
|
purchaseUAV: guild.server.purchaseUAV,
|
||||||
purchaseEMP: guild.server.purchaseEMP,
|
purchaseEMP: guild.server.purchaseEMP,
|
||||||
allowedChannels: guild.server.allowedChannels,
|
allowedChannels: guild.server.allowedChannels,
|
||||||
@@ -32,6 +37,7 @@ module.exports = {
|
|||||||
factionArmbands: guild.server.factionArmbands,
|
factionArmbands: guild.server.factionArmbands,
|
||||||
usedArmbands: guild.server.usedArmbands,
|
usedArmbands: guild.server.usedArmbands,
|
||||||
excludedRoles: guild.server.excludedRoles,
|
excludedRoles: guild.server.excludedRoles,
|
||||||
|
hasExcludedRoles: guild.server.excludedRoles.length > 0 ? true : false,
|
||||||
botAdminRoles: guild.server.botAdminRoles,
|
botAdminRoles: guild.server.botAdminRoles,
|
||||||
|
|
||||||
alarms: guild.server.alarms,
|
alarms: guild.server.alarms,
|
||||||
@@ -56,8 +62,11 @@ module.exports = {
|
|||||||
getDefaultSettings(GuildId) {
|
getDefaultSettings(GuildId) {
|
||||||
return {
|
return {
|
||||||
serverID: GuildId,
|
serverID: GuildId,
|
||||||
autoRestart: 0, //
|
lastLog: null,
|
||||||
|
serverName: "our server!",
|
||||||
|
autoRestart: 0,
|
||||||
showKillfeedCoords: 0,
|
showKillfeedCoords: 0,
|
||||||
|
showKillfeedWeapon: 0,
|
||||||
purchaseUAV: 1, // Allow/Disallow purchase of UAVs
|
purchaseUAV: 1, // Allow/Disallow purchase of UAVs
|
||||||
purchaseEMP: 1, // Allow/Disallow purchase of EMPs
|
purchaseEMP: 1, // Allow/Disallow purchase of EMPs
|
||||||
allowedChannels: [],
|
allowedChannels: [],
|
||||||
|
|||||||
+117
-33
@@ -1,47 +1,131 @@
|
|||||||
|
const { weapons } = require('./weapons');
|
||||||
|
|
||||||
|
// Creates a copy of an object to prevent mutation of parent (i.e BodyParts, createWeaponsObject)
|
||||||
|
const copy = (obj) => JSON.parse(JSON.stringify(obj));
|
||||||
|
|
||||||
|
const BodyParts = {
|
||||||
|
Head: 0,
|
||||||
|
Torso: 0,
|
||||||
|
RightArm: 0,
|
||||||
|
LeftArm: 0,
|
||||||
|
RightLeg: 0,
|
||||||
|
LeftLeg: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const createWeaponsObject = (value) => {
|
||||||
|
const defaultWeapons = {};
|
||||||
|
for (const [_, weaponNames] of Object.entries(weapons)) {
|
||||||
|
for (const [name, _] of Object.entries(weaponNames)) {
|
||||||
|
defaultWeapons[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return copy(defaultWeapons);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
UpdatePlayer: async (client, player, interaction=null) => {
|
UpdatePlayer: async (client, player, interaction=null) => {
|
||||||
return await client.dbo.collection("players").updateOne({"playerID": player.playerID}, {$set: player}, (err, _) => {
|
/* Wrapping this function in a promise solves some bugs */
|
||||||
if (err) {
|
return new Promise(resolve => {
|
||||||
if (intearction == null) return client.error(err);
|
client.dbo.collection("players").updateOne(
|
||||||
else return client.sendInternalError(interaction, err);
|
{ "playerID": player.playerID },
|
||||||
}
|
{ $set: {...player} },
|
||||||
|
{ upsert: true }, // Create player stat document if it does not exist
|
||||||
|
(err, _) => {
|
||||||
|
if (err) {
|
||||||
|
if (interaction == null) return client.error(`UpdatePlayer Error: ${err}`);
|
||||||
|
else return client.sendInternalError(interaction, `UpdatePlayer Error: ${err}`);
|
||||||
|
} else resolve();
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultPlayer(gt, pID, NSID) {
|
getDefaultPlayer(gamertag, playerId, nitradoServerId) {
|
||||||
return {
|
return {
|
||||||
gamertag: gt,
|
// Identifiers
|
||||||
playerID: pID,
|
gamertag: gamertag,
|
||||||
discordID: "",
|
playerID: playerId,
|
||||||
nitradoServerID: NSID,
|
discordID: "",
|
||||||
|
nitradoServerID: nitradoServerId,
|
||||||
|
|
||||||
KDR: 0.00,
|
// General PVP Stats
|
||||||
kills: 0,
|
KDR: 0.00,
|
||||||
deaths: 0,
|
kills: 0,
|
||||||
killStreak: 0,
|
deaths: 0,
|
||||||
bestKillStreak: 0,
|
killStreak: 0,
|
||||||
longestKill: 0,
|
bestKillStreak: 0,
|
||||||
deathStreak: 0,
|
longestKill: 0,
|
||||||
worstDeathStreak: 0,
|
deathStreak: 0,
|
||||||
|
worstDeathStreak: 0,
|
||||||
|
|
||||||
pos: [],
|
// In depth PVP Stats
|
||||||
lastPos: [],
|
shotsLanded: 0,
|
||||||
time: null,
|
timesShot: 0,
|
||||||
lastTime: null,
|
shotsLandedPerBodyPart: copy(BodyParts),
|
||||||
|
timesShotPerBodyPart: copy(BodyParts),
|
||||||
|
weaponStats: createWeaponsObject({
|
||||||
|
kills: 0,
|
||||||
|
deaths: 0,
|
||||||
|
shotsLanded: 0,
|
||||||
|
timesShot: 0,
|
||||||
|
shotsLandedPerBodyPart: copy(BodyParts),
|
||||||
|
timesShotPerBodyPart: copy(BodyParts),
|
||||||
|
}),
|
||||||
|
combatRating: 800,
|
||||||
|
highestCombatRating: 800,
|
||||||
|
lowestCombatRating: 800,
|
||||||
|
combatRatingHistory: [800],
|
||||||
|
|
||||||
lastConnectionDate: null,
|
// General Session Data
|
||||||
lastDisconnectionDate: null,
|
lastConnectionDate: null,
|
||||||
lastDamageDate: null,
|
lastDisconnectionDate: null,
|
||||||
lastDeathDate: null,
|
lastDamageDate: null,
|
||||||
lastHitBy: null,
|
lastDeathDate: null,
|
||||||
connected: false,
|
lastHitBy: null,
|
||||||
|
connected: false,
|
||||||
|
pos: [],
|
||||||
|
lastPos: [],
|
||||||
|
time: null,
|
||||||
|
lastTime: null,
|
||||||
|
|
||||||
totalSessionTime: 0,
|
// Session Stats
|
||||||
lastSessionTime: 0,
|
totalSessionTime: 0,
|
||||||
longestSessionTime: 0,
|
lastSessionTime: 0,
|
||||||
connections: 0,
|
longestSessionTime: 0,
|
||||||
|
connections: 0,
|
||||||
|
|
||||||
bounties: [],
|
// Other
|
||||||
|
bounties: [],
|
||||||
|
bountiesLength: 0,
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
insertPVPstats(player) {
|
||||||
|
player.shotsLanded = 0;
|
||||||
|
player.timesShot = 0;
|
||||||
|
player.shotsLandedPerBodyPart = copy(BodyParts);
|
||||||
|
player.timesShotPerBodyPart = copy(BodyParts);
|
||||||
|
player.weaponStats = createWeaponsObject({
|
||||||
|
kills: 0,
|
||||||
|
deaths: 0,
|
||||||
|
shotsLanded: 0,
|
||||||
|
timesShot: 0,
|
||||||
|
shotsLandedPerBodyPart: copy(BodyParts),
|
||||||
|
timesShotPerBodyPart: copy(BodyParts),
|
||||||
|
});
|
||||||
|
return player;
|
||||||
|
},
|
||||||
|
|
||||||
|
// If a new weapon is not in the existing weaponStats, this will add it.
|
||||||
|
createWeaponStats(player, weapon) {
|
||||||
|
player.weaponStats[weapon] = {
|
||||||
|
kills: 0,
|
||||||
|
deaths: 0,
|
||||||
|
shotsLanded: 0,
|
||||||
|
timesShot: 0,
|
||||||
|
shotsLandedPerBodyPart: copy(BodyParts),
|
||||||
|
timesShotPerBodyPart: copy(BodyParts),
|
||||||
|
}
|
||||||
|
return player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
module.exports = {
|
||||||
|
weapons: {
|
||||||
|
handguns: {
|
||||||
|
"CR-75": "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/40/CZ75.png/revision/latest/scale-to-width-down/112?cb=20210505021307",
|
||||||
|
"Deagle": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/62/Deagle.png/revision/latest/scale-to-width-down/127?cb=20210512003023",
|
||||||
|
"Derringer": "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/9f/Derringer_Black.png/revision/latest/scale-to-width-down/105?cb=20220521175445",
|
||||||
|
"FX-45": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fd/FNX45.png/revision/latest/scale-to-width-down/104?cb=20210505025055",
|
||||||
|
"IJ-70": "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/26/MakarovIJ70.png/revision/latest/scale-to-width-down/92?cb=20210209000551",
|
||||||
|
"Kolt 1911": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f9/Colt1911.png/revision/latest/scale-to-width-down/112?cb=20210505030200",
|
||||||
|
"Longhorn": "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/79/Longhorn.png/revision/latest/scale-to-width-down/222?cb=20220324214533",
|
||||||
|
"MK II": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0d/MKII.png/revision/latest/scale-to-width-down/171?cb=20210210153348",
|
||||||
|
"Mlock-91": "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/9b/Glock19.png/revision/latest/scale-to-width-down/121?cb=20210505024259",
|
||||||
|
"P1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cc/P1.png/revision/latest/scale-to-width-down/120?cb=20220518204515",
|
||||||
|
"Revolver": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/6d/Revolver.png/revision/latest/scale-to-width-down/148?cb=20210208232303",
|
||||||
|
"Signal Pistol": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a7/Flaregun.png/revision/latest/scale-to-width-down/107?cb=20210501150913",
|
||||||
|
},
|
||||||
|
shotguns: {
|
||||||
|
"BK-12": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cb/Izh18Shotgun.png/revision/latest/scale-to-width-down/256?cb=20220922184507",
|
||||||
|
"BK-133": "https://static.wikia.nocookie.net/dayz_gamepedia/images/5/5c/MP-133-Shotgun.png/revision/latest/scale-to-width-down/256?cb=20210210190104",
|
||||||
|
"BK-43": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c7/Izh43Shotgun.png/revision/latest/scale-to-width-down/256?cb=20210210185835",
|
||||||
|
"Vaiga": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c8/Vaiga.png/revision/latest/scale-to-width-down/256?cb=20220220185225",
|
||||||
|
},
|
||||||
|
subMachineGuns: {
|
||||||
|
"Bizon": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/af/PP19.png/revision/latest/scale-to-width-down/251?cb=20220127132305",
|
||||||
|
"CR-61 Skorpion": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/63/VZ61Scorpion.png/revision/latest/scale-to-width-down/222?cb=20220518204508",
|
||||||
|
"SG5-K": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fc/MP5-K.png/revision/latest/scale-to-width-down/158?cb=20220221011343",
|
||||||
|
"USG-45": "https://static.wikia.nocookie.net/dayz_gamepedia/images/d/d7/UMP45.png/revision/latest/scale-to-width-down/153?cb=20220221002354",
|
||||||
|
},
|
||||||
|
assaultRifles: {
|
||||||
|
"AUR A1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e6/AugShort.png/revision/latest/scale-to-width-down/173?cb=20211104175243",
|
||||||
|
"AUR AX": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/be/Aug.png/revision/latest/scale-to-width-down/233?cb=20211104182427",
|
||||||
|
"KA-101": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f2/AK101.png/revision/latest/scale-to-width-down/251?cb=20210207040122",
|
||||||
|
"KA-74": "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/8b/AK74.png/revision/latest/scale-to-width-down/253?cb=20210505013141",
|
||||||
|
"KAS-74U": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0b/AKS74U.png/revision/latest/scale-to-width-down/191?cb=20210505014222",
|
||||||
|
"KA-M": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/6c/AKM.png/revision/latest/scale-to-width-down/244?cb=20210505011614",
|
||||||
|
"LE-MAS": "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/21/FAMAS.png/revision/latest/scale-to-width-down/197?cb=20210902183114",
|
||||||
|
"M16-A2": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b3/M16-A2.png/revision/latest/scale-to-width-down/256?cb=20220221002601",
|
||||||
|
"M4-A1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a1/M4A1.png/revision/latest/scale-to-width-down/223?cb=20220330014851",
|
||||||
|
"SVAL": "https://static.wikia.nocookie.net/dayz_gamepedia/images/3/39/ASVAL.png/revision/latest/scale-to-width-down/256?cb=20210208015731",
|
||||||
|
"Vikhr": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0d/Vikhr.png/revision/latest/scale-to-width-down/173?cb=20240116163108"
|
||||||
|
},
|
||||||
|
battleRifles: {
|
||||||
|
"LAR": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e9/FAL.png/revision/latest/scale-to-width-down/256?cb=20220221001123",
|
||||||
|
},
|
||||||
|
boltActionRifles: {
|
||||||
|
"CR-527": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f0/CR527Wood.png/revision/latest/scale-to-width-down/256?cb=20220518204503 ",
|
||||||
|
"CR-550 Savanna": "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/44/CR-550_Savanna.png/revision/latest/scale-to-width-down/256?cb=20220518204410",
|
||||||
|
"M70 Tundra": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/62/Winchester70.png/revision/latest/scale-to-width-down/256?cb=20220517152918",
|
||||||
|
"Mosin 91/30": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a8/Mosin9130.png/revision/latest/scale-to-width-down/256?cb=20230126021955",
|
||||||
|
"Pioneer": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/69/Scout.png/revision/latest/scale-to-width-down/256?cb=20220518204357",
|
||||||
|
"SSG 82": "https://static.wikia.nocookie.net/dayz_gamepedia/images/1/10/SSG82.png/revision/latest/scale-to-width-down/256?cb=20220922192455",
|
||||||
|
"VS-89": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ea/SV98.png/revision/latest/scale-to-width-down/256?cb=20240424164607",
|
||||||
|
},
|
||||||
|
breakActionRifles: {
|
||||||
|
"BK-18": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cb/IZH18_Rifle.png/revision/latest/scale-to-width-down/256?cb=20220517154121",
|
||||||
|
"Blaze": "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/8a/Blaze_95_Double_Rifle_Wood.png/revision/latest/scale-to-width-down/256?cb=20220517154129",
|
||||||
|
},
|
||||||
|
leverActionRifles: {
|
||||||
|
"Repeater Carbine": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/ce/Repeater.png/revision/latest/scale-to-width-down/256?cb=20220517154151",
|
||||||
|
},
|
||||||
|
marksmanRifles: {
|
||||||
|
"VSD": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a2/SVD_w._PSO-1.png/revision/latest/scale-to-width-down/256?cb=20220220235826",
|
||||||
|
"VSS": "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/83/VSSVintorez.png/revision/latest/scale-to-width-down/256?cb=20210208202042",
|
||||||
|
},
|
||||||
|
semiAutomaticRifles: {
|
||||||
|
"DMR": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b4/M14.png/revision/latest/scale-to-width-down/350?cb=20231005142636",
|
||||||
|
"SK 59/66": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fe/SKS.png/revision/latest/scale-to-width-down/256?cb=20220517154633",
|
||||||
|
"Sporter 22": "https://static.wikia.nocookie.net/dayz_gamepedia/images/5/5b/Sporter_22_Wood.png/revision/latest/scale-to-width-down/256?cb=20220518204154",
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
"Crossbow": "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/79/Crossbow.png/revision/latest/scale-to-width-down/212?cb=20180121164101",
|
||||||
|
"M79": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b7/M79.png/revision/latest/scale-to-width-down/256?cb=20220521184052",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
weaponClassOf: (weapon) => Object.keys(module.exports.weapons).filter(c => weapon in module.exports.weapons[c])[0],
|
||||||
|
}
|
||||||
@@ -4,11 +4,14 @@ const { GetGuild } = require('../database/guild');
|
|||||||
module.exports = async (client, member) => {
|
module.exports = async (client, member) => {
|
||||||
|
|
||||||
let GuildDB = await GetGuild(client, member.guild.id);
|
let GuildDB = await GetGuild(client, member.guild.id);
|
||||||
|
if (!client.exists(GuildDB.welcomeChannel)) return;
|
||||||
const channel = client.GetChannel(GuildDB.welcomeChannel);
|
const channel = client.GetChannel(GuildDB.welcomeChannel);
|
||||||
|
|
||||||
|
if (GuildDB.serverName == "") GuildDB.serverName = "our server!"
|
||||||
|
|
||||||
let embed = new EmbedBuilder()
|
let embed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Welcome** <@${member.user.id}> to **DayZ Reforger**\nTo gain access please use the command </gamertag-link:1087116946442559609>`);
|
.setDescription(`**Welcome** <@${member.user.id}> to **${GuildDB.serverName}**\nUse the </gamertag-link:1087116946442559609> command to link your Discord to your gamertag.`);
|
||||||
|
|
||||||
channel.send({ content: `<@${member.user.id}>`, embeds: [embed] });
|
channel.send({ content: `<@${member.user.id}>`, embeds: [embed] });
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
const { InteractionType } = require('discord.js');
|
||||||
const { GetGuild } = require('../database/guild');
|
const { GetGuild } = require('../database/guild');
|
||||||
|
|
||||||
|
|
||||||
module.exports = async (client, interaction) => {
|
module.exports = async (client, interaction) => {
|
||||||
if (interaction.isCommand()) return;
|
if (interaction.type == InteractionType.ApplicationCommand) return;
|
||||||
/*
|
/*
|
||||||
This file handles all menu and button interactions
|
This file routes any menu, modal & button interactions
|
||||||
from any command
|
from any command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,8 @@
|
|||||||
const DayzR = require('./src/DayzRBot');
|
const { ShardingManager } = require('discord.js');
|
||||||
const config = require('./config/config');
|
const config = require('./config/config');
|
||||||
const { GatewayIntentBits } = require('discord.js');
|
|
||||||
|
|
||||||
const path = require("path");
|
const manager = new ShardingManager('./bot.js', { token: config.Token });
|
||||||
const fs = require('fs');
|
|
||||||
const { HandleActivePlayersList } = require('./util/LogsHandler');
|
|
||||||
|
|
||||||
// Log all uncaught exceptions before killing process.
|
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
|
||||||
process.on('uncaughtException', async (error) => {
|
|
||||||
console.trace(error);
|
|
||||||
let d = new Date();
|
|
||||||
// Asynchronously write the error message to a log file using Promises
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
|
||||||
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
|
||||||
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
|
||||||
if (logErr) {
|
|
||||||
console.error('Error writing uncaughtException to log file:', logErr);
|
|
||||||
reject(logErr);
|
|
||||||
process.exit()
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Now gracefully close the program
|
manager.spawn();
|
||||||
process.exit()
|
|
||||||
});
|
|
||||||
|
|
||||||
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
|
||||||
client.build()
|
|
||||||
Generated
+79
-889
File diff suppressed because it is too large.
Load diff
+2
-4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "12.0.4",
|
"version": "13.3.21",
|
||||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
@@ -20,14 +20,12 @@
|
|||||||
"@discordjs/rest": "^1.1.0",
|
"@discordjs/rest": "^1.1.0",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"concat-stream": "^2.0.0",
|
"concat-stream": "^2.0.0",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"discord-bitfield-calculator": "^1.0.0",
|
"discord-bitfield-calculator": "^1.0.0",
|
||||||
"discord.js": "^14.8.0",
|
"discord.js": "^14.8.0",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"mongodb": "^4.12.1",
|
"mongodb": "^4.12.1",
|
||||||
"winston": "^3.8.1"
|
"winston": "^3.8.1"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"nodemon": "^2.0.20"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+228
-112
@@ -1,17 +1,21 @@
|
|||||||
const { RegisterGlobalCommands, RegisterGuildCommands } = require("../util/RegisterSlashCommands");
|
const { RegisterGlobalCommands, RegisterGuildCommands } = require("../util/RegisterSlashCommands");
|
||||||
const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
|
const { Collection, Client, EmbedBuilder, Routes, InteractionResponseType, InteractionType, GatewayDispatchEvents } = require('discord.js');
|
||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const { REST } = require('@discordjs/rest');
|
const { REST } = require('@discordjs/rest');
|
||||||
const Logger = require("../util/Logger");
|
const Logger = require("../util/Logger");
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
// custom util imports
|
// custom util imports
|
||||||
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings } = require('../util/NitradoAPI');
|
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings, PostServerSettings, NitradoCredentialStatus } = require('../util/NitradoAPI');
|
||||||
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
||||||
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler');
|
||||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require('../util/AlarmsHandler');
|
||||||
|
const { decrypt } = require('../util/Cryptic');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
// Data structures imports
|
// Data structures imports
|
||||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||||
|
const { Missions } = require('../database/destinations');
|
||||||
const { GetGuild } = require('../database/guild');
|
const { GetGuild } = require('../database/guild');
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
@@ -32,75 +36,109 @@ class DayzRBot extends Client {
|
|||||||
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
||||||
this.timer = this.config.Dev == 'PROD.' ? minute * 5 : minute / 4;
|
this.timer = this.config.Dev == 'PROD.' ? minute * 5 : minute / 4;
|
||||||
|
|
||||||
if (this.config.Token === "" || this.config.GuildID === "") {
|
if (
|
||||||
|
this.config.Token === "" ||
|
||||||
|
this.config.SecretKey === "" ||
|
||||||
|
this.config.SecretIv === ""
|
||||||
|
) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
"The config.js is not filled out. Please make sure nothing is blank, otherwise the bot will not work properly."
|
"The config.js is not filled out. Please make sure nothing is blank, otherwise the bot will not work properly."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!["DEV.", "PROD."].includes(this.config.Dev)) {
|
||||||
|
throw new TypeError(
|
||||||
|
"The Dev version in the config.js does not match the allowed cases of 'DEV.' or 'PROD.'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate secret hash with crypto to use for encryption
|
||||||
|
this.key = crypto
|
||||||
|
.createHash('sha512')
|
||||||
|
.update(this.config.SecretKey)
|
||||||
|
.digest('hex')
|
||||||
|
.substring(0, 32);
|
||||||
|
|
||||||
|
this.encryptionIV = crypto
|
||||||
|
.createHash('sha512')
|
||||||
|
.update(this.config.SecretIv)
|
||||||
|
.digest('hex')
|
||||||
|
.substring(0, 16);
|
||||||
|
|
||||||
this.db;
|
this.db;
|
||||||
this.dbo;
|
this.dbo;
|
||||||
|
|
||||||
this.databaseConnected = false;
|
this.databaseConnected = false;
|
||||||
this.arInterval = arInterval;
|
this.arInterval = arInterval;
|
||||||
this.arIntervalId; // Interval for auto-restart functions
|
this.arIntervalIds = new Map();
|
||||||
this.playerSessions = new Map();
|
this.playerSessions = new Map();
|
||||||
this.alarmPingQueue = {};
|
this.logHistory = new Map();
|
||||||
this.processingLogs = false;
|
this.alarmPingQueue = new Map();
|
||||||
this.autoRestartInit();
|
this.playerListMsgIds = new Map();
|
||||||
|
|
||||||
|
this.initialize();
|
||||||
this.LoadCommandsAndInteractionHandlers();
|
this.LoadCommandsAndInteractionHandlers();
|
||||||
this.LoadEvents();
|
this.LoadEvents();
|
||||||
|
|
||||||
this.Ready = false;
|
this.Ready = false;
|
||||||
this.activePlayersTick = 11;
|
this.activePlayersTick = 11;
|
||||||
|
|
||||||
this.ws.on("INTERACTION_CREATE", async (interaction) => {
|
this.ws.on(GatewayDispatchEvents.InteractionCreate, async (interaction) => {
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
if (interaction.type != 3) {
|
if (interaction.type == InteractionType.ApplicationCommand) {
|
||||||
let GuildDB = await GetGuild(this, interaction.guild_id);
|
let GuildDB = await GetGuild(this, interaction.guild_id);
|
||||||
|
|
||||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
if (this.exists(GuildDB.Nitrado) && this.exists(GuildDB.Nitrado.Auth)) {
|
||||||
const guild = this.guilds.cache.get(GuildDB.serverID);
|
GuildDB.Nitrado.Auth = decrypt(
|
||||||
const role = guild.roles.cache.find(role => role.id == factionID);
|
GuildDB.Nitrado.Auth,
|
||||||
if (!role) {
|
this.config.EncryptionMethod,
|
||||||
let query = {
|
this.key,
|
||||||
$pull: { 'server.usedArmbands': data.armband },
|
this.encryptionIV
|
||||||
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
);
|
||||||
};
|
|
||||||
await this.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
|
||||||
if (err) return this.sendInternalError(interaction, err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = interaction.data.name.toLowerCase();
|
const command = interaction.data.name.toLowerCase();
|
||||||
const args = interaction.data.options;
|
const args = interaction.data.options;
|
||||||
|
|
||||||
this.log(`Interaction - ${command}`);
|
// Free unused armbands for related commands
|
||||||
|
if (['armbands', 'claim', 'factions'].includes(command)) {
|
||||||
|
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||||
|
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}`]: "" },
|
||||||
|
};
|
||||||
|
this.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||||
|
if (err) return this.sendInternalError(interaction, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.rest = new REST({ version: '10' }).setToken(this.config.Token);
|
this.log(`Interaction [${interaction.guild_id}] - ${command}`);
|
||||||
|
|
||||||
|
const rest = new REST({ version: '10' }).setToken(this.config.Token);
|
||||||
|
|
||||||
// Easy to send response so ;)
|
// Easy to send response so ;)
|
||||||
interaction.guild = await this.guilds.fetch(interaction.guild_id);
|
interaction.guild = await this.guilds.fetch(interaction.guild_id);
|
||||||
interaction.send = async (message) => {
|
const handleCallback = async (interactionType, message) => {
|
||||||
return await this.rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
|
return await rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
|
||||||
body: {
|
body: {
|
||||||
type: 4,
|
type: interactionType,
|
||||||
data: message,
|
data: message,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
interaction.deferReply = async (message) => {
|
// Nicely name our custom callback functions and pass correct type because discord is picky with numbers...
|
||||||
return await this.rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
|
interaction.send = async (message) => handleCallback(InteractionResponseType.ChannelMessageWithSource, message);
|
||||||
body: {
|
interaction.deferReply = async (message) => handleCallback(InteractionResponseType.DeferredChannelMessageWithSource, message);
|
||||||
type: 5,
|
interaction.showModal = async (message) => handleCallback(InteractionResponseType.Modal, message);
|
||||||
data: message,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
interaction.editReply = async (message) => {
|
interaction.editReply = async (message) => {
|
||||||
return await this.rest.patch(Routes.webhookMessage(this.application.id, interaction.token), {
|
return await rest.patch(Routes.webhookMessage(this.application.id, interaction.token), {
|
||||||
body: message,
|
body: message,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -135,17 +173,7 @@ class DayzRBot extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async readLogs(guild) {
|
async readLogs(guild) {
|
||||||
const fileStream = fs.createReadStream('./logs/server-logs.ADM');
|
const fileStream = fs.createReadStream(`./logs/${guild.Nitrado.ServerID}-logs.ADM`);
|
||||||
|
|
||||||
let logHistoryDir = path.join(__dirname, '..', 'logs', 'history-logs.ADM.json');
|
|
||||||
let history;
|
|
||||||
try {
|
|
||||||
history = JSON.parse(fs.readFileSync(logHistoryDir));
|
|
||||||
} catch (err) {
|
|
||||||
history = {
|
|
||||||
lastLog: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fileStream,
|
input: fileStream,
|
||||||
@@ -154,13 +182,14 @@ class DayzRBot extends Client {
|
|||||||
let lines = [];
|
let lines = [];
|
||||||
for await (const line of rl) { lines.push(line); }
|
for await (const line of rl) { lines.push(line); }
|
||||||
|
|
||||||
let logIndex = lines.indexOf(history.lastLog);
|
let logIndex = lines.indexOf(this.logHistory.get(guild.Nitrado.ServerID));
|
||||||
|
|
||||||
|
if (this.playerSessions.get(guild.Nitrado.ServerID).size === 0) {
|
||||||
|
let players = await this.dbo.collection('players').find({"nitradoServerID": guild.Nitrado.ServerID}) // Get all players of this server
|
||||||
|
.toArray().then(all => all.filter(p => p.connected).map(p => p.connected = false)); // assume all players who were previously connected are not connected on init only.
|
||||||
|
|
||||||
if (this.playerSessions.size === 0) {
|
|
||||||
let players = await this.dbo.collection('players').find({"connected": true}).toArray();
|
|
||||||
players.map(p => p.connected = false); // assume all players not connected on init only.
|
|
||||||
for (let i = 0; i < players.length; i++) {
|
for (let i = 0; i < players.length; i++) {
|
||||||
UpdatePlayer(this, players[i])
|
await UpdatePlayer(this, players[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,43 +200,52 @@ class DayzRBot extends Client {
|
|||||||
if ((i - 1) >= 0 && lines[i] == lines[i - 1]) continue; // continue if this line is a duplicate of the last line
|
if ((i - 1) >= 0 && lines[i] == lines[i - 1]) continue; // continue if this line is a duplicate of the last line
|
||||||
|
|
||||||
// Handle general logs
|
// Handle general logs
|
||||||
if (lines[i].includes('connected') || lines[i].includes('pos=<')) await HandlePlayerLogs(this, guild, lines[i], guild.combatLogTimer);
|
if (lines[i].includes('connected') || lines[i].includes('pos=<')) await HandlePlayerLogs(guild.Nitrado.ServerID, this, guild, lines[i], guild.combatLogTimer);
|
||||||
if (lines[i].includes('killed by Zmb') || lines[i].includes('>) died.')) await UpdateLastDeathDate(this, lines[i]); // Updates users last death date for non PVP deaths.
|
if (lines[i].includes('killed by Zmb') || lines[i].includes('>) died.')) await UpdateLastDeathDate(guild.Nitrado.ServerID, this, lines[i]); // Updates users last death date for non PVP deaths.
|
||||||
if (lines[i].includes(') placed Fireplace')) await PlaceFireplaceInAlarm(this, guild, lines[i]);
|
if (lines[i].includes(') placed Fireplace')) await PlaceFireplaceInAlarm(this, guild, lines[i]);
|
||||||
|
|
||||||
// Handle killfeed logs
|
// Handle killfeed logs
|
||||||
if (lines[i].includes('killed by with') || lines[i].includes('killed by LandMineTrap')) await HandleKillfeed(this, guild, lines[i]); // Handles explosive deaths
|
if (
|
||||||
if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by') && lines[i].includes('TransportHit')) await HandleKillfeed(this, guild, lines[i]); // Handles vehicle deaths
|
(lines[i].includes('killed by with') || lines[i].includes('killed by LandMineTrap')) || // Handle explosive deaths
|
||||||
if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player') && lines[i].includes('hit by Player')) await HandleKillfeed(this, guild, lines[i]); // Handles regular deaths
|
(!(i + 1 >= lines.length) && lines[i + 1].includes('killed by') && lines[i].includes('TransportHit')) || // Handle vehicle deaths
|
||||||
if (lines[i].includes('killed by Player') && !lines[i - 1].includes('hit by Player')) await HandleKillfeed(this, guild, lines[i]); // Handles deaths missing hit by log
|
(!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player') && lines[i].includes('hit by Player')) || // Handle PVP deaths
|
||||||
|
(lines[i].includes('killed by Player') && !lines[i - 1].includes('hit by Player')) // Handle deaths missing hit by log
|
||||||
|
) await HandleKillfeed(guild.Nitrado.ServerID, this, guild, lines[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle alarm pings
|
// Handle alarm pings
|
||||||
const maxEmbed = 10;
|
const maxEmbed = 10;
|
||||||
for (const [channel_id, data] of Object.entries(this.alarmPingQueue)) {
|
|
||||||
const channel = this.GetChannel(channel_id);
|
this.alarmPingQueue.forEach(queue => {
|
||||||
if (!channel) continue;
|
queue.forEach(async (data, channel_id) => {
|
||||||
for (const [role, embeds] of Object.entries(data)) {
|
const channel = this.GetChannel(channel_id);
|
||||||
if (embeds.length > maxEmbed) {
|
if (!channel) return;
|
||||||
|
|
||||||
|
const NAME = "DayZ.R Zone Alert";
|
||||||
|
const webhook = await GetWebhook(this, NAME, channel_id);
|
||||||
|
|
||||||
|
data.forEach(async (embeds, role) => {
|
||||||
let embedArrays = [];
|
let embedArrays = [];
|
||||||
while (embeds.length > maxEmbed)
|
while (embeds.length > 0);
|
||||||
embedArrays.push(embeds.splice(0, maxEmbed));
|
embedArrays.push(embeds.splice(0, maxEmbed));
|
||||||
|
|
||||||
for (let i = 0; i < embedArrays.length; i++) {
|
for (let i = 0; i < embedArrays.length; i++) {
|
||||||
if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
let content = { embeds: embedArrays[i] };
|
||||||
else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
if (role != '-no-role-ping-') content.content = `<@&${role}>`;
|
||||||
}
|
WebhookSend(this, webhook, content);
|
||||||
} else {
|
|
||||||
if (role == '-no-role-ping-') channel.send({ embeds: embeds });
|
|
||||||
else channel.send({ content: `<@&${role}>`, embeds: embeds });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.alarmPingQueue = {};
|
// if (role == '-no-role-ping-') channel.send({ embeds: embedArrays[i] });
|
||||||
|
// else channel.send({ content: `<@&${role}>`, embeds: embedArrays[i] });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.alarmPingQueue.set(guild.serverID, new Map()); // Clear alarm queue for this guild
|
||||||
|
|
||||||
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
||||||
let previouslyConnected = await this.dbo.collection('players').find({"connected": true}).toArray(); // All players with connection log captured above and no disconnect log
|
let previouslyConnected = await this.dbo.collection('players').find({"nitradoServerID": guild.Nitrado.ServerID})
|
||||||
|
.toArray().then(players => players.filter(p => p.connected)); // All players with connection log captured above and no disconnect log
|
||||||
let lastDetectedTime;
|
let lastDetectedTime;
|
||||||
|
|
||||||
for (let i = lines.length - 1; i > 0; i--) {
|
for (let i = lines.length - 1; i > 0; i--) {
|
||||||
@@ -230,14 +268,14 @@ class DayzRBot extends Client {
|
|||||||
lastDetectedTime = await this.getDateEST(info.time);
|
lastDetectedTime = await this.getDateEST(info.time);
|
||||||
|
|
||||||
let playerStat = await this.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await this.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!this.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, this.config.Nitrado.ServerID);
|
if (!this.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, guild.Nitrado.ServerID);
|
||||||
|
|
||||||
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
||||||
|
|
||||||
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
||||||
if (this.playerSessions.has(info.playerID)) {
|
if (this.playerSessions.get(guild.Nitrado.ServerID).has(info.playerID)) {
|
||||||
// Player is already in a session, update the session's end time.
|
// Player is already in a session, update the session's end time.
|
||||||
const session = this.playerSessions.get(info.playerID);
|
const session = this.playerSessions.get(guild.Nitrado.ServerID).get(info.playerID);
|
||||||
session.endTime = lastDetectedTime; // Update end time.
|
session.endTime = lastDetectedTime; // Update end time.
|
||||||
} else {
|
} else {
|
||||||
// Player is not in a session, create a new session.
|
// Player is not in a session, create a new session.
|
||||||
@@ -245,7 +283,7 @@ class DayzRBot extends Client {
|
|||||||
startTime: lastDetectedTime,
|
startTime: lastDetectedTime,
|
||||||
endTime: null, // Initialize end time as null.
|
endTime: null, // Initialize end time as null.
|
||||||
};
|
};
|
||||||
this.playerSessions.set(info.playerID, newSession);
|
this.playerSessions.get(guild.Nitrado.ServerID).set(info.playerID, newSession);
|
||||||
|
|
||||||
// Check if the player has been marked as connected before, but only if a session doesn't exist
|
// Check if the player has been marked as connected before, but only if a session doesn't exist
|
||||||
// in the map, indicating the connection was discovered in the logs during this session.
|
// in the map, indicating the connection was discovered in the logs during this session.
|
||||||
@@ -261,36 +299,73 @@ class DayzRBot extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
history.lastLog = lines[lines.length - 1];
|
const lastLine = lines[lines.length - 1]
|
||||||
|
this.logHistory.set(guild.Nitrado.ServerID, lastLine);
|
||||||
// write JSON string to a file
|
this.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, {$set: { "server.lastLog": lastLine }}, (err, res) => {
|
||||||
fs.writeFileSync(logHistoryDir, JSON.stringify(history));
|
if (err) this.error(`Failed to save last log to guild config [${guild.serverID}] for nitrado server [${guild.Nitrado.ServerID}]`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async logsUpdateTimer(c) {
|
async logsUpdateTimer(c) {
|
||||||
if (c.processingLogs) return; // Process is already running, wait till next scheduled time.
|
|
||||||
c.processingLogs = true;
|
|
||||||
let t = new Date();
|
|
||||||
// c.log(`...Logs Tick - ${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}...`);
|
|
||||||
c.activePlayersTick++;
|
c.activePlayersTick++;
|
||||||
|
|
||||||
const settings = await FetchServerSettings(c, "logsUpdateTimer").then(res => res.data.gameserver);
|
c.guilds.cache.forEach(async (guild) => {
|
||||||
const filename = settings.game_specific.log_files.sort((a, b) => a.length - b.length)[0];
|
let GuildDB = await GetGuild(c, guild.id);
|
||||||
const path = `${settings.game_specific.path.slice(0, -1)}${filename.split(settings.game)[1]}`;
|
|
||||||
|
|
||||||
let guild = await GetGuild(c, c.config.GuildID);
|
/*
|
||||||
|
Note to self:
|
||||||
|
return statements do not prematurely exit out of a forEach loop like it does in a for loop.
|
||||||
|
*/
|
||||||
|
|
||||||
await DownloadNitradoFile(c, path, './logs/server-logs.ADM').then(async (status) => {
|
if (!c.exists(GuildDB.Nitrado)) return; // Continue if no nitrado credentials
|
||||||
if (status == 1) return c.error('...Failed to Download logs...');
|
if (GuildDB.Nitrado.Status == NitradoCredentialStatus.FAILED) return; // Continue if these credentials are marked as failed
|
||||||
// c.log('...Downloaded logs...');
|
|
||||||
await c.readLogs(guild).then(async () => {
|
const NitradoCred = {
|
||||||
// c.log('...Analyzed logs...');
|
ServerID: GuildDB.Nitrado.ServerID,
|
||||||
HandleExpiredUAVs(c, guild);
|
UserID: GuildDB.Nitrado.UserID,
|
||||||
HandleEvents(c, guild)
|
Auth: decrypt(
|
||||||
if (c.activePlayersTick == 12) await HandleActivePlayersList(c, guild);
|
GuildDB.Nitrado.Auth,
|
||||||
})
|
c.config.EncryptionMethod,
|
||||||
|
c.key,
|
||||||
|
c.encryptionIV
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await FetchServerSettings(NitradoCred, c, "logsUpdateTimer").then(res => res);
|
||||||
|
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 [${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]}`;
|
||||||
|
|
||||||
|
// 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) => {
|
||||||
|
if (status == 1) return c.error(`Failed to Download Nitrado Log Files - [${NitradoCred.ServerID}]`);
|
||||||
|
await c.readLogs(GuildDB).then(async () => {
|
||||||
|
HandleExpiredUAVs(c, GuildDB);
|
||||||
|
HandleEvents(c, GuildDB)
|
||||||
|
if (c.activePlayersTick == 12) await HandleActivePlayersList(NitradoCred, c, GuildDB);
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
c.processingLogs = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectMongo(mongoURI, dbo) {
|
async connectMongo(mongoURI, dbo) {
|
||||||
@@ -322,7 +397,9 @@ class DayzRBot extends Client {
|
|||||||
this.databaseConnected = true;
|
this.databaseConnected = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
databaselogs.attempts++;
|
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}`);
|
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
@@ -333,20 +410,51 @@ class DayzRBot extends Client {
|
|||||||
if (failed) process.exit(-1);
|
if (failed) process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async autoRestartInit() {
|
async initialize() {
|
||||||
// Wait for MongoDB to connect
|
// Wait for MongoDB to connect
|
||||||
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||||
|
|
||||||
let is_enabled = undefined;
|
if (!this.databaseConnected) return;
|
||||||
if (this.databaseConnected) is_enabled = await this.dbo.collection("guilds").findOne({ "server.autoRestart": 1 }).then(is_enabled => is_enabled);
|
let guilds = await this.dbo.collection("guilds").find({}).toArray();
|
||||||
|
|
||||||
if (is_enabled) {
|
/*
|
||||||
this.log('Starting periodic Nitrado server status check.');
|
Initialize auto restart for enabled servers
|
||||||
this.arIntervalId = setInterval(CheckServerStatus, this.arInterval, this);
|
Initialize last logs
|
||||||
|
Initialize Player Sessions
|
||||||
|
*/
|
||||||
|
for (let i = 0; i < guilds.length; i++) {
|
||||||
|
if (!this.exists(guilds[i].Nitrado)) continue;
|
||||||
|
if (guilds[i].server.autoRestart) {
|
||||||
|
const NitradoCred = {
|
||||||
|
ServerID: guilds[i].Nitrado.ServerID,
|
||||||
|
UserID: guilds[i].Nitrado.UserID,
|
||||||
|
Auth: decrypt(
|
||||||
|
guilds[i].Nitrado.Auth,
|
||||||
|
this.config.EncryptionMethod,
|
||||||
|
this.key,
|
||||||
|
this.encryptionIV
|
||||||
|
)
|
||||||
|
};
|
||||||
|
this.arIntervalIds.set(guilds[i].server.serverID, setInterval(CheckServerStatus, this.arInterval, NitradoCred, this))
|
||||||
|
}
|
||||||
|
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.alarmPingQueue.set(guilds[i].serverID, new Map()); // Initialize alarm queue to be empty
|
||||||
|
this.playerListMsgIds.set(guilds[i].serverID, ""); // Initialize player list message ids
|
||||||
|
this.log(`[${guilds[i].server.serverID}] Initialized existing Nitrado`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exists(n) { return null != n && undefined != n && "" != n }
|
async initNewNitradoServer(guildId, Nitrado) {
|
||||||
|
let guild = await GetGuild(this, guildId)
|
||||||
|
|
||||||
|
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`);
|
||||||
|
}
|
||||||
|
|
||||||
|
exists(n) { return typeof(n) == 'number' ? !isNaN(n) : null != n && undefined != n && "" != n }
|
||||||
|
|
||||||
secondsToDhms(seconds) {
|
secondsToDhms(seconds) {
|
||||||
seconds = Number(seconds);
|
seconds = Number(seconds);
|
||||||
@@ -429,7 +537,15 @@ class DayzRBot extends Client {
|
|||||||
// Calls register for guild and global commands
|
// Calls register for guild and global commands
|
||||||
RegisterSlashCommands() {
|
RegisterSlashCommands() {
|
||||||
RegisterGlobalCommands(this);
|
RegisterGlobalCommands(this);
|
||||||
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
let p = Promise.resolve()
|
||||||
|
this.guilds.cache.forEach((guild) => {
|
||||||
|
p = p.then(() => {
|
||||||
|
RegisterGuildCommands(this, guild.id);
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 500);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
|||||||
+19
-23
@@ -1,12 +1,13 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { destinations } = require('../database/destinations');
|
const { nearest } = require('../database/destinations');
|
||||||
const { calculateVector } = require('./vector');
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
SendConnectionLogs: async (client, guild, data) => {
|
SendConnectionLogs: async (client, guild, data) => {
|
||||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
const channel = client.GetChannel(guild.connectionLogsChannel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||||
@@ -15,25 +16,31 @@ module.exports = {
|
|||||||
.setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red)
|
.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'}**`);
|
.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.connected) {
|
||||||
if (!(data.lastConnectionDate == null)) {
|
if (data.lastConnectionDate != null) {
|
||||||
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000);
|
||||||
let sessionTime = client.secondsToDhms(unixTime - oldUnixTime);
|
let sessionTime = client.secondsToDhms(unixTime - oldUnixTime);
|
||||||
connectionLog.addFields({ name: '**Session Time**', value: `**${sessionTime}**`, inline: false });
|
connectionLog.addFields({ name: '**Session Time**', value: `**${sessionTime}**`, inline: false });
|
||||||
} else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false });
|
} 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) => {
|
DetectCombatLog: async (client, guild, data) => {
|
||||||
if (!client.exists(data.lastDamageDate)) return;
|
if (!client.exists(data.lastDamageDate)) return;
|
||||||
if (!client.exists(guild.connectionLogsChannel)) 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 newDt = await client.getDateEST(data.time);
|
||||||
const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
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
|
// or if death after last combat
|
||||||
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
if (diffSeconds > (data.combatLogTimer * 60)) return;
|
||||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||||
@@ -43,30 +50,19 @@ module.exports = {
|
|||||||
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy});
|
||||||
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
if (attacker.lastDeathDate > data.lastDamageDate) return;
|
||||||
|
|
||||||
const channel = client.GetChannel(guild.connectionLogsChannel);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
let unixTime = Math.floor(newDt.getTime() / 1000);
|
let unixTime = Math.floor(newDt.getTime() / 1000);
|
||||||
|
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
||||||
let tempDest;
|
|
||||||
let lastDist = 1000000;
|
|
||||||
let destination_dir;
|
|
||||||
for (let i = 0; i < destinations.length; i++) {
|
|
||||||
let { distance, theta, dir } = calculateVector(data.pos, 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}`;
|
|
||||||
|
|
||||||
let combatLog = new EmbedBuilder()
|
let combatLog = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Red)
|
.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}`);
|
.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] });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+38
-37
@@ -1,8 +1,8 @@
|
|||||||
const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
const { BanPlayer, UnbanPlayer } = require('./NitradoAPI');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { calculateVector } = require('./vector');
|
const { nearest } = require('../database/destinations');
|
||||||
const { destinations } = require('../database/destinations');
|
|
||||||
const { GetGuild } = require('../database/guild');
|
const { GetGuild } = require('../database/guild');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
// Private functions (only called locally)
|
// Private functions (only called locally)
|
||||||
|
|
||||||
@@ -21,32 +21,30 @@ const ExpireEvent = async(client, guild, e) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const HandlePlayerTrackEvent = 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 player = await client.dbo.collection("players").findOne({"gamertag": e.gamertag});
|
||||||
|
|
||||||
let newDt = await client.getDateEST(player.time);
|
let newDt = await client.getDateEST(player.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
let tempDest;
|
const destination = nearest(player.pos, guild.Nitrado.Mission);
|
||||||
let lastDist = 1000000;
|
|
||||||
let destination_dir;
|
|
||||||
for (let i = 0; i < destinations.length; i++) {
|
|
||||||
let { distance, theta, dir } = calculateVector(player.pos, 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 trackEvent = new EmbedBuilder()
|
const trackEvent = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.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}`);
|
.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 NAME = "DayZ.R Player Tracker";
|
||||||
const channel = client.GetChannel(e.channel);
|
const webhook = await GetWebhook(client, NAME, e.channel);
|
||||||
if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] });
|
|
||||||
else channel.send({ embeds: [trackEvent] });
|
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 now = new Date();
|
||||||
let diff = ((now - e.creationDate) / 1000) / 60;
|
let diff = ((now - e.creationDate) / 1000) / 60;
|
||||||
@@ -76,12 +74,12 @@ module.exports = {
|
|||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
if (!client.alarmPingQueue[alarm.channel]) client.alarmPingQueue[alarm.channel] = {};
|
if (!client.alarmPingQueue.get(guild.serverID).has(alarm.channel)) client.alarmPingQueue.get(guild.serverID).set(alarm.channel, new Map());
|
||||||
let route = alarm.mute ? '-no-role-ping-' : alarm.role;
|
let route = alarm.mute ? null : alarm.role;
|
||||||
if (!client.alarmPingQueue[alarm.channel][route]) client.alarmPingQueue[alarm.channel][route] = [];
|
if (!client.alarmPingQueue.get(guild.serverID).get(alarm.channel).has(route)) client.alarmPingQueue.get(guild.serverID).get(alarm.channel).set(route, []);
|
||||||
|
|
||||||
if (alarm.rules.includes['ban_on_entry']) {
|
if (alarm.rules.includes['ban_on_entry']) {
|
||||||
client.alarmPingQueue[alarm.channel][route].push(
|
client.alarmPingQueue.get(guild.serverID).get(alarm.channel).get(route).push(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`)
|
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`)
|
||||||
@@ -92,7 +90,7 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.alarmPingQueue[alarm.channel][route].push(
|
client.alarmPingQueue.get(guild.serverID).get(alarm.channel).get(route).push(
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`)
|
.setDescription(`**Zone Ping - <t:${unixTime}>**\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`)
|
||||||
@@ -113,18 +111,7 @@ module.exports = {
|
|||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
let tempDest;
|
const destination = nearest(data.pos, guild.Nitrado.Mission);
|
||||||
let lastDist = 1000000;
|
|
||||||
let destination_dir;
|
|
||||||
for (let i = 0; i < destinations.length; i++) {
|
|
||||||
let { distance, theta, dir } = calculateVector(data.pos, 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}`;
|
|
||||||
|
|
||||||
let uavEmbed = new EmbedBuilder()
|
let uavEmbed = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
@@ -180,6 +167,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (distance < alarm.radius) {
|
if (distance < alarm.radius) {
|
||||||
const channel = client.GetChannel(alarm.channel);
|
const channel = client.GetChannel(alarm.channel);
|
||||||
|
if (!channel) continue;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(data.time);
|
let newDt = await client.getDateEST(data.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
@@ -189,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}**.__`)
|
.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 })
|
.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);
|
BanPlayer(client, data.killer);
|
||||||
break;
|
break;
|
||||||
@@ -221,6 +215,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (distance < alarm.radius) {
|
if (distance < alarm.radius) {
|
||||||
const channel = client.GetChannel(alarm.channel);
|
const channel = client.GetChannel(alarm.channel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
let newDt = await client.getDateEST(info.time);
|
let newDt = await client.getDateEST(info.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
@@ -230,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**.__`)
|
.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 })
|
.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);
|
BanPlayer(client, info.player);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
calculateNewCombatRating: (Ra, Rb, score) => {
|
||||||
|
const Ea = 1 / (1 + Math.pow(10, ((Rb - Ra) / 400)));
|
||||||
|
return Math.round(Ra + 32 * (score - Ea));
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
encrypt: (data, EncryptionMethod, Key, EncryptionIV) => {
|
||||||
|
const cipher = crypto.createCipheriv(EncryptionMethod, Key, EncryptionIV)
|
||||||
|
return Buffer.from(
|
||||||
|
cipher.update(data, 'utf8', 'hex') + cipher.final('hex')
|
||||||
|
).toString('base64') // Encrypts data and converts to hex and base64
|
||||||
|
},
|
||||||
|
|
||||||
|
decrypt: (data, EncryptionMethod, Key, EncryptionIV) => {
|
||||||
|
const buff = Buffer.from(data, 'base64')
|
||||||
|
const decipher = crypto.createDecipheriv(EncryptionMethod, Key, EncryptionIV)
|
||||||
|
return (
|
||||||
|
decipher.update(buff.toString('utf8'), 'hex', 'utf8') +
|
||||||
|
decipher.final('utf8')
|
||||||
|
) // Decrypts data and converts to utf8
|
||||||
|
}
|
||||||
|
}
|
||||||
+108
-54
@@ -1,9 +1,11 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { createUser, addUser } = require('../database/user');
|
const { createUser, addUser } = require('../database/user');
|
||||||
const { KillInAlarm } = require('./AlarmsHandler');
|
const { KillInAlarm } = require('./AlarmsHandler');
|
||||||
const { destinations } = require('../database/destinations');
|
const { nearest } = require('../database/destinations');
|
||||||
const { calculateVector } = require('./vector');
|
|
||||||
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
const { getDefaultPlayer, UpdatePlayer } = require('../database/player');
|
||||||
|
const { calculateNewCombatRating } = require('./CombatRatingHandler');
|
||||||
|
const { weapons, weaponClassOf } = require('../database/weapons');
|
||||||
|
const { GetWebhook, WebhookSend } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
const Templates = {
|
const Templates = {
|
||||||
Killed: 1,
|
Killed: 1,
|
||||||
@@ -15,6 +17,16 @@ const Templates = {
|
|||||||
Vehicle: 7,
|
Vehicle: 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TemplateExpressions = {
|
||||||
|
1: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) with (.*) from (.*) meters /g,
|
||||||
|
2: /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g,
|
||||||
|
3: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g,
|
||||||
|
4: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by with (.*)/g,
|
||||||
|
5: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by LandMineTrap/g,
|
||||||
|
6: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*)/g,
|
||||||
|
7: /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by (.*) with TransportHit/g,
|
||||||
|
};
|
||||||
|
|
||||||
const Vehicles = {
|
const Vehicles = {
|
||||||
CivilianSedan: 'White Olga',
|
CivilianSedan: 'White Olga',
|
||||||
CivilianSedan_Black: 'Black Olga',
|
CivilianSedan_Black: 'Black Olga',
|
||||||
@@ -42,7 +54,7 @@ const Vehicles = {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
// Update last death date for non PVP deaths
|
// Update last death date for non PVP deaths
|
||||||
UpdateLastDeathDate: async (client, line) => {
|
UpdateLastDeathDate: async (NitradoServerID, client, line) => {
|
||||||
let killedByZmb = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by (.*)/g;
|
let killedByZmb = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by (.*)/g;
|
||||||
let diedTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) died\. Stats> Water: (.*) Energy: (.*) Bleed sources: (.*)/g;
|
let diedTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) died\. Stats> Water: (.*) Energy: (.*) Bleed sources: (.*)/g;
|
||||||
|
|
||||||
@@ -59,39 +71,27 @@ module.exports = {
|
|||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||||
|
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
|
|
||||||
return await UpdatePlayer(client, victimStat);
|
await UpdatePlayer(client, victimStat);
|
||||||
|
return
|
||||||
},
|
},
|
||||||
|
|
||||||
HandleKillfeed: async (client, guild, line) => {
|
HandleKillfeed: async (NitradoServerID, client, guild, line) => {
|
||||||
|
|
||||||
|
const NAME = "DayZ.R Killfeed";
|
||||||
const channel = client.GetChannel(guild.killfeedChannel);
|
const channel = client.GetChannel(guild.killfeedChannel);
|
||||||
|
|
||||||
let templateKilled = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) with (.*) from (.*) meters /g;
|
const killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
||||||
let template = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
line.includes('hit by Player') && !line.includes('meters') ? Templates.Melee : // Missing meters indicates it was a melee attack.
|
||||||
let templateDEAD = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g;
|
line.includes('hit by Player') ? Templates.HitBy :
|
||||||
let explosionTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by with (.*)/g;
|
line.includes('killed by Player') ? Templates.Killed :
|
||||||
let landMineTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by LandMineTrap/g;
|
line.includes('TransportHit') ? Templates.Vehicle :
|
||||||
let meleeTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*)/g;
|
line.includes('killed by LandMineTrap') ? Templates.LandMine : Templates.Explosion;
|
||||||
let vehicleTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by (.*) with TransportHit/g;
|
|
||||||
|
|
||||||
let killedBy = line.includes('hit by Player') && line.includes('(DEAD)') && line.includes('meters') ? Templates.HitByAndDead :
|
let data = [...line.matchAll(TemplateExpressions[killedBy])][0];
|
||||||
line.includes('hit by Player') && !line.includes('meters') ? Templates.Melee : // Missing meters indicates it was a melee attack.
|
|
||||||
line.includes('hit by Player') ? Templates.HitBy :
|
|
||||||
line.includes('killed by Player') ? Templates.Killed :
|
|
||||||
line.includes('TransportHit') ? Templates.Vehicle :
|
|
||||||
line.includes('killed by LandMineTrap') ? Templates.LandMine : Templates.Explosion;
|
|
||||||
|
|
||||||
let data = killedBy == Templates.HitByAndDead ? [...line.matchAll(templateDEAD)][0] :
|
|
||||||
killedBy == Templates.HitBy ? [...line.matchAll(template)][0] :
|
|
||||||
killedBy == Templates.Killed ? [...line.matchAll(templateKilled)][0] :
|
|
||||||
killedBy == Templates.LandMine ? [...line.matchAll(landMineTemplate)][0] :
|
|
||||||
killedBy == Templates.Melee ? [...line.matchAll(meleeTemplate)][0] :
|
|
||||||
killedBy == Templates.Vehicle ? [...line.matchAll(vehicleTemplate)][0] :
|
|
||||||
[...line.matchAll(explosionTemplate)][0];
|
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add additional data
|
// Add additional data
|
||||||
if (killedBy == Templates.HitBy || killedBy == Templates.HitByAndDead || killedBy == Templates.Melee) {
|
if ([Templates.HitBy, Templates.HitByAndDead, Templates.Melee].includes(killedBy)) {
|
||||||
info.killer = data[6];
|
info.killer = data[6];
|
||||||
info.killerID = data[7];
|
info.killerID = data[7];
|
||||||
info.killerPOS = data[8].split(', ').map(v => parseFloat(v));
|
info.killerPOS = data[8].split(', ').map(v => parseFloat(v));
|
||||||
@@ -127,23 +127,19 @@ module.exports = {
|
|||||||
const unixTime = Math.floor(newDt.getTime()/1000);
|
const unixTime = Math.floor(newDt.getTime()/1000);
|
||||||
|
|
||||||
const showCoords = client.exists(guild.showKillfeedCoords) ? guild.showKillfeedCoords : false; // default to false if no record of configuration.
|
const showCoords = client.exists(guild.showKillfeedCoords) ? guild.showKillfeedCoords : false; // default to false if no record of configuration.
|
||||||
let tempDest;
|
const showWeapon = client.exists(guild.showKillfeedWeapon) ? guild.showKillfeedWeapon : false; // default to false if no record of configuration.
|
||||||
let lastDist = 1000000;
|
|
||||||
let destination_dir;
|
|
||||||
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(info.victimPOS, guild.Nitrado.Mission);
|
||||||
|
|
||||||
|
if ([Templates.LandMine, Templates.Explosion, Templates.Vehicle].includes(killedBy))
|
||||||
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) {
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, client.config.Nitrado.ServerID);
|
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;
|
victimStat.lastDeathDate = newDt;
|
||||||
|
|
||||||
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
const cod = killedBy == Templates.LandMine ? `Land Mine Trap` :
|
||||||
@@ -155,31 +151,73 @@ module.exports = {
|
|||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Death Event** - <t:${unixTime}>\n**${info.victim}** ${killMessage} a **${cod}.**${coord}`);
|
.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 await UpdatePlayer(client, victimStat);
|
|
||||||
|
if (!channel) return;
|
||||||
|
const webhook = await GetWebhook(this, 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
|
KillInAlarm(client, guild.serverID, info); // check if kill happened in a no kill zone
|
||||||
|
|
||||||
if (!client.exists(info.victim) || !client.exists(info.victimID) || !client.exists(info.killer) || !client.exists(info.killerID)) return stats;
|
if (!client.exists(info.victim) || !client.exists(info.victimID) || !client.exists(info.killer) || !client.exists(info.killerID)) return;
|
||||||
|
|
||||||
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
let victimStat = await client.dbo.collection("players").findOne({"playerID": info.victimID});
|
||||||
let killerStat = await client.dbo.collection("players").findOne({"playerID": info.killerID});
|
let killerStat = await client.dbo.collection("players").findOne({"playerID": info.killerID});
|
||||||
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, client.config.Nitrado.ServerID);
|
if (!client.exists(victimStat)) victimStat = getDefaultPlayer(info.victim, info.victimID, NitradoServerID);
|
||||||
if (!client.exists(killerStat)) killerStat = getDefaultPlayer(info.killer, info.killerID, client.config.Nitrado.ServerID);
|
if (!client.exists(killerStat)) killerStat = getDefaultPlayer(info.killer, info.killerID, NitradoServerID);
|
||||||
|
|
||||||
|
let weapon = info.weapon.includes("Engraved") ? info.weapon.split("Engraved ")[1] :
|
||||||
|
info.weapon.includes("Sawed-off") ? info.weapon.split("Sawed-off ")[1] :
|
||||||
|
info.weapon;
|
||||||
|
|
||||||
|
// Update killer stats
|
||||||
killerStat.kills++;
|
killerStat.kills++;
|
||||||
killerStat.killStreak++;
|
killerStat.killStreak++;
|
||||||
killerStat.bestKillStreak = killerStat.killStreak > killerStat.bestKillStreak ? killerStat.killStreak : killerStat.bestKillStreak;
|
killerStat.bestKillStreak = killerStat.killStreak > killerStat.bestKillStreak ? killerStat.killStreak : killerStat.bestKillStreak;
|
||||||
killerStat.longestKill = parseFloat(info.distance) > killerStat.longestKill ? parseFloat(info.distance).toFixed(1) : killerStat.longestKill;
|
killerStat.KDR = killerStat.kills / (killerStat.deaths == 0 ? 1 : killerStat.deaths); // prevent division by 0
|
||||||
|
killerStat.longestKill = info.distance > killerStat.longestKill ? info.distance : killerStat.longestKill;
|
||||||
|
killerStat.deathStreak = 0;
|
||||||
|
if (!client.exists(killerStat.weaponStats[weapon].kills)) killerStat.weaponStats[weapon].kills = 0;
|
||||||
|
killerStat.weaponStats[weapon].kills++;
|
||||||
|
|
||||||
|
// Update victim stats
|
||||||
victimStat.deaths++;
|
victimStat.deaths++;
|
||||||
victimStat.deathStreak++;
|
victimStat.deathStreak++;
|
||||||
victimStat.worstDeathStreak = victimStat.deathStreak > victimStat.worstDeathStreak ? victimStat.deathStreak : victimStat.worstDeathStreak;
|
victimStat.worstDeathStreak = victimStat.deathStreak > victimStat.worstDeathStreak ? victimStat.deathStreak : victimStat.worstDeathStreak;
|
||||||
killerStat.KDR = killerStat.kills / (killerStat.deaths == 0 ? 1 : killerStat.deaths); // prevent division by 0
|
|
||||||
victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0
|
victimStat.KDR = victimStat.kills / (victimStat.deaths == 0 ? 1 : victimStat.deaths); // prevent division by 0
|
||||||
victimStat.killStreak = 0;
|
victimStat.killStreak = 0;
|
||||||
victimStat.lastDeathDate = newDt;
|
victimStat.lastDeathDate = newDt;
|
||||||
killerStat.deathStreak = 0;
|
if (!client.exists(victimStat.weaponStats[weapon].deaths)) victimStat.weaponStats[weapon].death = 0;
|
||||||
|
victimStat.weaponStats[weapon].deaths++;
|
||||||
|
|
||||||
|
// Create defaults for non-existing ratings
|
||||||
|
if (!client.exists(killerStat.combatRating)) killerStat.combatRating = 800;
|
||||||
|
if (!client.exists(victimStat.combatRating)) victimStat.combatRating = 800;
|
||||||
|
if (!client.exists(killerStat.combatRatingHistory)) killerStat.combatRatingHistory = [800];
|
||||||
|
if (!client.exists(victimStat.combatRatingHistory)) victimStat.combatRatingHistory = [800];
|
||||||
|
if (!client.exists(killerStat.highestCombatRating)) killerStat.highestCombatRating = Math.max(...killerStat.combatRatingHistory);
|
||||||
|
if (!client.exists(victimStat.lowestCombatRating)) victimStat.lowestCombatRating = Math.min(...victimStat.combatRatingHistory);
|
||||||
|
|
||||||
|
// Calculate new ratings
|
||||||
|
let killerOldRating = killerStat.combatRating;
|
||||||
|
let victimOldRating = victimStat.combatRating;
|
||||||
|
killerStat.combatRating = calculateNewCombatRating(killerStat.combatRating, victimStat.combatRating, client.exists(info.bodyPart) && info.bodyPart.includes('Head') ? 1.25 : 1);
|
||||||
|
victimStat.combatRating = calculateNewCombatRating(victimStat.combatRating, killerStat.combatRating, 0);
|
||||||
|
|
||||||
|
// Update combat rating records
|
||||||
|
if (killerStat.combatRating > killerStat.highestCombatRating) killerStat.highestCombatRating = killerStat.combatRating;
|
||||||
|
if (victimStat.combatRating < victimStat.lowestCombatRating) victimStat.lowestCombatRating = victimStat.combatRating;
|
||||||
|
if (killerStat.combatRatingHistory.length >= 12) killerStat.combatRatingHistory = killerStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 12)
|
||||||
|
if (victimStat.combatRatingHistory.length >= 12) victimStat.combatRatingHistory = victimStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 12)
|
||||||
|
killerStat.combatRatingHistory.push(killerStat.combatRating);
|
||||||
|
victimStat.combatRatingHistory.push(victimStat.combatRating);
|
||||||
|
|
||||||
|
let kdiff = killerStat.combatRating - killerOldRating;
|
||||||
|
let vdiff = victimStat.combatRating - victimOldRating;
|
||||||
|
|
||||||
let receivedBounty = null;
|
let receivedBounty = null;
|
||||||
if (victimStat.bounties.length > 0 && killerStat.discordID != "") {
|
if (victimStat.bounties.length > 0 && killerStat.discordID != "") {
|
||||||
@@ -196,7 +234,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
banking = banking.user;
|
banking = banking.user;
|
||||||
|
|
||||||
if (!client.exists(banking.guilds[ guild.serverID])) {
|
if (!client.exists(banking.guilds[guild.serverID])) {
|
||||||
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, client, guild.startingBalance);
|
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, client, guild.startingBalance);
|
||||||
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
||||||
}
|
}
|
||||||
@@ -222,14 +260,30 @@ module.exports = {
|
|||||||
await UpdatePlayer(client, victimStat);
|
await UpdatePlayer(client, victimStat);
|
||||||
await UpdatePlayer(client, killerStat);
|
await UpdatePlayer(client, killerStat);
|
||||||
|
|
||||||
|
const header = `**Kill Event** - <t:${unixTime}>\n**${info.killer}** killed **${info.victim}**`;
|
||||||
|
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 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 killEvent = new EmbedBuilder()
|
let killEvent = new EmbedBuilder()
|
||||||
.setColor(client.config.Colors.Default)
|
.setColor(client.config.Colors.Default)
|
||||||
.setDescription(`**Kill Event** - <t:${unixTime}>\n**${info.killer}** killed **${info.victim}**\n> **__Kill Data__**\n> Weapon: \` ${info.weapon} \`\n> Distance: \` ${info.distance} \`\n> Body Part: \` ${info.bodyPart != undefined ? info.bodyPart.split('(')[0] : 'N/A'} \`\n> Damage: \` ${info.damage != undefined ? info.damage : 'N/A'} \`\n **Killer**\n${killerStat.KDR.toFixed(2)} K/D - ${killerStat.kills} Kill${(killerStat.kills == 0 || killerStat.kills > 1) ? 's':''} - Killstreak: ${killerStat.killStreak}\n**Victim**\n${victimStat.KDR.toFixed(2)} K/D - ${victimStat.deaths} Death${victimStat.deaths == 0 || victimStat.deaths>1?'s':''} - Deathstreak: ${victimStat.deathStreak}${coord}`);
|
.setDescription(`${header}${killData}${killerStatsView}${victimStatsView}${coord}`);
|
||||||
|
|
||||||
if (client.exists(channel)) await channel.send({ embeds: [killEvent] });
|
if (showWeapon) {
|
||||||
if (client.exists(receivedBounty) && client.exists(channel)) await channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
|
let weaponClass = weaponClassOf(weapon);
|
||||||
|
killEvent.setThumbnail(weapons[weaponClass][weapon])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const webhook = await GetWebhook(this, 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+95
-70
@@ -3,13 +3,13 @@ const { HandleAlarmsAndUAVs } = require('./AlarmsHandler');
|
|||||||
const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler');
|
const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler');
|
||||||
const { getDefaultPlayer } = require('../database/player');
|
const { getDefaultPlayer } = require('../database/player');
|
||||||
const { FetchServerSettings } = require('../util/NitradoAPI');
|
const { FetchServerSettings } = require('../util/NitradoAPI');
|
||||||
const { UpdatePlayer } = require('../database/player')
|
const { UpdatePlayer, insertPVPstats, createWeaponStats } = require('../database/player')
|
||||||
|
const { Missions } = require('../database/destinations');
|
||||||
let lastSendMessage;
|
const { GetWebhook, WebhookSend, WebhookMessageEdit } = require("../util/WebhookHandler");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
HandlePlayerLogs: async (client, GuildDB, line, combatLogTimer = 5) => {
|
HandlePlayerLogs: async (NitradoServerID, client, GuildDB, line, combatLogTimer = 5) => {
|
||||||
|
|
||||||
const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g;
|
const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g;
|
||||||
const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g;
|
const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g;
|
||||||
@@ -30,17 +30,18 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||||
const newDt = await client.getDateEST(info.time);
|
const newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastConnectionDate = newDt;
|
playerStat.lastConnectionDate = newDt;
|
||||||
playerStat.connected = true;
|
playerStat.connected = true;
|
||||||
|
if (!client.exists(playerStat.connections)) playerStat.connections = 0;
|
||||||
playerStat.connections++;
|
playerStat.connections++;
|
||||||
|
|
||||||
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
||||||
if (client.playerSessions.has(info.playerID)) {
|
if (client.playerSessions.get(NitradoServerID).has(info.playerID)) {
|
||||||
// Player is already in a session, update the session's end time.
|
// Player is already in a session, update the session's end time.
|
||||||
const session = client.playerSessions.get(info.playerID);
|
const session = client.playerSessions.get(NitradoServerID).get(info.playerID);
|
||||||
session.endTime = newDt; // Update end time.
|
session.endTime = newDt; // Update end time.
|
||||||
} else {
|
} else {
|
||||||
// Player is not in a session, create a new session.
|
// Player is not in a session, create a new session.
|
||||||
@@ -48,7 +49,7 @@ module.exports = {
|
|||||||
startTime: newDt,
|
startTime: newDt,
|
||||||
endTime: null, // Initialize end time as null.
|
endTime: null, // Initialize end time as null.
|
||||||
};
|
};
|
||||||
client.playerSessions.set(info.playerID, newSession);
|
client.playerSessions.get(NitradoServerID).set(info.playerID, newSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SendConnectionLogs(client, GuildDB, {
|
await SendConnectionLogs(client, GuildDB, {
|
||||||
@@ -58,7 +59,7 @@ module.exports = {
|
|||||||
lastConnectionDate: null,
|
lastConnectionDate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
return await UpdatePlayer(client, playerStat);
|
await UpdatePlayer(client, playerStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes(' disconnected')) {
|
if (line.includes(' disconnected')) {
|
||||||
@@ -74,7 +75,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||||
|
|
||||||
let oldUnixTime;
|
let oldUnixTime;
|
||||||
let sessionTimeSeconds;
|
let sessionTimeSeconds;
|
||||||
@@ -111,7 +112,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return await UpdatePlayer(client, playerStat);
|
await UpdatePlayer(client, playerStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes('pos=<') && !line.includes('hit by')) {
|
if (line.includes('pos=<') && !line.includes('hit by')) {
|
||||||
@@ -128,7 +129,7 @@ module.exports = {
|
|||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||||
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastPos = playerStat.pos;
|
playerStat.lastPos = playerStat.pos;
|
||||||
@@ -147,7 +148,7 @@ module.exports = {
|
|||||||
pos: info.pos,
|
pos: info.pos,
|
||||||
});
|
});
|
||||||
|
|
||||||
return await UpdatePlayer(client, playerStat)
|
await UpdatePlayer(client, playerStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes('hit by Player')) {
|
if (line.includes('hit by Player')) {
|
||||||
@@ -155,86 +156,110 @@ module.exports = {
|
|||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
const info = {
|
const info = {
|
||||||
time: data[1],
|
time: data[1],
|
||||||
player: data[2],
|
player: data[2],
|
||||||
playerID: data[3],
|
playerID: data[3],
|
||||||
attacker: data[6],
|
attacker: data[6],
|
||||||
attackerID: data[7]
|
attackerID: data[7],
|
||||||
|
bodyPart: data[9].split("(")[0],
|
||||||
|
weapon: data[12],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return;
|
if (!client.exists(info.player) || !client.exists(info.playerID) || !client.exists(info.attacker) || !client.exists(info.attackerID)) return;
|
||||||
|
|
||||||
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID});
|
||||||
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, client.config.Nitrado.ServerID);
|
let attackerStat = await client.dbo.collection("players").findOne({"playerID": info.attackerID});
|
||||||
|
if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID);
|
||||||
|
if (!client.exists(attackerStat)) attackerStat = getDefaultPlayer(info.attacker, info.attackerID, NitradoServerID);
|
||||||
|
|
||||||
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
playerStat.lastDamageDate = await client.getDateEST(info.time);
|
||||||
playerStat.lastHitBy = info.attacker;
|
playerStat.lastHitBy = info.attacker;
|
||||||
|
|
||||||
return await UpdatePlayer(client, playerStat);
|
if (!client.exists(playerStat.shotsLanded)) playerStat = insertPVPstats(playerStat);
|
||||||
|
if (!client.exists(attackerStat.shotsLanded)) attackerStat = insertPVPstats(attackerStat);
|
||||||
|
|
||||||
|
// Update in depth PVP stats if non Melee weapon
|
||||||
|
if (info.weapon.includes("Engraved")) info.weapon = info.weapon.split("Engraved ")[1];
|
||||||
|
if (info.weapon.includes("Sawed-off")) info.weapon = info.weapon.split("Sawed-off ")[1];
|
||||||
|
if (info.weapon in playerStat.weaponStats) {
|
||||||
|
playerStat.timesShot++;
|
||||||
|
playerStat.timesShotPerBodyPart[info.bodyPart]++;
|
||||||
|
if (!client.exists(playerStat.weaponStats[info.weapon])) playerStat = createWeaponStats(playerStat, info.weapon);
|
||||||
|
playerStat.weaponStats[info.weapon].timesShot++;
|
||||||
|
playerStat.weaponStats[info.weapon].timesShotPerBodyPart[info.bodyPart]++;
|
||||||
|
|
||||||
|
attackerStat.shotsLanded++;
|
||||||
|
attackerStat.shotsLandedPerBodyPart[info.bodyPart]++;
|
||||||
|
if (!client.exists(attackerStat.weaponStats[info.weapon])) attackerStat = createWeaponStats(attackerStat, info.weapon);
|
||||||
|
attackerStat.weaponStats[info.weapon].shotsLanded++;
|
||||||
|
attackerStat.weaponStats[info.weapon].shotsLandedPerBodyPart[info.bodyPart]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
await UpdatePlayer(client, playerStat);
|
||||||
|
await UpdatePlayer(client, attackerStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
||||||
HandleActivePlayersList: async (client, guild) => {
|
HandleActivePlayersList: async (nitrado_cred, client, guild) => {
|
||||||
client.activePlayersTick = 0; // reset hour tick
|
client.activePlayersTick = 0; // reset hour tick
|
||||||
|
|
||||||
const data = await FetchServerSettings(client, 'HandleActivePlayersList'); // Fetch server status
|
if (!client.exists(guild.activePlayersChannel)) return;
|
||||||
|
const channel = client.GetChannel(guild.activePlayersChannel);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
if (data && data !== 1) {
|
const data = await FetchServerSettings(nitrado_cred, client, 'HandleActivePlayersList'); // Fetch server status
|
||||||
let hostname = data.data.gameserver.settings.config.hostname;
|
const e = data && data !== 1; // Check if data exists
|
||||||
let map = data.data.gameserver.settings.config.mission.slice(12);
|
|
||||||
let status = data.data.gameserver.status;
|
|
||||||
let slots = data.data.gameserver.slots;
|
|
||||||
let playersOnline = data.data.gameserver.query.player_current;
|
|
||||||
|
|
||||||
let statusEmoji;
|
const hostname = e ? data.data.gameserver.settings.config.hostname : 'N/A';
|
||||||
let statusText;
|
const map = Missions[data.data.gameserver.settings.config.mission];
|
||||||
if (status === "started") {
|
const status = e ? data.data.gameserver.status : 'N/A';
|
||||||
statusEmoji = "🟢";
|
const slots = e ? data.data.gameserver.slots : 'N/A';
|
||||||
statusText = "Active";
|
const playersOnline = e ? data.data.gameserver.query.player_current : undefined;
|
||||||
} else if (status === "stopped") {
|
|
||||||
statusEmoji = "🔴";
|
|
||||||
statusText = "Stopped";
|
|
||||||
} else if (status === "restarting") {
|
|
||||||
statusEmoji = "↻";
|
|
||||||
statusText = "Restarting";
|
|
||||||
} else {
|
|
||||||
statusEmoji = "❓"; // Unknown status
|
|
||||||
statusText = "Unknown Status";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!client.exists(guild.activePlayersChannel)) return;
|
const Statuses = {
|
||||||
|
"started": {emoji: "🟢", text: "Active"},
|
||||||
|
"stopped": {emoji: "🔴", text: "Stopped"},
|
||||||
|
"restarting": {emoji: "↻", text: "Restarting"},
|
||||||
|
};
|
||||||
|
|
||||||
const channel = client.GetChannel(guild.activePlayersChannel);
|
const emojiStatus = Statuses[status].emoji || "❓";
|
||||||
let activePlayers = await client.dbo.collection("players").find({"connected": true}).toArray();
|
const textStatus = Statuses[status].text || "Unknown Status";
|
||||||
|
|
||||||
let des = ``;
|
let activePlayers = await client.dbo.collection("players").find({"nitradoServerID": nitrado_cred.ServerID}).toArray().filter(player => player.connected);
|
||||||
for (let i = 0; i < activePlayers.length; i++) {
|
|
||||||
des += `**- ${activePlayers[i].gamertag}**\n`;
|
|
||||||
}
|
|
||||||
const nodes = activePlayers.length === 0;
|
|
||||||
const PlayersEmbed = new EmbedBuilder()
|
|
||||||
.setColor(client.config.Colors.Default)
|
|
||||||
.setTitle(`Online List \` ${playersOnline === undefined ? activePlayers.length : playersOnline} \` Player${playersOnline !== 1 ? 's' : ''} Online`)
|
|
||||||
.addFields(
|
|
||||||
{ name: 'Server:', value: `\` ${hostname} \``, inline: false },
|
|
||||||
{ name: 'Map:', value: `\` ${map} \``, inline: true },
|
|
||||||
{ name: 'Status:', value: `\` ${statusEmoji} ${statusText} \``, inline: true },
|
|
||||||
{ name: 'Slots:', value: `\` ${slots} \``, inline: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const activePlayersEmbed = new EmbedBuilder()
|
let des = activePlayers.length > 0 ? `` : `**No Players Online**`;
|
||||||
.setColor(client.config.Colors.Default)
|
for (let i = 0; i < activePlayers.length; i++) {
|
||||||
.setTimestamp()
|
des += `**- ${activePlayers[i].gamertag}**\n`;
|
||||||
.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 nodes = activePlayers.length === 0;
|
||||||
|
const serverEmbed = new EmbedBuilder()
|
||||||
return channel.send({ embeds: [PlayersEmbed, activePlayersEmbed] }).then(sentMessage =>
|
.setColor(client.config.Colors.Default)
|
||||||
lastSendMessage = sentMessage
|
.setTitle(`Online List - \` ${playersOnline === undefined ? activePlayers.length : playersOnline} \` Player${playersOnline !== 1 ? 's' : ''} Online`)
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Server:', value: `\` ${hostname} \``, inline: false },
|
||||||
|
{ name: 'Map:', value: `\` ${map} \``, inline: true },
|
||||||
|
{ name: 'Status:', value: `\` ${emojiStatus} ${textStatus} \``, inline: true },
|
||||||
|
{ name: 'Slots:', value: `\` ${slots} \``, inline: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const activePlayersEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setTimestamp()
|
||||||
|
.setTitle(`Players Online:`)
|
||||||
|
.setDescription(des || (nodes ? "No Players Online :(" : ""));
|
||||||
|
|
||||||
|
const NAME = "DayZ.R Admin Logs";
|
||||||
|
const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel);
|
||||||
|
|
||||||
|
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] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+122
-97
@@ -8,20 +8,18 @@ const retryDelay = 5000; // 5 seconds
|
|||||||
|
|
||||||
// Private functions (only called locally)
|
// Private functions (only called locally)
|
||||||
|
|
||||||
const UploadNitradoFile = async (client, remoteDir, remoteFilename, localFileDir) => {
|
const UploadNitradoFile = async (nitrado_cred, client, remoteDir, remoteFilename, localFileDir) => {
|
||||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers/file_server/upload?` + new URLSearchParams({
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/upload?` + new URLSearchParams({
|
||||||
path: remoteDir,
|
path: remoteDir,
|
||||||
file: remoteFilename
|
file: remoteFilename
|
||||||
}), {
|
}), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": client.config.Nitrado.Auth
|
"Authorization": nitrado_cred.Auth
|
||||||
},
|
},
|
||||||
}).then(response =>
|
}).then(response => response.json());
|
||||||
response.json().then(data => data)
|
|
||||||
).then(res => res);
|
|
||||||
|
|
||||||
let contents = fs.readFileSync(localFileDir, 'utf8');
|
let contents = fs.readFileSync(localFileDir, 'utf8');
|
||||||
|
|
||||||
@@ -34,60 +32,24 @@ const UploadNitradoFile = async (client, remoteDir, remoteFilename, localFileDir
|
|||||||
body: contents,
|
body: contents,
|
||||||
})
|
})
|
||||||
if (!uploadRes.ok) {
|
if (!uploadRes.ok) {
|
||||||
const errorText = await uploadRes.text();
|
client.error(`Failed to upload file to Nitrado (${nitrado_cred.ServerID}): status: ${uploadRes.status}, message: ${res.statusText}: UploadNitradoFile`);
|
||||||
client.error(`Failed to upload file to Nitrado (${client.config.Nitrado.ServerID}): status: ${uploadRes.status}, message: ${errorText}: UploadNitradoFile`);
|
|
||||||
if (retries === 2) return 1; // Return error status on the second failed status code.
|
if (retries === 2) return 1; // Return error status on the second failed status code.
|
||||||
} else {
|
} else {
|
||||||
return uploadRes;
|
return uploadRes;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.error(`UploadNitradoFile: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
client.error(`UploadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`);
|
||||||
if (retries === maxRetries) throw new Error(`UploadNitradoFile: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`);
|
if (retries === maxRetries) {
|
||||||
|
client.error(`UploadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PostServerSettings = async (client, category, key, value) => {
|
const HandlePlayerBan = async (nitrado_cred, client, gamertag, ban) => {
|
||||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
const data = await module.exports.FetchServerSettings(nitrado_cred, client, 'HandlePlayerBan'); // Fetch server status
|
||||||
try {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("category", category);
|
|
||||||
formData.append("key", key);
|
|
||||||
formData.append("value", value);
|
|
||||||
formData.pipe(concat(data => {
|
|
||||||
async function postData() {
|
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers/settings`, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: 'include',
|
|
||||||
headers: {
|
|
||||||
...formData.getHeaders(),
|
|
||||||
"Authorization": client.config.Nitrado.Auth
|
|
||||||
},
|
|
||||||
body: data,
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
const errorText = await res.text();
|
|
||||||
client.error(`Failed to get post Nitrado server settings (${client.config.Nitrado.ServerID}): status: ${res.status}, message: ${errorText}: PostServerSettings`);
|
|
||||||
if (retries === 2) return 1; // Return error status on the second failed status code.
|
|
||||||
} else {
|
|
||||||
const data = await res.json();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
postData();
|
|
||||||
}));
|
|
||||||
return 0;
|
|
||||||
} catch (error) {
|
|
||||||
client.error(`PostServerSettings: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
|
||||||
if (retries === maxRetries) throw new Error(`PostServerSettings: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`);
|
|
||||||
}
|
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const HandlePlayerBan = async (client, gamertag, ban) => {
|
|
||||||
const data = await module.exports.FetchServerSettings(client, 'HandlePlayerBan'); // Fetch server status
|
|
||||||
|
|
||||||
if (data && data != 1) {
|
if (data && data != 1) {
|
||||||
let bans = data.data.gameserver.settings.general.bans;
|
let bans = data.data.gameserver.settings.general.bans;
|
||||||
@@ -97,26 +59,31 @@ const HandlePlayerBan = async (client, gamertag, ban) => {
|
|||||||
|
|
||||||
let category = 'general';
|
let category = 'general';
|
||||||
let key = 'bans';
|
let key = 'bans';
|
||||||
return await PostServerSettings(client, category, key, bans); // returns 1 (failed) or 0 (not failed)
|
return await module.exports.PostServerSettings(nitrado_cred, client, category, key, bans); // returns 1 (failed) or 0 (not failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetRemoteDir = async (client, dir="") => {
|
const GetRemoteDir = async (nitrado_cred, client, dir="") => {
|
||||||
const dirParam = client.exists(dir) ? `?dir=${dir}` : "";
|
const dirParam = client.exists(dir) ? `?dir=${dir}` : "";
|
||||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers/file_server/list${dirParam}`, {
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/list${dirParam}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": client.config.Nitrado.Auth
|
"Authorization": nitrado_cred.Auth
|
||||||
}
|
}
|
||||||
}).then(response =>
|
}).then(response =>
|
||||||
response.json().then(data => data)
|
response.json().then(data => data)
|
||||||
).then(res => res);
|
).then(res => res);
|
||||||
|
|
||||||
|
if (res.status === "error") return 1;
|
||||||
|
|
||||||
return res.data.entries;
|
return res.data.entries;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.error(`GetRemoteDir: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
client.error(`GetRemoteDir: Error connecting to server (${nitrado_cred.ServerID}): ${error}`);
|
||||||
if (retries == maxRetries) throw new Error(`GetRemoteDir: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`)
|
if (retries == maxRetries) {
|
||||||
|
client.error(`GetRemoteDir: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
}
|
}
|
||||||
@@ -126,12 +93,12 @@ const GetRemoteDir = async (client, dir="") => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
DownloadNitradoFile: async(client, filename, outputDir) => {
|
DownloadNitradoFile: async(nitrado_cred, client, filename, outputDir) => {
|
||||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers/file_server/download?file=${filename}`, {
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/download?file=${filename}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": client.config.Nitrado.Auth
|
"Authorization": nitrado_cred.Auth
|
||||||
}
|
}
|
||||||
}).then(response =>
|
}).then(response =>
|
||||||
response.json().then(data => data)
|
response.json().then(data => data)
|
||||||
@@ -139,16 +106,18 @@ module.exports = {
|
|||||||
|
|
||||||
const stream = fs.createWriteStream(outputDir);
|
const stream = fs.createWriteStream(outputDir);
|
||||||
if (!res.data || !res.data.token) {
|
if (!res.data || !res.data.token) {
|
||||||
const errorText = await res.text();
|
client.error(`Error downloading File "${filename}": message: ${res.message}: DownloadNitradoFile`);
|
||||||
client.error(`Error downloading File "${filename}": message: ${errorText}: DownloadNitradoFile`);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const { body } = await fetch(res.data.token.url);
|
const { body } = await fetch(res.data.token.url);
|
||||||
await finished(Readable.fromWeb(body).pipe(stream));
|
await finished(Readable.fromWeb(body).pipe(stream));
|
||||||
return 0;
|
return 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.error(`DownloadNitradoFile: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
client.error(`DownloadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`);
|
||||||
if (retries === maxRetries) throw new Error(`DownloadNitradoFile: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`);
|
if (retries === maxRetries) {
|
||||||
|
client.error(`DownloadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
}
|
}
|
||||||
@@ -160,92 +129,139 @@ module.exports = {
|
|||||||
rather than write two whole different functions for each.
|
rather than write two whole different functions for each.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BanPlayer: async (client, gamertag) => await HandlePlayerBan(client, gamertag, true),
|
BanPlayer: async (nitrado_cred, client, gamertag) => await HandlePlayerBan(nitrado_cred, client, gamertag, true),
|
||||||
UnbanPlayer: async (client, gamertag) => await HandlePlayerBan(client, gamertag, false),
|
UnbanPlayer: async (nitrado_cred, client, gamertag) => await HandlePlayerBan(nitrado_cred, client, gamertag, false),
|
||||||
|
|
||||||
RestartServer: async (client, restart_message, message) => {
|
RestartServer: async (nitrado_cred, client, restart_message, message) => {
|
||||||
const params = {
|
const params = {
|
||||||
restart_message: restart_message,
|
restart_message: restart_message,
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
// client.log('Restarting server...');
|
|
||||||
for (let retries = 0; retries < maxRetries; retries++) {
|
for (let retries = 0; retries < maxRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers/restart`, {
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/restart`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": client.config.Nitrado.Auth,
|
"Authorization": nitrado_cred.Auth,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(params)
|
body: JSON.stringify(params)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const errorText = await res.text();
|
client.error(`Failed to restart Nitrado server (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: RestartServer`);
|
||||||
client.error(`Failed to restart Nitrado server (${client.config.Nitrado.ServerID}): status: ${res.status}, message: ${errorText}: RestartServer`);
|
|
||||||
return 1; // Return error status on failed status code.
|
return 1; // Return error status on failed status code.
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.error(`RestartServer: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
client.error(`RestartServer: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`);
|
||||||
if (retries === maxRetries) throw new Error(`RestartServer: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`);
|
if (retries === maxRetries) {
|
||||||
|
client.error(`RestartServer: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
FetchServerSettings: async (client, fetcher) => {
|
FetchServerSettings: async (nitrado_cred, client, fetcher) => {
|
||||||
for (let retries = 0; retries <= maxRetries; retries++) {
|
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
// get current status
|
// get current status
|
||||||
const res = await fetch(`https://api.nitrado.net/services/${client.config.Nitrado.ServerID}/gameservers`, {
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": client.config.Nitrado.Auth
|
"Authorization": nitrado_cred.Auth
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const errorText = await res.text();
|
client.error(`Failed to get Nitrado server stats (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: ${fetcher} via FetchServerSettings`);
|
||||||
client.error(`Failed to get Nitrado server stats (${client.config.Nitrado.ServerID}): status: ${res.status}, message: ${errorText}: ${fetcher} via FetchServerSettings`);
|
|
||||||
if (retries === 2) return 1; // Return error status on the second failed status code.
|
if (retries === 2) return 1; // Return error status on the second failed status code.
|
||||||
} else {
|
} else {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.error(`${fetcher} via FetchServerSettings: Error connecting to server (${client.config.Nitrado.ServerID}): ${error.message}`);
|
client.error(`${fetcher} via FetchServerSettings: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`);
|
||||||
if (retries === maxRetries) throw new Error(`${fetcher} via FetchServerSettings: Error connecting to server (${client.config.Nitrado.ServerID}) after ${maxRetries} retries`);
|
if (retries === maxRetries) {
|
||||||
|
client.error(`${fetcher} via FetchServerSettings: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
CheckServerStatus: async (client) => {
|
PostServerSettings: async (nitrado_cred, client, category, key, value) => {
|
||||||
const data = await module.exports.FetchServerSettings(client, 'CheckServerStatus'); // Fetch server status
|
for (let retries = 0; retries <= maxRetries; retries++) {
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("category", category);
|
||||||
|
formData.append("key", key);
|
||||||
|
formData.append("value", value);
|
||||||
|
formData.pipe(concat(data => {
|
||||||
|
async function postData() {
|
||||||
|
const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/settings`, {
|
||||||
|
method: "POST",
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
...formData.getHeaders(),
|
||||||
|
"Authorization": nitrado_cred.Auth
|
||||||
|
},
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
client.error(`Failed to get post Nitrado server settings (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: PostServerSettings`);
|
||||||
|
if (retries === 2) return 1; // Return error status on the second failed status code.
|
||||||
|
} else {
|
||||||
|
const data = await res.json();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
postData();
|
||||||
|
}));
|
||||||
|
return 0;
|
||||||
|
} catch (error) {
|
||||||
|
client.error(`PostServerSettings: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`);
|
||||||
|
if (retries === maxRetries) {
|
||||||
|
client.error(`PostServerSettings: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
CheckServerStatus: async (nitrado_cred, client) => {
|
||||||
|
const data = await module.exports.FetchServerSettings(nitrado_cred, client, 'CheckServerStatus'); // Fetch server status
|
||||||
|
|
||||||
if (data && data != 1) {
|
if (data && data != 1) {
|
||||||
if (data && data.data.gameserver.status === 'stopped') {
|
if (data && data.data.gameserver.status === 'stopped') {
|
||||||
client.log(`Restart of Nitrado server ${client.config.Nitrado.ServerID} has been invoked by the bot, the periodic check showed status of "${data.data.gameserver.status}".`);
|
client.log(`Restart of Nitrado server ${nitrado_cred.ServerID} has been invoked by the bot, the periodic check showed status of "${data.data.gameserver.status}".`);
|
||||||
// Write optional "restart_message" to set in the Nitrado server logs and send a notice "message" to your server community.
|
// Write optional "restart_message" to set in the Nitrado server logs and send a notice "message" to your server community.
|
||||||
restart_message = 'Server being restarted by periodic bot check.';
|
restart_message = 'Server being restarted by periodic bot check.';
|
||||||
message = 'The server was restarted by periodic bot check!';
|
message = 'The server was restarted by periodic bot check!';
|
||||||
|
|
||||||
module.exports.RestartServer(client, restart_message, message);
|
module.exports.RestartServer(nitrado_cred, client, restart_message, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
DisableBaseDamage: async (client, preference) => {
|
DisableBaseDamage: async (nitrado_cred, client, preference) => {
|
||||||
const pref = preference ? '1' : '0';
|
const pref = preference ? '1' : '0';
|
||||||
const posted = await PostServerSettings(client, "config", "disableBaseDamage", pref);
|
const posted = await module.exports.PostServerSettings(nitrado_cred, client, "config", "disableBaseDamage", pref);
|
||||||
if (posted == 1) return 1;
|
if (posted == 1) return 1;
|
||||||
|
|
||||||
const basePath = await GetRemoteDir(client).then(dirs => dirs.filter(dir => dir.type == 'dir')[0].path)
|
const remoteDirs = await GetRemoteDir(nitrado_cred, client);
|
||||||
const missionPath = await GetRemoteDir(client, basePath).then(dirs => dirs[0].path)
|
if (remoteDirs == 1) return 1;
|
||||||
|
const basePath = remoteDirs.filter(dir => dir.type == 'dir')[0].path
|
||||||
|
const remoteDirsFromBase = await GetRemoteDir(nitrado_cred, client, basePath);
|
||||||
|
if (remoteDirsFromBase == 1) return 1;
|
||||||
|
const missionPath = remoteDirsFromBase[0].path;
|
||||||
const cfggameplayPath = `${missionPath}/cfggameplay.json`;
|
const cfggameplayPath = `${missionPath}/cfggameplay.json`;
|
||||||
|
|
||||||
const jsonDir = `./logs/cfggameplay.json`;
|
const jsonDir = `./logs/cfggameplay.json`;
|
||||||
await module.exports.DownloadNitradoFile(client, cfggameplayPath, jsonDir);
|
await module.exports.DownloadNitradoFile(nitrado_cred, client, cfggameplayPath, jsonDir);
|
||||||
|
|
||||||
let gameplay = JSON.parse(fs.readFileSync(jsonDir));
|
let gameplay = JSON.parse(fs.readFileSync(jsonDir));
|
||||||
gameplay.GeneralData.disableBaseDamage = preference;
|
gameplay.GeneralData.disableBaseDamage = preference;
|
||||||
@@ -253,23 +269,27 @@ module.exports = {
|
|||||||
// write JSON to file
|
// write JSON to file
|
||||||
fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2));
|
fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2));
|
||||||
|
|
||||||
const uploaded = await UploadNitradoFile(client, missionPath, 'cfggameplay.json', jsonDir);
|
const uploaded = await UploadNitradoFile(nitrado_cred, client, missionPath, 'cfggameplay.json', jsonDir);
|
||||||
if (uploaded == 1) return 1;
|
if (uploaded == 1) return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
DisableContainerDamage: async (client, preference) => {
|
DisableContainerDamage: async (nitrado_cred, client, preference) => {
|
||||||
const pref = preference ? '1' : '0';
|
const pref = preference ? '1' : '0';
|
||||||
const posted = await PostServerSettings(client, "config", "disableContainerDamage", pref);
|
const posted = await module.exports.PostServerSettings(nitrado_cred, client, "config", "disableContainerDamage", pref);
|
||||||
if (posted == 1) return 1;
|
if (posted == 1) return 1;
|
||||||
|
|
||||||
const basePath = await GetRemoteDir(client).then(dirs => dirs.filter(dir => dir.type == 'dir')[0].path)
|
const remoteDirs = await GetRemoteDir(nitrado_cred, client);
|
||||||
const missionPath = await GetRemoteDir(client, basePath).then(dirs => dirs[0].path)
|
if (remoteDirs == 1) return 1;
|
||||||
|
const basePath = remoteDirs.filter(dir => dir.type == 'dir')[0].path
|
||||||
|
const remoteDirsFromBase = await GetRemoteDir(nitrado_cred, client, basePath);
|
||||||
|
if (remoteDirsFromBase == 1) return 1;
|
||||||
|
const missionPath = remoteDirsFromBase[0].path;
|
||||||
const cfggameplayPath = `${missionPath}/cfggameplay.json`;
|
const cfggameplayPath = `${missionPath}/cfggameplay.json`;
|
||||||
|
|
||||||
const jsonDir = `./logs/cfggameplay.json`;
|
const jsonDir = `./logs/cfggameplay.json`;
|
||||||
await module.exports.DownloadNitradoFile(client, cfggameplayPath, jsonDir);
|
await module.exports.DownloadNitradoFile(nitrado_cred, client, cfggameplayPath, jsonDir);
|
||||||
|
|
||||||
let gameplay = JSON.parse(fs.readFileSync(jsonDir));
|
let gameplay = JSON.parse(fs.readFileSync(jsonDir));
|
||||||
gameplay.GeneralData.disableContainerDamage = preference;
|
gameplay.GeneralData.disableContainerDamage = preference;
|
||||||
@@ -277,9 +297,14 @@ module.exports = {
|
|||||||
// write JSON to file
|
// write JSON to file
|
||||||
fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2));
|
fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2));
|
||||||
|
|
||||||
const uploaded = await UploadNitradoFile(client, missionPath, 'cfggameplay.json', jsonDir);
|
const uploaded = await UploadNitradoFile(nitrado_cred, client, missionPath, 'cfggameplay.json', jsonDir);
|
||||||
if (uploaded == 1) return 1;
|
if (uploaded == 1) return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
NitradoCredentialStatus: {
|
||||||
|
FAILED: "FAILED",
|
||||||
|
OK: "OK",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ module.exports = {
|
|||||||
let distance = parseFloat(Math.sqrt(Math.pow(delta[0], 2) + Math.pow(delta[1], 2)).toFixed(0));
|
let distance = parseFloat(Math.sqrt(Math.pow(delta[0], 2) + Math.pow(delta[1], 2)).toFixed(0));
|
||||||
let thetat = Math.round(Math.atan2(delta[0], delta[1]) / Math.PI * 180);
|
let thetat = Math.round(Math.atan2(delta[0], delta[1]) / Math.PI * 180);
|
||||||
let theta = (thetat < 0) ? (360 + thetat) : thetat;
|
let theta = (thetat < 0) ? (360 + thetat) : thetat;
|
||||||
let compass = ["S", "SW", "W", "NW", "N", "N by NE", "NE", "E", "SE", "S"];
|
let compass = ["S", "SW", "W", "NW", "N", "NE", "E", "SE", "S"];
|
||||||
let dir = compass[Math.round(theta / 45)];
|
let dir = compass[Math.round(theta / 45)];
|
||||||
|
|
||||||
return {distance, theta, dir}
|
return {distance, theta, dir}
|
||||||
@@ -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