├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── events ├── guildCreate.js ├── ready.js ├── interactionCreate.js └── guildMemberAdd.js ├── .gitignore ├── util ├── CombatRatingHandler.js ├── CommandOptionTypes.js ├── Vector.js ├── Cryptic.js ├── Logger.js ├── WebhookHandler.js ├── RegisterSlashCommands.js ├── AdminLogsHandler.js ├── AlarmsHandler.js ├── LogsHandler.js └── NitradoAPI.js ├── index.js ├── .env.example ├── SECURITY.md ├── package.json ├── database ├── user.js ├── guild.js ├── player.js ├── armbands.js └── weapons.js ├── bot.js ├── commands ├── excluded.js ├── channels.js ├── location.js ├── armbands.js ├── factions.js ├── player-list.js ├── gamertag-unlink.js ├── lookup.js ├── purchase-uav.js ├── reset.js ├── collect-income.js ├── gamertag-link.js ├── purchase-emp.js ├── compare-rating.js ├── help.js ├── leaderboard.js ├── event.js ├── bank.js ├── weapon-stats.js ├── bounty.js └── claim.js ├── README.md ├── LICENSE ├── CONTRIBUTING.md └── config └── config.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: SowinskiBraeden 2 | -------------------------------------------------------------------------------- /events/guildCreate.js: -------------------------------------------------------------------------------- 1 | module.exports = (client, guild) => { 2 | require("../util/RegisterSlashCommands").RegisterGuildCommands(client, guild.id); 3 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node modules 2 | node_modules/* 3 | 4 | # Testing/dev related 5 | *_test.js 6 | dev-*.js 7 | commands/debug.js 8 | 9 | # Logs 10 | logs/* 11 | 12 | # env 13 | .env 14 | -------------------------------------------------------------------------------- /util/CombatRatingHandler.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | calculateNewCombatRating: (Ra, Rb, score) => { 3 | const Ea = 1 / (1 + Math.pow(10, ((Rb - Ra) / 400))); 4 | return Math.round(Ra + 32 * (score - Ea)); 5 | }, 6 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { ShardingManager } = require('discord.js'); 2 | const config = require('./config/config'); 3 | 4 | const manager = new ShardingManager('./bot.js', { token: config.Token }); 5 | 6 | manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`)); 7 | 8 | manager.spawn(); 9 | -------------------------------------------------------------------------------- /util/CommandOptionTypes.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | CommandOptionTypes: { 3 | SubCommand: 1, 4 | SubCommandGroup: 2, 5 | String: 3, 6 | Integer: 4, 7 | Boolean: 5, 8 | User: 6, 9 | Channel: 7, 10 | Role: 8, 11 | Mentionable: 9, 12 | Float: 10, // AKA Number in Discord's Documentation 13 | Attachment: 11, 14 | } 15 | }; -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # Discord Bot Token 2 | token='Your Discord Bot token' 3 | 4 | # MongoDB Information 5 | mongoURI='Your mongodb URI' 6 | dbo='Your mongodb database' 7 | 8 | # Encryption 9 | key='Secret Encryption Key' 10 | iv='Secret Initialization Vector' 11 | 12 | # Other Bot Configuration 13 | Dev=PROD. # or DEV. 14 | 15 | # Note: "PROD." downloads Nitrado logs every 5 minutes, "DEV." checks every 15 seconds. 16 | # Any other value for Dev will not allow the bot to run. 17 | -------------------------------------------------------------------------------- /events/ready.js: -------------------------------------------------------------------------------- 1 | module.exports = async (client) => { 2 | (client.Ready = true), 3 | client.user.setActivity({ 4 | type: client.config.Presence.type, 5 | name: client.config.Presence.name 6 | }); 7 | client.log(`Successfully Logged in as ${client.user.tag}`); 8 | client.log(`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`) 9 | client.RegisterSlashCommands(); 10 | setInterval(client.logsUpdateTimer, client.timer, client); 11 | }; 12 | -------------------------------------------------------------------------------- /util/Vector.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | calculateVector: (pos1, pos2) => { 3 | let delta = [Math.round(pos2[0] - pos1[0]), Math.round(pos2[1] - pos1[1])]; 4 | let distance = parseFloat(Math.sqrt(Math.pow(delta[0], 2) + Math.pow(delta[1], 2)).toFixed(0)); 5 | let thetat = Math.round(Math.atan2(delta[0], delta[1]) / Math.PI * 180); 6 | let theta = (thetat < 0) ? (360 + thetat) : thetat; 7 | let compass = ["S", "SW", "W", "NW", "N", "NE", "E", "SE", "S"]; 8 | let dir = compass[Math.round(theta / 45)]; 9 | 10 | return {distance, theta, dir} 11 | } 12 | } -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | ------- | ------------------ | 7 | | 13.x.x | :white_check_mark: | 8 | | 5.x.x | :x: | 9 | | < 5.0 | :x: | 10 | 11 | ## Reporting a Vulnerability 12 | 13 | Use this section to tell people how to report a vulnerability. 14 | 15 | 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 16 | if I have any questions or clarifications. 17 | 18 | Thank you for helping to keep our repository safe to use for the community! 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /events/interactionCreate.js: -------------------------------------------------------------------------------- 1 | const { InteractionType } = require('discord.js'); 2 | const { GetGuild } = require('../database/guild'); 3 | 4 | 5 | module.exports = async (client, interaction) => { 6 | if (interaction.type == InteractionType.ApplicationCommand) return; 7 | /* 8 | This file routes any menu, modal & button interactions 9 | from any command 10 | */ 11 | 12 | let GuildDB = await GetGuild(client, interaction.guildId); 13 | const interactionName = interaction.customId.split("-")[0]; 14 | let interactionHandler = client.interactionHandlers.get(interactionName); 15 | 16 | try { 17 | interactionHandler.run(client, interaction, GuildDB); 18 | } catch (err) { 19 | client.sendInternalError(interaction, err); 20 | } 21 | } -------------------------------------------------------------------------------- /util/Cryptic.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | 3 | module.exports = { 4 | encrypt: (data, EncryptionMethod, Key, EncryptionIV) => { 5 | const cipher = crypto.createCipheriv(EncryptionMethod, Key, EncryptionIV) 6 | return Buffer.from( 7 | cipher.update(data, 'utf8', 'hex') + cipher.final('hex') 8 | ).toString('base64') // Encrypts data and converts to hex and base64 9 | }, 10 | 11 | decrypt: (data, EncryptionMethod, Key, EncryptionIV) => { 12 | const buff = Buffer.from(data, 'base64') 13 | const decipher = crypto.createDecipheriv(EncryptionMethod, Key, EncryptionIV) 14 | return ( 15 | decipher.update(buff.toString('utf8'), 'hex', 'utf8') + 16 | decipher.final('utf8') 17 | ) // Decrypts data and converts to utf8 18 | } 19 | } -------------------------------------------------------------------------------- /events/guildMemberAdd.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const { GetGuild } = require('../database/guild'); 3 | 4 | module.exports = async (client, member) => { 5 | 6 | let GuildDB = await GetGuild(client, member.guild.id); 7 | if (!client.exists(GuildDB.welcomeChannel)) return; 8 | const channel = client.GetChannel(GuildDB.welcomeChannel); 9 | 10 | if (GuildDB.serverName == "") GuildDB.serverName = "our server!" 11 | 12 | let embed = new EmbedBuilder() 13 | .setColor(client.config.Colors.Default) 14 | .setDescription(`**Welcome** <@${member.user.id}> to **${GuildDB.serverName}**\nUse the command to link your Discord to your gamertag.`); 15 | 16 | channel.send({ content: `<@${member.user.id}>`, embeds: [embed] }); 17 | }; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dayzr-bot", 3 | "version": "13.3.25", 4 | "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", 5 | "main": "index.js", 6 | "nodemonConfig": { 7 | "ignore": [ 8 | "logs/*.log", 9 | "logs/*.json" 10 | ] 11 | }, 12 | "scripts": { 13 | "start": "node index.js", 14 | "dev": "node index.js", 15 | "debug": "nodemon index.js" 16 | }, 17 | "author": "Braeden Sowinski", 18 | "license": "MIT", 19 | "dependencies": { 20 | "@discordjs/rest": "^1.1.0", 21 | "colors": "^1.4.0", 22 | "concat-stream": "^2.0.0", 23 | "crypto": "^1.0.1", 24 | "discord-bitfield-calculator": "^1.0.0", 25 | "discord.js": "^14.8.0", 26 | "dotenv": "^16.0.3", 27 | "form-data": "^4.0.0", 28 | "mongodb": "^4.12.1", 29 | "winston": "^3.8.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Execute command '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /util/Logger.js: -------------------------------------------------------------------------------- 1 | const winston = require("winston"); 2 | const colors = require("colors"); 3 | 4 | class Logger { 5 | constructor(LoggingFile) { 6 | this.logger = winston.createLogger({ 7 | transports: [new winston.transports.File({ filename: LoggingFile })], 8 | }); 9 | } 10 | 11 | log(Text) { 12 | let d = new Date(); 13 | this.logger.log({ 14 | level: "info", 15 | message: 16 | `${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | Info: ` + Text}); 17 | console.log( 18 | colors.green( 19 | `${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}` 20 | ) + colors.yellow(" | Info: " + Text) 21 | ); 22 | } 23 | 24 | error(Text) { 25 | let d = new Date(); 26 | this.logger.log({ 27 | level: "error", 28 | message: 29 | `${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | Error: ` + Text}); 30 | console.log( 31 | colors.green( 32 | `${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}` 33 | ) + colors.yellow(" | Error: ") + colors.red(Text) 34 | ); 35 | } 36 | } 37 | 38 | module.exports = Logger; -------------------------------------------------------------------------------- /database/user.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | createUser: async (userID, initialGuildID, startingBalance, client) => { 3 | let User = { 4 | user: { 5 | userID: userID, 6 | guilds: {} 7 | } 8 | }; 9 | 10 | User.user.guilds[initialGuildID] = { 11 | balance: startingBalance, 12 | lastIncome: new Date('2000-01-01T00:00:00'), 13 | }; 14 | 15 | await client.dbo.collection("users").insertOne(User, (err, res) => { 16 | if (err) { 17 | client.error(`Failed to create user - ${err}`); 18 | return undefined; 19 | } 20 | }); 21 | 22 | return User; 23 | }, 24 | 25 | /* 26 | This function is to add a new guild specific user to an already existing 27 | user document 28 | or 29 | can be used to reset a data back to default 30 | */ 31 | addUser: async (guilds, newGuildID, userID, client, startingBalance) => { 32 | let updatedGuilds = guilds; 33 | updatedGuilds[newGuildID] = { 34 | balance: startingBalance, 35 | lastIncome: new Date('2000-01-01T00:00:00') 36 | } 37 | 38 | await client.dbo.collection("users").updateOne({"user.userID":userID}, {$set: {"user.guilds": updatedGuilds}}, (err, res) => { 39 | if (err) return false 40 | }) 41 | return true 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /bot.js: -------------------------------------------------------------------------------- 1 | const DayzR = require('./src/DayzRBot'); 2 | const config = require('./config/config'); 3 | const { GatewayIntentBits } = require('discord.js'); 4 | 5 | const path = require("path"); 6 | const fs = require('fs'); 7 | const { HandleActivePlayersList } = require('./util/LogsHandler'); 8 | 9 | // Log all uncaught exceptions before killing process. 10 | process.on('uncaughtException', async (error) => { 11 | console.trace(error); 12 | let d = new Date(); 13 | // Asynchronously write the error message to a log file using Promises 14 | await new Promise((resolve, reject) => { 15 | if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing 16 | fs.appendFile(path.join(__dirname, "./logs/Logs.log"), 17 | `{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => { 18 | if (logErr) { 19 | console.error('Error writing uncaughtException to log file:', logErr); 20 | reject(logErr); 21 | process.exit() 22 | } else { 23 | resolve(); 24 | } 25 | }); 26 | }); 27 | 28 | // Now gracefully close the program 29 | process.exit() 30 | }); 31 | 32 | let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config); 33 | client.build() 34 | -------------------------------------------------------------------------------- /commands/excluded.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | 3 | module.exports = { 4 | name: "excluded", 5 | debug: false, 6 | global: false, 7 | description: "View a list of excluded roles", 8 | usage: "", 9 | permissions: { 10 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 11 | member: [], 12 | }, 13 | options: [], 14 | SlashCommand: { 15 | /** 16 | * 17 | * @param {require("../structures/DayzRBot")} client 18 | * @param {import("discord.js").Message} message 19 | * @param {string[]} args 20 | * @param {*} param3 21 | */ 22 | run: async (client, interaction, args, { GuildDB }) => { 23 | if (GuildDB.excludedRoles.length == 0) { 24 | let noExcludes = new EmbedBuilder() 25 | .setColor(client.config.Colors.Default) 26 | .setTitle('Excluded Roles') 27 | .setDescription('> There have been no excluded roles'); 28 | 29 | return interaction.send({ embeds: [noExcludes] }); 30 | } 31 | 32 | let excluded = new EmbedBuilder() 33 | .setColor(client.config.Colors.Default) 34 | .setTitle('Excluded Roles') 35 | 36 | let des = '*These roles you cannot use to claim an armband.*'; 37 | for (let i = 0; i < GuildDB.excludedRoles.length; i++) { 38 | des += `\n> <@&${GuildDB.excludedRoles[i]}>`; 39 | } 40 | excluded.setDescription(des); 41 | 42 | return interaction.send({ embeds: [excluded] }); 43 | }, 44 | }, 45 | Interactions: {} 46 | } 47 | -------------------------------------------------------------------------------- /commands/channels.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | 3 | module.exports = { 4 | name: "channels", 5 | debug: false, 6 | global: false, 7 | description: "View a list of allowed channels", 8 | usage: "", 9 | permissions: { 10 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 11 | member: [], 12 | }, 13 | options: [], 14 | SlashCommand: { 15 | /** 16 | * 17 | * @param {require("../structures/DayzRBot")} client 18 | * @param {import("discord.js").Message} message 19 | * @param {string[]} args 20 | * @param {*} param3 21 | */ 22 | run: async (client, interaction, args, { GuildDB }) => { 23 | if (!GuildDB.customChannelStatus) { 24 | let noChannels = new EmbedBuilder() 25 | .setColor(client.config.Colors.Default) 26 | .setTitle('Channels') 27 | .setDescription('> There are no configured channels'); 28 | 29 | return interaction.send({ embeds: [noChannels] }); 30 | } 31 | 32 | let channels = new EmbedBuilder() 33 | .setColor(client.config.Colors.Default) 34 | .setTitle('Channels') 35 | 36 | let des = ''; 37 | for (let i = 0; i < GuildDB.allowedChannels.length; i++) { 38 | if (i == 0) des += `> <#${GuildDB.allowedChannels[i]}>`; 39 | else des += `\n> <#${GuildDB.allowedChannels[i]}>`; 40 | } 41 | channels.setDescription(des); 42 | 43 | return interaction.send({ embeds: [channels] }); 44 | }, 45 | }, 46 | Interactions: {} 47 | } 48 | -------------------------------------------------------------------------------- /util/WebhookHandler.js: -------------------------------------------------------------------------------- 1 | const { makeURLSearchParams } = require('@discordjs/rest'); 2 | const { REST } = require('@discordjs/rest'); 3 | const { Routes } = require('discord.js'); 4 | 5 | const createWebhook = async (client, channel_id, name, avatar) => { 6 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 7 | return await rest.post(Routes.channelWebhooks(channel_id), { 8 | body: { 9 | name: name, 10 | avatar: avatar 11 | } 12 | }); 13 | }; 14 | 15 | module.exports = { 16 | GetWebhook: async (client, webhookName, channel_id) => { 17 | // Get all webhooks from configured channel 18 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 19 | const webhooks = await rest.get(Routes.channelWebhooks(channel_id)); 20 | 21 | let webhook = null; 22 | if (webhooks.length == 0) { 23 | // If no webhook exists, create new webhook with given name for this channel 24 | webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData); 25 | } else { 26 | // Check existing webhooks for one with given name 27 | let exists = false; 28 | for (let i = 0; i < webhooks.length; i++) { 29 | if (webhooks[i].name == webhookName) { 30 | webhook = webhooks[i]; 31 | exists = true; 32 | break; 33 | } 34 | } 35 | 36 | if (!exists) webhook = createWebhook(client, channel_id, webhookName, client.config.AvatarData); 37 | } 38 | 39 | return webhook; 40 | }, 41 | 42 | WebhookSend: async (client, webhook, content) => { 43 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 44 | return await rest.post(Routes.webhook(webhook.id, webhook.token), { 45 | body: content, 46 | query: makeURLSearchParams({ wait: true }) 47 | }); 48 | }, 49 | 50 | WebhookMessageEdit: async (client, webhook, message_id, content) => { 51 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 52 | return rest.patch(Routes.webhookMessage(webhook.id, webhook.token, message_id), { 53 | body: content 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /util/RegisterSlashCommands.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | const { Routes } = require('discord.js'); 4 | const { REST } = require('@discordjs/rest'); 5 | 6 | /** 7 | * Register slash commands for a guild 8 | * @param {require("../structures/DayzRBot")} client 9 | */ 10 | module.exports = { 11 | // Register guild commands 12 | RegisterGuildCommands: async (client, guild) => { 13 | const commands = []; 14 | const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js')); 15 | 16 | // Place your client and guild ids here 17 | const clientId = client.application.id; 18 | const guildId = guild; 19 | 20 | for (const file of commandFiles) { 21 | const command = require(`../commands/${file}`); 22 | if (!command.global) commands.push(command); // don't include global commands 23 | } 24 | 25 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 26 | 27 | try { 28 | client.log(`[${guildId}] Started refreshing guild (/) commands.`); 29 | 30 | await rest.put( 31 | Routes.applicationGuildCommands(clientId, guildId), 32 | { body: commands }, 33 | ); 34 | 35 | client.log(`[${guildId}] Successfully reloaded guild (/) commands.`); 36 | } catch (error) { 37 | client.error(error); 38 | } 39 | }, 40 | 41 | // Register global commands 42 | RegisterGlobalCommands: async (client) => { 43 | const commands = []; 44 | const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js')); 45 | 46 | const clientId = client.application.id; 47 | 48 | for (const file of commandFiles) { 49 | const command = require(`../commands/${file}`); 50 | if (command.global) commands.push(command); 51 | } 52 | 53 | const rest = new REST({ version: '10' }).setToken(client.config.Token); 54 | 55 | try { 56 | client.log('[global] Started refreshing global (/) commands.'); 57 | 58 | await rest.put( 59 | Routes.applicationCommands(clientId), 60 | { body: commands }, 61 | ); 62 | 63 | client.log('[global] Successfully reloaded global (/) commands.'); 64 | } catch (error) { 65 | client.error(error); 66 | } 67 | } 68 | }; -------------------------------------------------------------------------------- /commands/location.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const { nearest } = require('../database/destinations'); 3 | 4 | module.exports = { 5 | name: "location", 6 | debug: false, 7 | global: false, 8 | description: "Find your last known location", 9 | usage: "", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | SlashCommand: { 15 | /** 16 | * 17 | * @param {require("../structures/DayzRBot")} client 18 | * @param {import("discord.js").Message} message 19 | * @param {string[]} args 20 | * @param {*} param3 21 | */ 22 | run: async (client, interaction, args, { GuildDB }) => { 23 | 24 | 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)) { 25 | const warnNitradoNotInitialized = new EmbedBuilder() 26 | .setColor(client.config.Colors.Yellow) 27 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 28 | 29 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 30 | } 31 | 32 | let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); 33 | 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) }); 34 | 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)}); 35 | 36 | console.log(true); 37 | 38 | let newDt = await client.getDateEST(playerStat.time); 39 | let unixTime = Math.floor(newDt.getTime()/1000); 40 | 41 | const destination = nearest(playerStat.pos, GuildDB.Nitrado.Mission); 42 | 43 | let lastLocation = new EmbedBuilder() 44 | .setColor(client.config.Colors.Default) 45 | .setDescription(`**Location - **\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}`) 46 | 47 | return interaction.send({ embeds: [lastLocation], flags: (1 << 6) }); 48 | }, 49 | }, 50 | } -------------------------------------------------------------------------------- /commands/armbands.js: -------------------------------------------------------------------------------- 1 | const { StringSelectMenuBuilder, EmbedBuilder, ActionRowBuilder } = require('discord.js'); 2 | const { Armbands } = require('../database/armbands.js'); 3 | 4 | module.exports = { 5 | name: "armbands", 6 | debug: false, 7 | global: false, 8 | description: "View a list of armbads and what their image", 9 | usage: "", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | options: [], 15 | SlashCommand: { 16 | /** 17 | * 18 | * @param {require("../structures/DayzRBot")} client 19 | * @param {import("discord.js").Message} message 20 | * @param {string[]} args 21 | * @param {*} param3 22 | */ 23 | run: async (client, interaction, args, { GuildDB }) => { 24 | if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) 25 | return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); 26 | 27 | let available = new StringSelectMenuBuilder() 28 | .setCustomId(`View-1-${interaction.member.user.id}`) 29 | .setPlaceholder('View an armband from list 1') 30 | 31 | let availableNext = new StringSelectMenuBuilder() 32 | .setCustomId(`View-2-${interaction.member.user.id}`) 33 | .setPlaceholder('View an armband from list 2') 34 | 35 | let tracker = 0; 36 | for (let i = 0; i < Armbands.length; i++) { 37 | tracker++; 38 | data = { 39 | label: Armbands[i].name, 40 | description: 'View this armband', 41 | value: Armbands[i].name, 42 | } 43 | 44 | if (GuildDB.usedArmbands.includes(Armbands[i].name)) data.label += ' - [ Claimed ]' 45 | 46 | if (tracker > 25) availableNext.addOptions(data); 47 | else available.addOptions(data); 48 | } 49 | 50 | let compList = [] 51 | 52 | let opt = new ActionRowBuilder().addComponents(available); 53 | compList.push(opt) 54 | let opt2 = undefined; 55 | if (tracker > 25) { 56 | opt2 = new ActionRowBuilder().addComponents(availableNext); 57 | compList.push(opt2); 58 | } 59 | 60 | return interaction.send({ components: compList, flags: (1 << 6) }); 61 | }, 62 | }, 63 | Interactions: { 64 | View: { 65 | run: async (client, interaction, GuildDB) => { 66 | let armbandURL; 67 | 68 | for (let i = 0; i < Armbands.length; i++) { 69 | if (Armbands[i].name == interaction.values[0]) { 70 | armbandURL = Armbands[i].url; 71 | break; 72 | } 73 | } 74 | 75 | let armbandTitle = `${interaction.values[0]}${GuildDB.usedArmbands.includes(interaction.values[0]) ? ' - [ Claimed ]' : ''}`; 76 | 77 | const success = new EmbedBuilder() 78 | .setColor(client.config.Colors.Default) 79 | .setTitle(armbandTitle) 80 | .setImage(armbandURL); 81 | 82 | return interaction.update({ embeds: [success], components: [] }); 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DayZ.R Bot 2 | 3 | A general purpose Discord Bot to handle DayZ Killfeed, stats, alarms and factions' armbands and more using Nitrado Log files. 4 | 5 | ***Explore the docs »*** 6 | * [Technologies](#built-with) 7 | * [About](#about) 8 | * [Support](#support) 9 | * [License](#license) 10 | * [Contributing](#contributing) 11 | * [Getting Started](#getting-started) 12 | * [Prerequisites](#prerequisites) 13 | * [Installation](#installation) 14 | * [Contact](#contact) 15 | 16 | ### Built With 17 | 18 | * [Node.js](https://nodejs.org/en) 19 | * [Discord.js](https://discord.js.org/#/) 20 | * [MongoDB](https://www.mongodb.com/) 21 | 22 | ## About The Project 23 | 24 | Originally just a simple project to have factions select their armbands, and track that in the Discord. With the increasing difficulty of other DayZ killfeed bots, I 25 | expanded this project to include the killfeed, alarms, banking, and much much more. 26 | 27 | ## Support 28 | [» Community Support](https://discord.gg/KVFJCvvFtK) 29 | 30 | ## License 31 | [» License](/LICENSE) 32 | 33 | ## Contributing 34 | [» Contributing](/CONTRIBUTING.md) 35 | 36 | ## Getting Started 37 | 38 | The bot requires minimal setup to get started. 39 | 40 | ### Prerequisites 41 | 42 | 1. [Create your Discord Bot and get the private token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) for later configuration. Invite this bot to your desired discord server. 43 | 44 | 2. You'll need some important private information from your Nitrado account for later configuration. 45 | i. Your Nitrado user ID 46 | ii. Your DayZ Nitrado server ID 47 | iii. Create and Copy your Nitrado authentication token. 48 | 49 | 3. You'll need to setup an instance of MongoDB. You can use the cloud platform, MongoDB Atlas, or create your own instance locally. 50 | i. [Create your MongoDB Altas instance.](https://www.mongodb.com/docs/manual/tutorial/getting-started/) 51 | ii. [Create your local MongoDB server instance.](https://www.mongodb.com/docs/manual/administration/install-community/) 52 | 53 | After this, you'll need to get your MongoURI from your database instance, as well as your database name for later configuration. 54 | 55 | ### Installation 56 | 57 | 1. Clone the repo 58 | ``` 59 | $ git clone https://github.com/SowinskiBraeden/dayz-reforger.git 60 | $ cd dayz-reforger 61 | ``` 62 | 2. Rename `.env.example` to `.env` 63 | 3. Enter desired values into `.env` 64 | ``` 65 | # Discord Bot Token 66 | token='Your Discord Bot token' 67 | 68 | # MongoDB Information 69 | mongoURI='Your mongodb URI' 70 | dbo='Your mongodb database' 71 | 72 | # Encryption 73 | key='Secret Encryption Key', 74 | iv='Secret Initialization Vector', 75 | 76 | # Other Bot Configuration 77 | Dev=PROD. # or DEV. 78 | ``` 79 | 80 | ## Contact 81 | 82 | Braeden Sowinski - [@BraedenSowinski](https://twitter.com/BraedenSowinski) - braeden@sowinski.dev - @mcdazzzled on Discord 83 | 84 | Project Link: [https://github.com/SowinskiBraeden/dayz-reforger](https://github.com/SowinskiBraeden/dayz-reforger) 85 | -------------------------------------------------------------------------------- /commands/factions.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { Armbands } = require('../database/armbands.js'); 4 | 5 | module.exports = { 6 | name: "factions", 7 | debug: false, 8 | global: false, 9 | description: "View the armband of a faction", 10 | usage: "[role]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [{ 16 | name: "faction_role", 17 | description: "View a specific faction's armband by role", 18 | value: "faction_role", 19 | type: CommandOptions.Role, 20 | required: false, 21 | }], 22 | SlashCommand: { 23 | /** 24 | * 25 | * @param {require("../structures/DayzRBot")} client 26 | * @param {import("discord.js").Message} message 27 | * @param {string[]} args 28 | * @param {*} param3 29 | */ 30 | run: async (client, interaction, args, { GuildDB }) => { 31 | if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) 32 | return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); 33 | 34 | // Return list of factions and their armband. 35 | if (!args) { 36 | 37 | let factions = new EmbedBuilder() 38 | .setColor(client.config.Colors.Default) 39 | .setTitle('Factions & Armbands') 40 | 41 | let description = ''; 42 | 43 | if (GuildDB.usedArmbands.length == 0) { 44 | description = '> There are no factions that have claimed armbands.'; 45 | } else { 46 | for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) { 47 | if (description == "") description += `> <@&${factionID}> - ${data.armband}`; 48 | else description += `\n> <@&${factionID}> - *${data.armband}*`; 49 | } 50 | } 51 | 52 | factions.setDescription(description); 53 | 54 | return interaction.send({ embeds: [factions] }); 55 | } 56 | 57 | // Else return specific faction and their armband. 58 | if (!GuildDB.factionArmbands[args[0].value]) { 59 | return interaction.send({ 60 | embeds: [ 61 | new EmbedBuilder() 62 | .setColor(client.config.Colors.Yellow) 63 | .setDescription(`**Notice:**\n> The faction <@&${args[0].value}> has not claimed an armband.`) 64 | ], 65 | flags: (1 << 6) 66 | }); 67 | } 68 | 69 | let armbandURL; 70 | 71 | for (let i = 0; i < Armbands.length; i++) { 72 | if (Armbands[i].name == GuildDB.factionArmbands[args[0].value].armband) { 73 | armbandURL = Armbands[i].url; 74 | break; 75 | } 76 | } 77 | 78 | const faction = new EmbedBuilder() 79 | .setColor(client.config.Colors.Default) 80 | .setDescription(`> Faction <@&${GuildDB.factionArmbands[args[0].value].faction}> - ***${GuildDB.factionArmbands[args[0].value].armband}***`) 81 | .setImage(armbandURL); 82 | 83 | return interaction.send({ embeds: [faction] }); 84 | }, 85 | }, 86 | Interactions: {} 87 | } 88 | -------------------------------------------------------------------------------- /util/AdminLogsHandler.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const { nearest } = require('../database/destinations'); 3 | const { GetWebhook, WebhookSend } = require("../util/WebhookHandler"); 4 | 5 | module.exports = { 6 | 7 | SendConnectionLogs: async (client, guild, data) => { 8 | if (!client.exists(guild.connectionLogsChannel)) return; 9 | const channel = client.GetChannel(guild.connectionLogsChannel); 10 | if (!channel) return; 11 | 12 | let newDt = await client.getDateEST(data.time); 13 | let unixTime = Math.floor(newDt.getTime() / 1000); 14 | 15 | let connectionLog = new EmbedBuilder() 16 | .setColor(data.connected ? client.config.Colors.Green : client.config.Colors.Red) 17 | .setDescription(`**${data.connected ? 'Connect' : 'Disconnect'} Event - \n${data.player} ${data.connected ? 'Connected' : 'Disconnected'}**`); 18 | 19 | const NAME = "DayZ.R Admin Logs"; 20 | const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel); 21 | 22 | if (!data.connected) { 23 | if (data.lastConnectionDate != null) { 24 | let oldUnixTime = Math.floor(data.lastConnectionDate.getTime() / 1000); 25 | let sessionTime = client.secondsToDhms(unixTime - oldUnixTime); 26 | connectionLog.addFields({ name: '**Session Time**', value: `**${sessionTime}**`, inline: false }); 27 | } else connectionLog.addFields({ name: '**Session Time**', value: `**Unknown**`, inline: false }); 28 | } 29 | 30 | // if (client.exists(channel)) await channel.send({ embeds: [connectionLog] }); 31 | await WebhookSend(client, webhook, {embeds: [connectionLog]}); 32 | }, 33 | 34 | DetectCombatLog: async (client, guild, data) => { 35 | if (!client.exists(data.lastDamageDate)) return; 36 | if (!client.exists(guild.connectionLogsChannel)) return; 37 | const channel = client.GetChannel(guild.connectionLogsChannel); 38 | if (!channel) return; // Ensure channel exists 39 | 40 | const newDt = await client.getDateEST(data.time); 41 | const diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000); 42 | 43 | // If diff is greater than configured time in minutes, not a combat log 44 | // or if death after last combat 45 | if (diffSeconds > (data.combatLogTimer * 60)) return; 46 | if (data.lastDamageDate <= data.lastDeathDate) return; 47 | 48 | // If lastHitBy (attacker) died after shooting this player 49 | // then it does not count as combat logging, (the combat ended due to death) 50 | let attacker = await client.dbo.collection("players").findOne({"gamertag": data.lastHitBy}); 51 | if (attacker.lastDeathDate > data.lastDamageDate) return; 52 | 53 | let unixTime = Math.floor(newDt.getTime() / 1000); 54 | const destination = nearest(data.pos, guild.Nitrado.Mission); 55 | 56 | let combatLog = new EmbedBuilder() 57 | .setColor(client.config.Colors.Red) 58 | .setDescription(`**NOTICE:**\n**${data.player}** has combat logged at 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}`); 59 | 60 | const NAME = "DayZ.R Admin Logs"; 61 | const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel); 62 | 63 | let content = { embeds: [combatLog] }; 64 | if (client.exists(guild.adminRole)) content.content = `<@&${guild.adminRole}>`; 65 | WebhookSend(client, webhook, content); 66 | // return channel.send({ embeds: [combatLog] }); 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /commands/player-list.js: -------------------------------------------------------------------------------- 1 | const { FetchServerSettings } = require('../util/NitradoAPI'); 2 | const { Missions } = require('../database/destinations'); 3 | const { EmbedBuilder } = require('discord.js'); 4 | 5 | module.exports = { 6 | name: "player-list", 7 | debug: false, 8 | global: false, 9 | description: "Get current online players", 10 | usage: "", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [], 16 | SlashCommand: { 17 | /** 18 | * 19 | * @param {require("../structures/DayzRBot")} client 20 | * @param {import("discord.js").Message} message 21 | * @param {string[]} args 22 | * @param {*} param3 23 | */ 24 | run: async (client, interaction, args, { GuildDB }, start) => { 25 | 26 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 27 | const warnNitradoNotInitialized = new EmbedBuilder() 28 | .setColor(client.config.Colors.Yellow) 29 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 30 | 31 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 32 | } 33 | 34 | await interaction.deferReply(); 35 | 36 | const data = await FetchServerSettings(GuildDB.Nitrado, client, 'commands/player-list.js'); // Fetch server status 37 | const e = data && data !== 1; // Check if data exists 38 | 39 | const hostname = e ? data.data.gameserver.settings.config.hostname : 'N/A'; 40 | const map = e ? Missions[data.data.gameserver.settings.config.mission] : 'N/A'; 41 | const status = e ? data.data.gameserver.status : 'N/A'; 42 | const slots = e ? data.data.gameserver.slots : 'N/A'; 43 | const playersOnline = e ? data.data.gameserver.query.player_current : 'N/A'; 44 | 45 | const Statuses = { 46 | "started": {emoji: "🟢", text: "Active"}, 47 | "stopped": {emoji: "🔴", text: "Stopped"}, 48 | "restarting": {emoji: "↻", text: "Restarting"}, 49 | }; 50 | 51 | const emojiStatus = e ? Statuses[status].emoji : "❓"; 52 | const textStatus = e ? Statuses[status].text : "Unknown Status"; 53 | 54 | let activePlayers = await client.dbo.collection("players").find({"connected": true}).toArray(); 55 | 56 | let des = activePlayers.length > 0 ? `` : `**No Players Online**`; 57 | for (let i = 0; i < activePlayers.length; i++) { 58 | des += `**- ${activePlayers[i].gamertag}**\n`; 59 | } 60 | 61 | const nodes = activePlayers.length === 0; 62 | const serverEmbed = new EmbedBuilder() 63 | .setColor(client.config.Colors.Default) 64 | .setTitle(`Online List - \` ${playersOnline === undefined ? activePlayers.length : playersOnline} \` Player${playersOnline !== 1 ? 's' : ''} Online`) 65 | .addFields( 66 | { name: 'Server:', value: `\` ${hostname} \``, inline: false }, 67 | { name: 'Map:', value: `\` ${map} \``, inline: true }, 68 | { name: 'Status:', value: `\` ${emojiStatus} ${textStatus} \``, inline: true }, 69 | { name: 'Slots:', value: `\` ${slots} \``, inline: true } 70 | ); 71 | 72 | const activePlayersEmbed = new EmbedBuilder() 73 | .setColor(client.config.Colors.Default) 74 | .setTimestamp() 75 | .setTitle(`Players Online:`) 76 | .setDescription(des || (nodes ? "No Players Online :(" : "")); 77 | 78 | return interaction.editReply({ embeds: [serverEmbed, activePlayersEmbed] }); 79 | }, 80 | }, 81 | } -------------------------------------------------------------------------------- /commands/gamertag-unlink.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js'); 2 | const { UpdatePlayer } = require('../database/player'); 3 | 4 | module.exports = { 5 | name: "gamertag-unlink", 6 | debug: false, 7 | global: false, 8 | description: "Disconnect DayZ stats from your Discord", 9 | usage: "", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | SlashCommand: { 15 | /** 16 | * 17 | * @param {require("../structures/DayzRBot")} client 18 | * @param {import("discord.js").Message} message 19 | * @param {string[]} args 20 | * @param {*} param3 21 | */ 22 | run: async (client, interaction, args, { GuildDB }) => { 23 | 24 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 25 | const warnNitradoNotInitialized = new EmbedBuilder() 26 | .setColor(client.config.Colors.Yellow) 27 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 28 | 29 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 30 | } 31 | 32 | let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); 33 | 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.`)] }); 34 | 35 | const warnGTOverwrite = new EmbedBuilder() 36 | .setColor(client.config.Colors.Yellow) 37 | .setDescription(`**Notice:**\n> Are you sure you want to unlink your gamertag? This will limit some automatic features.`); 38 | 39 | const opt = new ActionRowBuilder() 40 | .addComponents( 41 | new ButtonBuilder() 42 | .setCustomId(`UnlinkGamertag-yes-${interaction.member.user.id}`) 43 | .setLabel("Yes") 44 | .setStyle(ButtonStyle.Success), 45 | new ButtonBuilder() 46 | .setCustomId(`UnlinkGamertag-no-${interaction.member.user.id}`) 47 | .setLabel("No") 48 | .setStyle(ButtonStyle.Secondary) 49 | ) 50 | 51 | return interaction.send({ embeds: [warnGTOverwrite], components: [opt] }); 52 | }, 53 | }, 54 | 55 | Interactions: { 56 | 57 | UnlinkGamertag: { 58 | run: async(client, interaction, GuildDB) => { 59 | if (!interaction.customId.endsWith(interaction.member.user.id)) 60 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 61 | 62 | if (interaction.customId.split('-')[1]=='yes') { 63 | let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); 64 | 65 | playerStat.discordID = ""; 66 | 67 | await UpdatePlayer(client, playerStat, interaction); 68 | 69 | let connectedEmbed = new EmbedBuilder() 70 | .setColor(client.config.Colors.Default) 71 | .setDescription(`Successfully unlinked \` ${playerStat.gamertag} \` as your gamertag.`); 72 | 73 | return interaction.update({ embeds: [connectedEmbed], components: [] }); 74 | 75 | } else { 76 | const cancel = new EmbedBuilder() 77 | .setColor(client.config.Colors.Default) 78 | .setDescription('**Canceled**\n> The gamertag unlink will not processed.'); 79 | 80 | return interaction.update({ embeds: [cancel], components: [] }); 81 | } 82 | } 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /commands/lookup.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | 4 | module.exports = { 5 | name: "lookup", 6 | debug: false, 7 | global: false, 8 | description: "Search for a user's Discord or Gamertag", 9 | usage: "[option] [parameter]", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | options: [{ 15 | name: "discord", 16 | description: "Find a Discord user from a Gamertag", 17 | value: "discord", 18 | type: CommandOptions.SubCommand, 19 | options: [{ 20 | name: "gamertag", 21 | description: "Gamertag of player", 22 | value: "gamertag", 23 | type: CommandOptions.String, 24 | required: true, 25 | }] 26 | }, { 27 | name: "gamertag", 28 | description: "Find a Gamertag from a Discord user", 29 | value: "gamertag", 30 | type: CommandOptions.SubCommand, 31 | options: [{ 32 | name: "user", 33 | description: "Discord User", 34 | value: "user", 35 | type: CommandOptions.User, 36 | required: true, 37 | }] 38 | }], 39 | SlashCommand: { 40 | /** 41 | * 42 | * @param {require("../structures/DayzRBot")} client 43 | * @param {import("discord.js").Message} message 44 | * @param {string[]} args 45 | * @param {*} param3 46 | */ 47 | run: async (client, interaction, args, { GuildDB }) => { 48 | 49 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 50 | const warnNitradoNotInitialized = new EmbedBuilder() 51 | .setColor(client.config.Colors.Yellow) 52 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 53 | 54 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 55 | } 56 | 57 | if (args[0].name == 'discord') { 58 | 59 | let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value}); 60 | if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].options[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 \`.`)] }); 61 | 62 | if (client.exists(playerStat.discordID)) { 63 | const found = new EmbedBuilder() 64 | .setColor(client.config.Colors.Yellow) 65 | .setDescription(`**Record Found**\n> The gamertag \` ${playerStat.gamertag} \` is currently linked to <@${playerStat.discordID}>.`) 66 | 67 | return interaction.send({ embeds: [found] }); 68 | } 69 | 70 | let notFound = new EmbedBuilder() 71 | .setColor(client.config.Colors.Default) 72 | .setDescription(`**Record Not Found**\n The gamertag \` ${playerStat.gamertag} \` currently has no linked Discord account.`); 73 | 74 | return interaction.send({ embeds: [notFound] }) 75 | 76 | } else if (args[0].name == 'gamertag') { 77 | 78 | let playerStat = await client.dbo.collection("players").findOne({"discordID": args[0].options[0].value}); 79 | if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** The user <@${args[0].options[0].value}> has not linked a gamertag.`)] }); 80 | 81 | const found = new EmbedBuilder() 82 | .setColor(client.config.Colors.Yellow) 83 | .setDescription(`**Record Found**\n> The user <@${playerStat.discordID}> has linked the gamertag \` ${playerStat.gamertag} \`.`) 84 | 85 | return interaction.send({ embeds: [found] }); 86 | 87 | } 88 | }, 89 | }, 90 | } -------------------------------------------------------------------------------- /database/guild.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | GetGuild: async (client, GuildId) => { 3 | let guild = undefined; 4 | if (client.databaseConnected) guild = await client.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild); 5 | 6 | // If guild not found, generate guild default 7 | if (!guild) { 8 | guild = {} 9 | guild.server = module.exports.getDefaultSettings(GuildId); 10 | guild.Nitrado = undefined; 11 | if (client.databaseConnected) { 12 | client.dbo.collection("guilds").insertOne(guild, (err, res) => { 13 | if (err) client.error(`GetGuild Insert Error: ${err}`); 14 | }); 15 | } 16 | } 17 | 18 | return { 19 | serverID: GuildId, 20 | Nitrado: guild.Nitrado, 21 | lastLog: guild.server.lastLog, 22 | serverName: guild.server.serverName, 23 | autoRestart: guild.server.autoRestart, 24 | showKillfeedCoords: guild.server.showKillfeedCoords, 25 | showKillfeedWeapon: guild.server.showKillfeedWeapon, 26 | purchaseUAV: guild.server.purchaseUAV, 27 | purchaseEMP: guild.server.purchaseEMP, 28 | allowedChannels: guild.server.allowedChannels, 29 | customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, 30 | hasBotAdmin: guild.server.botAdminRoles.length > 0 ? true : false, 31 | 32 | killfeedChannel: guild.server.killfeedChannel, 33 | connectionLogsChannel: guild.server.connectionLogsChannel, 34 | activePlayersChannel: guild.server.activePlayersChannel, 35 | welcomeChannel: guild.server.welcomeChannel, 36 | 37 | factionArmbands: guild.server.factionArmbands, 38 | usedArmbands: guild.server.usedArmbands, 39 | excludedRoles: guild.server.excludedRoles, 40 | hasExcludedRoles: guild.server.excludedRoles.length > 0 ? true : false, 41 | botAdminRoles: guild.server.botAdminRoles, 42 | 43 | alarms: guild.server.alarms, 44 | events: guild.server.events, 45 | uavs: guild.server.uavs, 46 | 47 | incomeRoles: guild.server.incomeRoles, 48 | incomeLimiter: guild.server.incomeLimiter, 49 | 50 | startingBalance: guild.server.startingBalance, 51 | uavPrice: guild.server.uavPrice, 52 | empPrice: guild.server.empPrice, 53 | 54 | linkedGamertagRole: guild.server.linkedGamertagRole, 55 | memberRole: guild.server.memberRole, 56 | adminRole: guild.server.adminRole, 57 | 58 | combatLogTimer: guild.server.combatLogTimer, 59 | }; 60 | }, 61 | 62 | getDefaultSettings(GuildId) { 63 | return { 64 | serverID: GuildId, 65 | lastLog: null, 66 | serverName: "our server!", 67 | autoRestart: 0, 68 | showKillfeedCoords: 0, 69 | showKillfeedWeapon: 0, 70 | purchaseUAV: 1, // Allow/Disallow purchase of UAVs 71 | purchaseEMP: 1, // Allow/Disallow purchase of EMPs 72 | allowedChannels: [], 73 | 74 | killfeedChannel: "", 75 | connectionLogsChannel: "", 76 | activePlayersChannel: "", 77 | welcomeChannel: "", 78 | 79 | factionArmbands: {}, 80 | usedArmbands: [], 81 | excludedRoles: [], 82 | botAdminRoles: [], 83 | 84 | alarms: [], 85 | events: [], 86 | uavs: [], 87 | 88 | incomeRoles: [], 89 | incomeLimiter: 168, // # of hours in 7 days 90 | 91 | startingBalance: 500, 92 | uavPrice: 50000, 93 | empPrice: 500000, 94 | 95 | linkedGamertagRole: "", 96 | memberRole: "", 97 | adminRole: "", 98 | 99 | combatLogTimer: 5, // minutes 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /database/player.js: -------------------------------------------------------------------------------- 1 | const { weapons } = require('./weapons'); 2 | 3 | // Creates a copy of an object to prevent mutation of parent (i.e BodyParts, createWeaponsObject) 4 | const copy = (obj) => JSON.parse(JSON.stringify(obj)); 5 | 6 | const BodyParts = { 7 | Head: 0, 8 | Torso: 0, 9 | RightArm: 0, 10 | LeftArm: 0, 11 | RightLeg: 0, 12 | LeftLeg: 0, 13 | }; 14 | 15 | const createWeaponsObject = (value) => { 16 | const defaultWeapons = {}; 17 | for (const [_, weaponNames] of Object.entries(weapons)) { 18 | for (const [name, _] of Object.entries(weaponNames)) { 19 | defaultWeapons[name] = value; 20 | } 21 | } 22 | return copy(defaultWeapons); 23 | }; 24 | 25 | module.exports = { 26 | UpdatePlayer: async (client, player, interaction=null) => { 27 | /* Wrapping this function in a promise solves some bugs */ 28 | return new Promise(resolve => { 29 | client.dbo.collection("players").updateOne( 30 | { "playerID": player.playerID }, 31 | { $set: {...player} }, 32 | { upsert: true }, // Create player stat document if it does not exist 33 | (err, _) => { 34 | if (err) { 35 | if (interaction == null) return client.error(`UpdatePlayer Error: ${err}`); 36 | else return client.sendInternalError(interaction, `UpdatePlayer Error: ${err}`); 37 | } else resolve(); 38 | } 39 | ); 40 | }); 41 | }, 42 | 43 | getDefaultPlayer(gamertag, playerId, nitradoServerId) { 44 | return { 45 | // Identifiers 46 | gamertag: gamertag, 47 | playerID: playerId, 48 | discordID: "", 49 | nitradoServerID: nitradoServerId, 50 | 51 | // General PVP Stats 52 | KDR: 0.00, 53 | kills: 0, 54 | deaths: 0, 55 | killStreak: 0, 56 | bestKillStreak: 0, 57 | longestKill: 0, 58 | deathStreak: 0, 59 | worstDeathStreak: 0, 60 | 61 | // In depth PVP Stats 62 | shotsLanded: 0, 63 | timesShot: 0, 64 | shotsLandedPerBodyPart: copy(BodyParts), 65 | timesShotPerBodyPart: copy(BodyParts), 66 | weaponStats: createWeaponsObject({ 67 | kills: 0, 68 | deaths: 0, 69 | shotsLanded: 0, 70 | timesShot: 0, 71 | shotsLandedPerBodyPart: copy(BodyParts), 72 | timesShotPerBodyPart: copy(BodyParts), 73 | }), 74 | combatRating: 800, 75 | highestCombatRating: 800, 76 | lowestCombatRating: 800, 77 | combatRatingHistory: [800], 78 | 79 | // General Session Data 80 | lastConnectionDate: null, 81 | lastDisconnectionDate: null, 82 | lastDamageDate: null, 83 | lastDeathDate: null, 84 | lastHitBy: null, 85 | connected: false, 86 | pos: [], 87 | lastPos: [], 88 | time: null, 89 | lastTime: null, 90 | 91 | // Session Stats 92 | totalSessionTime: 0, 93 | lastSessionTime: 0, 94 | longestSessionTime: 0, 95 | connections: 0, 96 | 97 | // Other 98 | bounties: [], 99 | bountiesLength: 0, 100 | } 101 | }, 102 | 103 | insertPVPstats(player) { 104 | player.shotsLanded = 0; 105 | player.timesShot = 0; 106 | player.shotsLandedPerBodyPart = copy(BodyParts); 107 | player.timesShotPerBodyPart = copy(BodyParts); 108 | player.weaponStats = createWeaponsObject({ 109 | kills: 0, 110 | deaths: 0, 111 | shotsLanded: 0, 112 | timesShot: 0, 113 | shotsLandedPerBodyPart: copy(BodyParts), 114 | timesShotPerBodyPart: copy(BodyParts), 115 | }); 116 | return player; 117 | }, 118 | 119 | // If a new weapon is not in the existing weaponStats, this will add it. 120 | createWeaponStats(player, weapon) { 121 | player.weaponStats[weapon] = { 122 | kills: 0, 123 | deaths: 0, 124 | shotsLanded: 0, 125 | timesShot: 0, 126 | shotsLandedPerBodyPart: copy(BodyParts), 127 | timesShotPerBodyPart: copy(BodyParts), 128 | } 129 | return player; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /commands/purchase-uav.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { createUser, addUser } = require('../database/user') 4 | 5 | module.exports = { 6 | name: "purchase-uav", 7 | debug: false, 8 | global: false, 9 | description: "Send a UAV to scout for 30 minutes (500m range)", 10 | usage: "[x-coord] [y-coord]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: ["MANAGE_GUILD"], 14 | }, 15 | options: [ 16 | { 17 | name: "x-coord", 18 | description: "X Coordinate of the origin", 19 | value: "x-coord", 20 | type: CommandOptions.Float, 21 | min_value: 0.01, 22 | required: true, 23 | }, 24 | { 25 | name: "y-coord", 26 | description: "Y Coordinate of the origin", 27 | value: "y-coord", 28 | type: CommandOptions.Float, 29 | min_value: 0.01, 30 | required: true, 31 | }, 32 | ], 33 | SlashCommand: { 34 | /** 35 | * 36 | * @param {require("../structures/DayzRBot")} client 37 | * @param {import("discord.js").Message} message 38 | * @param {string[]} args 39 | * @param {*} param3 40 | */ 41 | run: async (client, interaction, args, { GuildDB }) => { 42 | 43 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 44 | const warnNitradoNotInitialized = new EmbedBuilder() 45 | .setColor(client.config.Colors.Yellow) 46 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 47 | 48 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 49 | } 50 | 51 | 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')] }); 52 | 53 | let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 54 | 55 | if (!banking) { 56 | banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) 57 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 58 | } 59 | banking = banking.user; 60 | 61 | if (!client.exists(banking.guilds[GuildDB.serverID])) { 62 | const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); 63 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 64 | } 65 | 66 | if (banking.guilds[GuildDB.serverID].balance.toFixed(2) - GuildDB.uavPrice < 0) { 67 | let embed = new EmbedBuilder() 68 | .setTitle('**Bank Notice:** NSF. Non sufficient funds') 69 | .setColor(client.config.Colors.Red); 70 | 71 | return interaction.send({ embeds: [embed], flags: (1 << 6) }); 72 | } 73 | 74 | const newBalance = banking.guilds[GuildDB.serverID].balance - GuildDB.uavPrice; 75 | 76 | client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => { 77 | if (err) return client.sendInternalError(interaction, err); 78 | }); 79 | 80 | let uav = { 81 | origin: [args[0].value, args[1].value], 82 | radius: 250, 83 | owner: interaction.member.user.id, 84 | creationDate: new Date(), 85 | }; 86 | 87 | client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { 88 | $push: { 89 | 'server.uavs': uav, 90 | } 91 | }, (err, res) => { 92 | if (err) return client.sendInternalError(interaction, err); 93 | }); 94 | 95 | let successEmbed = new EmbedBuilder() 96 | .setColor(client.config.Colors.Green) 97 | .setDescription(`**Success:** Successfully deployed a UAV to **[${uav.origin[0]}, ${uav.origin[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${uav.origin[0]};${uav.origin[1]})**\nRange: 500m`); 98 | 99 | return interaction.send({ embeds: [successEmbed], flags: (1 << 6) }); 100 | }, 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /commands/reset.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { addUser } = require('../database/user'); 4 | const bitfieldCalculator = require('discord-bitfield-calculator'); 5 | 6 | module.exports = { 7 | name: "reset", 8 | debug: false, 9 | global: false, 10 | description: "Reset a user's bank/money", 11 | usage: "[user]", 12 | permissions: { 13 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 14 | member: ["MANAGE_GUILD"], 15 | }, 16 | options: [{ 17 | name: "user", 18 | description: "User to reset", 19 | value: "user", 20 | type: CommandOptions.User, 21 | required: true, 22 | }], 23 | SlashCommand: { 24 | /** 25 | * 26 | * @param {require("../structures/DayzRBot")} client 27 | * @param {import("discord.js").Message} message 28 | * @param {string[]} args 29 | * @param {*} param3 30 | */ 31 | run: async (client, interaction, args, { GuildDB }) => { 32 | const permissions = bitfieldCalculator.permissions(interaction.member.permissions); 33 | let canUseCommand = false; 34 | 35 | if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; 36 | if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true; 37 | if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' }); 38 | 39 | const targetUserID = args[0].value.replace('<@!', '').replace('>', ''); 40 | 41 | const prompt = new EmbedBuilder() 42 | .setTitle(`Are you sure you want to reset this user?`) 43 | .setDescription('**Notice:** This will reset this users cash and balance.') 44 | .setColor(client.config.Colors.Yellow) 45 | 46 | const opt = new ActionRowBuilder() 47 | .addComponents( 48 | new ButtonBuilder() 49 | .setCustomId(`Reset-yes-${targetUserID}-${interaction.member.user.id}`) 50 | .setLabel("Yes") 51 | .setStyle(ButtonStyle.Danger), 52 | new ButtonBuilder() 53 | .setCustomId(`Reset-no-${targetUserID}-${interaction.member.user.id}`) 54 | .setLabel("No") 55 | .setStyle(ButtonStyle.Success) 56 | ) 57 | 58 | return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); 59 | 60 | }, 61 | }, 62 | 63 | Interactions: { 64 | 65 | Reset: { 66 | run: async (client, interaction, GuildDB) => { 67 | const choice = interaction.customId.split('-')[1]; 68 | const targetUserID = interaction.customId.split('-')[2]; 69 | 70 | if (!interaction.customId.endsWith(interaction.member.user.id)) { 71 | return interaction.reply({ 72 | content: "This button is not for you", 73 | flags: (1 << 6) 74 | }) 75 | } 76 | if (choice=='yes') { 77 | const successEmbed = new EmbedBuilder() 78 | .setColor(client.config.Colors.Green) 79 | .setTitle('Successfully reset user\'s data') 80 | 81 | let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 82 | 83 | let bankingReset = false; 84 | if (!banking) bankingReset = true 85 | else banking = banking.user 86 | 87 | if (!bankingReset) { 88 | const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); 89 | if (!success) { 90 | client.error(err); 91 | const embed = new EmbedBuilder() 92 | .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) 93 | .setColor(client.config.Colors.Red) 94 | 95 | return interaction.update({ embeds: [embed], components: [] }); 96 | } 97 | } 98 | 99 | return interaction.update({ embeds: [successEmbed], components: [] }); 100 | 101 | } else if (choice=='no') { 102 | const successEmbed = new EmbedBuilder() 103 | .setColor(client.config.Colors.Green) 104 | .setTitle(`The User was not reset`); 105 | 106 | return interaction.update({ embeds: [successEmbed], components: [] }); 107 | } 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /commands/collect-income.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, } = require('discord.js'); 2 | const { createUser, addUser } = require('../database/user'); 3 | 4 | module.exports = { 5 | name: "collect-income", 6 | debug: false, 7 | global: false, 8 | description: "Collect your income", 9 | usage: "", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | options: [], 15 | SlashCommand: { 16 | /** 17 | * 18 | * @param {require("../structures/DayzRBot")} client 19 | * @param {import("discord.js").Message} message 20 | * @param {string[]} args 21 | * @param {*} param3 22 | */ 23 | run: async (client, interaction, args, { GuildDB }) => { 24 | if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { 25 | return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); 26 | } 27 | 28 | const hasIncomeRole = GuildDB.incomeRoles.some(data => { 29 | if (interaction.member.roles.includes(data.role)) return true; 30 | return false; 31 | }); 32 | 33 | if (!hasIncomeRole) { 34 | const error = new EmbedBuilder() 35 | .setColor(client.config.Colors.Red) 36 | .setTitle('Missing Income!') 37 | .setDescription(`It appears you don't have any income`) 38 | 39 | return interaction.send({ embeds: [error] }) 40 | } 41 | 42 | let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 43 | 44 | 45 | if (!banking) { 46 | banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) 47 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 48 | } 49 | banking = banking.user; 50 | 51 | if (!client.exists(banking.guilds[GuildDB.serverID])) { 52 | const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); 53 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 54 | } 55 | 56 | if (!client.exists(banking.guilds[GuildDB.serverID].lastIncome)) banking.guilds[GuildDB.serverID].lastIncome = new Date('2000-01-01T00:00:00'); 57 | 58 | let now = new Date(); 59 | let diff = (now - banking.guilds[GuildDB.serverID].lastIncome) / 1000; 60 | diff /= (60 * 60); 61 | let hoursBetweenDates = Math.abs(Math.round(diff)); 62 | 63 | if (hoursBetweenDates >= GuildDB.incomeLimiter) { 64 | let roles = []; 65 | let income = []; 66 | for (let i = 0; i < GuildDB.incomeRoles.length; i++) { 67 | if (interaction.member.roles.includes(GuildDB.incomeRoles[i].role)) { 68 | roles.push(GuildDB.incomeRoles[i].role) 69 | income.push(GuildDB.incomeRoles[i].income) 70 | } 71 | } 72 | 73 | let totalIncome = income.reduce((x, y) => x + y, 0) 74 | 75 | let newData = banking.guilds[GuildDB.serverID]; 76 | newData.balance += totalIncome; 77 | newData.lastIncome = now; 78 | 79 | client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}`]: newData}}, (err, res) => { 80 | if (err) return client.sendInternalError(interaction, err); 81 | }); 82 | 83 | let description = `**You collected**`; 84 | for (let i = 0; i < roles.length; i++) { 85 | description += `\n<@&${roles[i]}> - $**${income[i].toFixed(2).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}**` 86 | } 87 | 88 | const success = new EmbedBuilder() 89 | .setColor(client.config.Colors.Green) 90 | .setDescription(description) 91 | 92 | return interaction.send({ embeds: [success] }) 93 | 94 | } else { 95 | let date = banking.guilds[GuildDB.serverID].lastIncome; 96 | date.setHours(date.getHours() + GuildDB.incomeLimiter); 97 | diff = (date - now) / 1000; 98 | let timeTillIncome = client.secondsToDhms(diff); 99 | 100 | const error = new EmbedBuilder() 101 | .setColor(client.config.Colors.Red) 102 | .setDescription(`You've already collected your income this week. Wait **${timeTillIncome}** to collect again.`); 103 | 104 | return interaction.send({ embeds: [error] }) 105 | } 106 | }, 107 | }, 108 | } -------------------------------------------------------------------------------- /commands/gamertag-link.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { UpdatePlayer } = require('../database/player'); 4 | 5 | module.exports = { 6 | name: "gamertag-link", 7 | debug: false, 8 | global: false, 9 | description: "Connect DayZ stats to your Discord", 10 | usage: "[gamertag]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [{ 16 | name: "gamertag", 17 | description: "Gamertag of player", 18 | value: "gamertag", 19 | type: CommandOptions.String, 20 | required: true, 21 | }], 22 | SlashCommand: { 23 | /** 24 | * 25 | * @param {require("../structures/DayzRBot")} client 26 | * @param {import("discord.js").Message} message 27 | * @param {string[]} args 28 | * @param {*} param3 29 | */ 30 | run: async (client, interaction, args, { GuildDB }) => { 31 | 32 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 33 | const warnNitradoNotInitialized = new EmbedBuilder() 34 | .setColor(client.config.Colors.Yellow) 35 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 36 | 37 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 38 | } 39 | 40 | let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].value}); 41 | 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 \`.`)] }); 42 | 43 | if (client.exists(playerStat.discordID)) { 44 | const warnGTOverwrite = new EmbedBuilder() 45 | .setColor(client.config.Colors.Yellow) 46 | .setDescription(`**Notice:**\n> The gamertag has previously been linked to <@${playerStat.discordID}>. Are you sure you would like to change this?`) 47 | 48 | const opt = new ActionRowBuilder() 49 | .addComponents( 50 | new ButtonBuilder() 51 | .setCustomId(`OverwriteGamertag-yes-${args[0].value}-${interaction.member.user.id}`) 52 | .setLabel("Yes") 53 | .setStyle(ButtonStyle.Success), 54 | new ButtonBuilder() 55 | .setCustomId(`OverwriteGamertag-no-${args[0].value}-${interaction.member.user.id}`) 56 | .setLabel("No") 57 | .setStyle(ButtonStyle.Secondary) 58 | ) 59 | 60 | return interaction.send({ embeds: [warnGTOverwrite], components: [opt] }); 61 | } 62 | 63 | playerStat.discordID = interaction.member.user.id; 64 | 65 | await UpdatePlayer(client, playerStat, interaction); 66 | 67 | let member = interaction.guild.members.cache.get(interaction.member.user.id); 68 | if (client.exists(GuildDB.linkedGamertagRole)) { 69 | let role = interaction.guild.roles.cache.get(GuildDB.linkedGamertagRole); 70 | member.roles.add(role); 71 | } 72 | 73 | if (client.exists(GuildDB.memberRole)) { 74 | let role = interaction.guild.roles.cache.get(GuildDB.memberRole); 75 | member.roles.add(role); 76 | } 77 | 78 | let connectedEmbed = new EmbedBuilder() 79 | .setColor(client.config.Colors.Default) 80 | .setDescription(`Successfully connected \` ${playerStat.gamertag} \` as your gamertag.`); 81 | 82 | return interaction.send({ embeds: [connectedEmbed] }) 83 | }, 84 | }, 85 | 86 | Interactions: { 87 | 88 | OverwriteGamertag: { 89 | run: async(client, interaction, GuildDB) => { 90 | if (!interaction.customId.endsWith(interaction.member.user.id)) 91 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 92 | 93 | if (interaction.customId.split('-')[1]=='yes') { 94 | let playerStat = await client.dbo.collection("players").findOne({"gamertag": interaction.customId.split('-')[2]}); 95 | 96 | playerStat.discordID = interaction.member.user.id; 97 | 98 | await UpdatePlayer(client, playerStat, interaction); 99 | 100 | let member = interaction.guild.members.cache.get(interaction.member.user.id); 101 | if (client.exists(GuildDB.linkedGamertagRole)) { 102 | let role = interaction.guild.roles.cache.get(GuildDB.linkedGamertagRole); 103 | member.roles.add(role); 104 | } 105 | 106 | if (client.exists(GuildDB.memberRole)) { 107 | let role = interaction.guild.roles.cache.get(GuildDB.memberRole); 108 | member.roles.add(role); 109 | } 110 | 111 | let connectedEmbed = new EmbedBuilder() 112 | .setColor(client.config.Colors.Default) 113 | .setDescription(`Successfully connected \` ${playerStat.gamertag} \` as your gamertag.`); 114 | 115 | return interaction.update({ embeds: [connectedEmbed], components: [] }); 116 | 117 | } else { 118 | const cancel = new EmbedBuilder() 119 | .setColor(client.config.Colors.Default) 120 | .setDescription('**Canceled**\n> The gamertag link will not be overwritten'); 121 | 122 | return interaction.update({ embeds: [cancel], components: [] }); 123 | } 124 | } 125 | } 126 | 127 | } 128 | } -------------------------------------------------------------------------------- /commands/purchase-emp.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js'); 2 | const { createUser, addUser } = require('../database/user'); 3 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 4 | 5 | module.exports = { 6 | name: "purchase-emp", 7 | debug: false, 8 | global: false, 9 | description: "EMP an Alarm to prevent any updates for 30 or 60 minutes", 10 | usage: "", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: ["MANAGE_GUILD"], 14 | }, 15 | options: [{ 16 | name: "duration", 17 | description: "Select the duration of the emp (30 or 60 minutes)", 18 | value: "duration", 19 | type: CommandOptions.Integer, 20 | required: true, 21 | choices: [ 22 | { name: "30 Minutes", value: 30 }, 23 | { name: "60 Minutes", value: 60 } 24 | ] 25 | }], 26 | SlashCommand: { 27 | /** 28 | * 29 | * @param {require("../structures/DayzRBot")} client 30 | * @param {import("discord.js").Message} message 31 | * @param {string[]} args 32 | * @param {*} param3 33 | */ 34 | run: async (client, interaction, args, { GuildDB }) => { 35 | 36 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 37 | const warnNitradoNotInitialized = new EmbedBuilder() 38 | .setColor(client.config.Colors.Yellow) 39 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 40 | 41 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 42 | } 43 | 44 | 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')] }); 45 | 46 | const duration = args[0].value; 47 | let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 48 | 49 | if (!banking) { 50 | banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) 51 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 52 | } 53 | banking = banking.user; 54 | 55 | if (!client.exists(banking.guilds[GuildDB.serverID])) { 56 | const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); 57 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 58 | } 59 | 60 | if (banking.guilds[GuildDB.serverID].balance.toFixed(2) - GuildDB.empPrice < 0) { 61 | let embed = new EmbedBuilder() 62 | .setTitle('**Bank Notice:** NSF. Non sufficient funds') 63 | .setColor(client.config.Colors.Red); 64 | 65 | return interaction.send({ embeds: [embed], flags: (1 << 6) }); 66 | } 67 | 68 | const price = duration == 30 ? GuildDB.empPrice : GuildDB.empPrice * 2; 69 | const newBalance = banking.guilds[GuildDB.serverID].balance - price; 70 | 71 | 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) }); 72 | 73 | client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => { 74 | if (err) return client.sendInternalError(interaction, err); 75 | }); 76 | 77 | let alarms = new StringSelectMenuBuilder() 78 | .setCustomId(`EMPAlarmSelect-${interaction.member.user.id}`) 79 | .setPlaceholder(`Select an Alarm to EMP.`) 80 | 81 | for (let i = 0; i < GuildDB.alarms.length; i++) { 82 | if (!GuildDB.alarms[i].empExempt) { 83 | alarms.addOptions({ 84 | label: GuildDB.alarms[i].name, 85 | description: `EMP this Alarm for $${price.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0})}}`, 86 | value: `${GuildDB.alarms[i].name}-${duration}`, 87 | }); 88 | } 89 | } 90 | 91 | const opt = new ActionRowBuilder().addComponents(alarms); 92 | 93 | return interaction.send({ components: [opt], flags: (1 << 6) }); 94 | }, 95 | }, 96 | 97 | Interactions: { 98 | EMPAlarmSelect: { 99 | run: async (client, interaction, GuildDB) => { 100 | let duration = parseInt(interaction.values[0].split('-')[1]); 101 | let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0].split('-')[0]); 102 | let alarms = GuildDB.alarms; 103 | let alarmIndex = alarms.indexOf(alarm); 104 | alarm.disabled = true; 105 | let d = new Date(); 106 | alarm.empExpire = new Date(d.getTime() + (duration * 60 * 1000)); 107 | alarms[alarmIndex] = alarm; 108 | 109 | client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { 110 | $set: { 111 | 'server.alarms': alarms, 112 | } 113 | }, (err, res) => { 114 | if (err) return client.sendInternalError(interaction, err); 115 | }); 116 | 117 | let successEmbed = new EmbedBuilder() 118 | .setColor(client.config.Colors.Green) 119 | .setDescription(`**Success:** Successfully EMP'd **${alarm.name}** for 30 minutes.`); 120 | 121 | return interaction.update({ embeds: [successEmbed], components: [] }); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /commands/compare-rating.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { insertPVPstats } = require('../database/player'); 4 | 5 | module.exports = { 6 | name: "compare-rating", 7 | debug: false, 8 | global: false, 9 | description: "Compare combat ratings between yourself and another player", 10 | usage: "[user or gamertag]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [{ 16 | name: "discord", 17 | description: "Discord user to lookup stats", 18 | value: "discord", 19 | type: CommandOptions.User, 20 | required: false, 21 | }, { 22 | name: "gamertag", 23 | description: "Gamertag to lookup stats", 24 | type: CommandOptions.String, 25 | required: false, 26 | }], 27 | SlashCommand: { 28 | /** 29 | * 30 | * @param {require("../structures/DayzRBot")} client 31 | * @param {import("discord.js").Message} message 32 | * @param {string[]} args 33 | * @param {*} param3 34 | */ 35 | run: async (client, interaction, args, { GuildDB }) => { 36 | 37 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 38 | const warnNitradoNotInitialized = new EmbedBuilder() 39 | .setColor(client.config.Colors.Yellow) 40 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 41 | 42 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 43 | } 44 | 45 | let discord = args[0] && args[0].name == 'discord' ? args[0].value : undefined; 46 | let gamertag = args[0] && args[0].name == 'gamertag' ? args[0].value : undefined; 47 | 48 | if (!discord && !gamertag) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`Please provide a Discord User or Gamertag`)] }); 49 | 50 | let leaderboard = await client.dbo.collection("players").aggregate([ 51 | { $sort: { 'combatRating': -1 } } 52 | ]).toArray(); 53 | 54 | let comp; 55 | if (discord) comp = leaderboard.find(s => s.discordID == discord); 56 | if (gamertag) comp = leaderboard.find(s => s.gamertag == gamertag); 57 | let self = leaderboard.find(s => s.discordID == interaction.member.user.id); 58 | 59 | 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.`)] }); 60 | 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.`)] }); 61 | 62 | let lbPosSelf = leaderboard.indexOf(self) + 1; 63 | let lbPosComp = leaderboard.indexOf(comp) + 1; 64 | 65 | let selfData = self.combatRatingHistory; 66 | let compData = comp.combatRatingHistory; 67 | if (selfData.length == 1) selfData.push(self.combatRating) // Make array 2 long for a straight line in the graph 68 | if (compData.length == 1) compData.push(comp.combatRating) // Make array 2 long for a straight line in the graph 69 | let selfDataMax = Math.max(...selfData); 70 | let compDataMax = Math.max(...compData); 71 | 72 | if (!client.exists(self.highestCombatRating) || self.highestCombatRating < selfDataMax) self.highestCombatRating = selfDataMax; 73 | if (!client.exists(comp.highestCombatRating) || comp.highestCombatRating < compDataMax) comp.highestCombatRating = compDataMax; 74 | 75 | let tag = comp.discordID != "" ? `<@${comp.discordID}>` : comp.gamertag; 76 | 77 | let statsEmbed = new EmbedBuilder() 78 | .setColor(client.config.Colors.Default) 79 | .setDescription(`<@${interaction.member.user.id}> vs ${tag} Combat Rating`) 80 | .addFields( 81 | { name: `${self.gamertag}'s Combat Rating Stats`, value: `> Leaderboard Pos: # ${lbPosSelf}\n> Rating: ${self.combatRating}`, inline: false }, 82 | { name: `${comp.gamertag}'s Combat Rating Stats`, value: `> Leaderboard Pos: # ${lbPosComp}\n> Rating: ${comp.combatRating}`, inline: false }, 83 | { name: 'Rating Difference', value: `${Math.abs(self.combatRating - comp.combatRating)}`, inline: false }, 84 | ); 85 | 86 | const dataMax = Math.max(selfDataMax, compDataMax); 87 | const dataMin = Math.min(Math.min(...selfData), Math.min(...compData)) 88 | 89 | const len = Math.max(selfData.length, compData.length); 90 | const diff = Math.abs(selfData.length - compData.length); 91 | if (selfData.length < compData.length) selfData.unshift(...(new Array(diff).fill(null, 0, diff))); 92 | if (compData.length < selfData.length) compData.unshift(...(new Array(diff).fill(null, 0, diff))); 93 | 94 | const chart = { 95 | type: 'line', 96 | data: { 97 | labels: new Array(len).fill(' ', 0, len), 98 | datasets: [ 99 | { 100 | data: selfData, 101 | label: `${self.gamertag}'s Combat Ratings`, 102 | }, 103 | { 104 | data: compData, 105 | label: `${comp.gamertag}'s Combat Ratings`, 106 | } 107 | ], 108 | }, 109 | options: { 110 | legend: { 111 | labels: { 112 | fontSize: 14, 113 | fontStyle: 'bold', 114 | } 115 | }, 116 | scales: { 117 | // Gives comfortable margin to the top of the y-axis 118 | yAxes: [{ 119 | ticks: { 120 | fontStyle: 'bold', 121 | // max: Math.round(dataMax / 10) * 10 + 10, 122 | // min: Math.round(dataMin / 10) * 10, 123 | }, 124 | }], 125 | }, 126 | // Gives a margin to the right of the whole graph 127 | layout: { 128 | padding: { 129 | right: 40, 130 | }, 131 | }, 132 | }, 133 | }; 134 | 135 | const encodedChart = encodeURIComponent(JSON.stringify(chart)); 136 | const chartURL = `https://quickchart.io/chart?c=${encodedChart}&bkg=${encodeURIComponent("#ded8d7")}`; 137 | 138 | statsEmbed.setImage(chartURL); 139 | 140 | return interaction.send({ embeds: [statsEmbed] }); 141 | }, 142 | }, 143 | } -------------------------------------------------------------------------------- /commands/help.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require("discord.js"); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const package = require("../package"); 4 | 5 | module.exports = { 6 | name: "help", 7 | debug: false, 8 | global: true, 9 | description: "Get information on a specific command", 10 | usage: "[option]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [ 16 | { 17 | name: "commands", 18 | description: "List all commands", 19 | value: "commands", 20 | type: CommandOptions.SubCommand, 21 | options: [{ 22 | name: "command", 23 | description: "Get information on a specific command", 24 | value: "command", 25 | type: CommandOptions.String, 26 | required: false, 27 | }] 28 | }, 29 | { 30 | name: "support", 31 | description: "Get support for Application", 32 | value: "support", 33 | type: CommandOptions.SubCommand, 34 | }, 35 | { 36 | name: "credits", 37 | description: "DayZ.R Bot Credits", 38 | value: "credits", 39 | type: CommandOptions.SubCommand, 40 | }, 41 | { 42 | name: "stats", 43 | description: "Current Bot Statistics", 44 | value: "stats", 45 | type: CommandOptions.SubCommand, 46 | } 47 | ], 48 | SlashCommand: { 49 | /** 50 | * 51 | * @param {require("../structures/DayzRBot")} client 52 | * @param {import("discord.js").Message} message 53 | * @param {string[]} args 54 | * @param {*} param3 55 | */ 56 | 57 | run: async (client, interaction, args, {GuildDB}, start) => { 58 | if (args[0].name == 'commands') { 59 | let Commands = client.commands.filter((cmd) => { 60 | return !cmd.debug 61 | }).map((cmd) => 62 | `\`/${cmd.name}${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` 63 | ); 64 | 65 | let Embed = new EmbedBuilder() 66 | .setTitle('Commands') 67 | .setColor(client.config.Colors.Default) 68 | .setDescription(`${Commands.join("\n")} 69 | 70 | DayZR Bot Version: v${client.config.Version}`); 71 | if (!args[0].options[0]) return interaction.send({ embeds: [Embed] }); 72 | else { 73 | let cmd = 74 | client.commands.get(args[0].options[0].value) || 75 | client.commands.find( 76 | (x) => x.aliases && x.aliases.includes(args[0].options[0].value) 77 | ); 78 | if (!cmd) 79 | return interaction.send({ content: `❌ | Unable to find that command.` }); 80 | 81 | let embed = new EmbedBuilder() 82 | .setDescription(cmd.description) 83 | .setColor(client.config.Colors.Green) 84 | .setTitle(`How to use /${cmd.name} command`) 85 | 86 | if (cmd.SlashCommand.options && cmd.SlashCommand.options[0].type == 1) { 87 | let description = `${cmd.description}\n\n**Usage**\n`; 88 | 89 | for (let i = 0; i < cmd.SlashCommand.options.length; i++) { 90 | if (cmd.SlashCommand.options[i].type == 1) { 91 | let param = ''; 92 | if (cmd.SlashCommand.options[i].options) { 93 | param = cmd.SlashCommand.options[i].options.length > 0 ? ' ' : ''; 94 | for (let j = 0; j < cmd.SlashCommand.options[i].options.length; j++) { 95 | if (cmd.SlashCommand.options[i].options[j].required) param += `[${cmd.SlashCommand.options[i].options[j].name}] ` 96 | } 97 | } 98 | description += `\`/${cmd.name} ${cmd.SlashCommand.options[i].name}${param}\`\n${cmd.SlashCommand.options[i].description}\n\n` 99 | } 100 | } 101 | embed.setDescription(description); 102 | } else embed.addFields({ name: "Usage", value: `\`/${cmd.name}\`${cmd.usage ? " " + cmd.usage : ""}`, inline: true }) 103 | 104 | return interaction.send({ embeds: [embed] }); 105 | } 106 | } else if (args[0].name == 'support') { 107 | const supportEmbed = new EmbedBuilder() 108 | .setColor(client.config.Colors.Default) 109 | .setDescription(`**__DayZ.R Bot Support__** 110 | 111 | Are you experiencing troubles with the DayZ.R Bot? 112 | Do you have questions or concerns? 113 | Do you require help to use the bot? 114 | Do you have a feature you'd like to see? 115 | 116 | Join the support server to have all your needs fulfilled. 117 | ╚➤ ${client.config.SupportServer} 118 | `) 119 | 120 | return interaction.send({ embeds: [supportEmbed] }); 121 | 122 | } else if (args[0].name == 'credits') { 123 | const creditsEmbed = new EmbedBuilder() 124 | .setColor(client.config.Colors.Default) 125 | .setTitle('DayzRBot Credits') 126 | .setDescription(` 127 | **Bot Author:** mcdazzzled 128 | **Github:** https://github.com/SowinskiBraeden/dayz-reforger 129 | 130 | ${client.config.SupportServer} 131 | `); 132 | 133 | return interaction.send({ embeds: [creditsEmbed] }) 134 | } else if (args[0].name == 'stats') { 135 | const end = new Date().getTime(); 136 | 137 | const totalGuilds = await client.shard.fetchClientValues("guilds.cache.size").then(results => { 138 | return results.reduce((acc, guildCount) => acc + guildCount, 0); 139 | }); 140 | 141 | const totalUsers = await client.shard.broadcastEval(c => { 142 | c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0); 143 | }).then(data => data.reduce((acc, memberCount) => acc + memberCount, 0)); 144 | 145 | const stats = new EmbedBuilder() 146 | .setColor(client.config.Colors.Default) 147 | .setTitle('DayZ Reforger Bot Statistics') 148 | .addFields( 149 | { name: 'Guilds', value: `\`\`\`${totalGuilds}\`\`\``, inline: true }, 150 | { name: 'Users', value: `\`\`\`${totalUsers}\`\`\``, inline: true }, 151 | { name: 'Latency', value: `\`\`\`${end - start}ms\`\`\``, inline: true }, 152 | { name: 'Uptime', value: `\`\`\`${client.secondsToDhms(process.uptime().toFixed(2))}\`\`\``, inline: true }, 153 | { name: 'Bot Version', value: `\`\`\`${client.config.Dev} v${client.config.Version}\`\`\``, inline: true }, 154 | { name: 'Discord Version', value: `\`\`\`Discord.js ${package.dependencies["discord.js"]}\`\`\``, inline: true }, 155 | ); 156 | 157 | return interaction.send({ embeds: [stats] }) 158 | } 159 | }, 160 | }, 161 | }; -------------------------------------------------------------------------------- /commands/leaderboard.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | 4 | module.exports = { 5 | name: "leaderboard", 6 | debug: false, 7 | global: false, 8 | description: "View server stats leaderboard", 9 | usage: "[category] [limit]", 10 | permissions: { 11 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 12 | member: [], 13 | }, 14 | options: [{ 15 | name: "category", 16 | description: "Leaderboard Category", 17 | value: "category", 18 | type: CommandOptions.String, 19 | required: true, 20 | choices: [ 21 | { name: "Money", value: "money" }, 22 | { name: "Total Time Played", value: "totalSessionTime" }, 23 | { name: "Longest Game Session", value: "longestSessionTime" }, 24 | { name: "Kills", value: "kills" }, 25 | { name: "Kill Streak", value: "killStreak" }, 26 | { name: "Best Kill Streak", value: "bestKillStreak" }, 27 | { name: "Deaths", value: "deaths" }, 28 | { name: "Death Streak", value: "deathStreak" }, 29 | { name: "Worst Death Streak", value: "worstDeathStreak" }, 30 | { name: "Longest Kill", value: "longestKill" }, 31 | { name: "KDR", value: "KDR" }, 32 | { name: "Server Connections", value: "connections" }, 33 | { name: "Shots Landed", value: "shotsLanded" }, 34 | { name: "Times Shot", value: "timesShot" }, 35 | { name: "Combat Rating", value: "combatRating" }, 36 | ] 37 | }, { 38 | name: "limit", 39 | description: "Leaderboard limit", 40 | value: "limit", 41 | type: CommandOptions.Integer, 42 | min_value: 1, 43 | max_value: 25, 44 | required: true, 45 | }], 46 | SlashCommand: { 47 | /** 48 | * 49 | * @param {require("../structures/DayzRBot")} client 50 | * @param {import("discord.js").Message} message 51 | * @param {string[]} args 52 | * @param {*} param3 53 | */ 54 | run: async (client, interaction, args, { GuildDB }) => { 55 | 56 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 57 | const warnNitradoNotInitialized = new EmbedBuilder() 58 | .setColor(client.config.Colors.Yellow) 59 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 60 | 61 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 62 | } 63 | 64 | const category = args[0].value; 65 | const limit = args[1].value; 66 | 67 | let leaderboard = []; 68 | if (category == 'money') { 69 | 70 | leaderboard = await client.dbo.collection("users").aggregate([ 71 | { $sort: { [`user.guilds.${GuildDB.serverID}.balance`]: -1 } } 72 | ]).toArray(); 73 | 74 | } else { 75 | 76 | leaderboard = await client.dbo.collection("players").aggregate([ 77 | { $sort: { [`${category}`]: -1 } } 78 | ]).toArray(); 79 | 80 | } 81 | 82 | let leaderboardEmbed = new EmbedBuilder() 83 | .setColor(client.config.Colors.Default); 84 | 85 | let title = category == 'kills' ? "Total Kills Leaderboard" : 86 | category == 'killStreak' ? "Current Killstreak Leaderboard" : 87 | category == 'bestKillStreak' ? "Best Killstreak Leaderboard" : 88 | category == 'deaths' ? "Total Deaths Leaderboard" : 89 | category == 'deathStreak' ? "Current Deathstreak Leaderboard" : 90 | category == 'worstDeathStreak' ? "Worst Deathstreak Leaderboard" : 91 | category == 'longestKill' ? "Longest Kill Leaderboard" : 92 | category == 'money' ? "Money Leaderboard" : 93 | category == 'totalSessionTime' ? "Total Time Played" : 94 | category == 'longestSessionTime' ? "Longest Game Session" : 95 | category == 'KDR' ? "Kill Death Ratio" : 96 | category == 'connections' ? "Times Connected" : 97 | category == 'shotsLanded' ? "Shots Landed" : 98 | category == 'timesShot' ? "Times Shot" : 99 | category == 'combatRating' ? "Combat Rating" : 'N/A Error'; 100 | 101 | leaderboardEmbed.setTitle(`**${title} - DayZ Reforger**`); 102 | 103 | let des = ``; 104 | for (let i = 0; i < limit; i++) { 105 | if (leaderboard.length < limit && i == leaderboard.length) break; 106 | 107 | let stats = category == 'kills' ? `${leaderboard[i].kills} Kill${(leaderboard[i].kills>1||leaderboard[i].kills==0)?'s':''}` : 108 | category == 'killStreak' ? `${leaderboard[i].killStreak} Player Killstreak` : 109 | category == 'bestKillStreak' ? `${leaderboard[i].bestKillStreak} Player Killstreak` : 110 | category == 'deaths' ? `${leaderboard[i].deaths} Death${leaderboard[i].deaths>1||leaderboard[i].deaths==0?'s':''}` : 111 | category == 'deathStreak' ? `${leaderboard[i].deathStreak} Deathstreak` : 112 | category == 'worstDeathstreak' ? `${leaderboard[i].worstDeathStreak} Deathstreak` : 113 | category == 'longestKill' ? `${leaderboard[i].longestKill}m` : 114 | category == 'money' ? `$${(leaderboard[i].user.guilds[GuildDB.serverID].balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}` : 115 | category == 'totalSessionTime' ? `**Total:** ${client.secondsToDhms(leaderboard[i].totalSessionTime)}\n> **Last Session:** ${client.secondsToDhms(leaderboard[i].lastSessionTime)}` : 116 | category == 'longestSessionTime' ? `**Longest Game Session:** ${client.secondsToDhms(leaderboard[i].longestSessionTime)}` : 117 | category == 'KDR' ? `**KDR: ${leaderboard[i].KDR.toFixed(2)}**` : 118 | category == 'connection' ? `**Connections: ${leaderboard[i].connections}**` : 119 | category == 'combatRating' ? `**Combat Rating:** ${leaderboard[i].combatRating}` : 120 | category == 'shotsLanded' ? `**Shots Landed:** ${leaderboard[i].shotsLanded}` : 121 | category == 'timesShot' ? `**Times Shot:** ${leaderboard[i].timesShot}` : 'N/A Error'; 122 | 123 | if (category == 'money') des += `**${i+1}.** <@${leaderboard[i].user.userID}> - **${stats}**\n` 124 | else if (category == 'totalSessionTime' || category == 'longestSessionTime' || category == 'combatRating') { 125 | tag = leaderboard[i].discordID != "" ? `<@${leaderboard[i].discordID}>` : leaderboard[i].gamertag; 126 | des += `**${i+1}.** ${tag}\n> ${stats}\n\n`; 127 | } else leaderboardEmbed.addFields({ name: `**${i+1}. ${leaderboard[i].gamertag}**`, value: `**${stats}**`, inline: true }); 128 | } 129 | 130 | if (['money', 'totalSessionTime', 'longestSessionTime', 'combatRating'].includes(category)) leaderboardEmbed.setDescription(des); 131 | 132 | return interaction.send({ embeds: [leaderboardEmbed] }); 133 | }, 134 | }, 135 | } 136 | -------------------------------------------------------------------------------- /commands/event.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const bitfieldCalculator = require('discord-bitfield-calculator'); 4 | 5 | module.exports = { 6 | name: "event", 7 | debug: false, 8 | global: false, 9 | description: "Admin controlled events", 10 | usage: "[event] [option]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [{ 16 | name: "player-track", 17 | description: "Track a player and announce location", 18 | value: "player-track", 19 | type: CommandOptions.SubCommand, 20 | options: [{ 21 | name: "gamertag", 22 | description: "Gamertag of player", 23 | value: "gamertag", 24 | type: CommandOptions.String, 25 | required: true, 26 | }, 27 | { 28 | name: "time", 29 | description: "Duration of tracking", 30 | value: "time", 31 | type: CommandOptions.Integer, 32 | required: true, 33 | choices: [ 34 | { name: '10-minutes', value: 10 }, { name: '15-minutes', value: 15 }, { name: '20-minutes', value: 20 }, { name: '25-minutes', value: 25 }, 35 | { name: '30-minutes', value: 30 }, { name: '60-minutes', value: 60 }, { name: '90-minutes', value: 90 }, { name: '120-minutes', value: 120 }, 36 | ] 37 | }, 38 | { 39 | name: "event-name", 40 | description: "Name of the event", 41 | value: "event-name", 42 | type: CommandOptions.String, 43 | required: true, 44 | }, 45 | { 46 | name: "channel", 47 | description: "Channel to post tracking data", 48 | value: "channel", 49 | type: CommandOptions.Channel, 50 | channel_types: [0], // Restrict to text channel 51 | required: true, 52 | }, { 53 | name: "role", 54 | description: "Optional role to ping", 55 | value: "role", 56 | type: CommandOptions.Role, 57 | required: false, 58 | }] 59 | }, { 60 | name: "delete", 61 | description: "Delete an active event", 62 | value: "delete", 63 | type: CommandOptions.SubCommand 64 | }], 65 | SlashCommand: { 66 | /** 67 | * 68 | * @param {require("../structures/DayzRBot")} client 69 | * @param {import("discord.js").Message} message 70 | * @param {string[]} args 71 | * @param {*} param3 72 | */ 73 | run: async (client, interaction, args, { GuildDB }) => { 74 | 75 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 76 | const warnNitradoNotInitialized = new EmbedBuilder() 77 | .setColor(client.config.Colors.Yellow) 78 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 79 | 80 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 81 | } 82 | 83 | const permissions = bitfieldCalculator.permissions(interaction.member.permissions); 84 | let canUseCommand = false; 85 | 86 | if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; 87 | if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) canUseCommand = true; 88 | if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' }); 89 | 90 | let events = GuildDB.events; 91 | 92 | if (args[0].name == 'player-track') { 93 | 94 | let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value}); 95 | if (!client.exists(playerStat)) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].options[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 \`.`)] }); 96 | 97 | let event = { 98 | type: args[0].name, 99 | name: args[0].options[2].value, 100 | gamertag: args[0].options[0].value, 101 | channel: args[0].options[3].value, 102 | role: args[0].options[4] ? args[0].options[4].value : null, 103 | time: args[0].options[1].value, 104 | creationDate: new Date(), 105 | }; 106 | 107 | events.push(event); 108 | 109 | client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, { 110 | $set: { 111 | "server.events": events 112 | } 113 | }, (err, res) => { 114 | if (err) return client.sendInternalError(interaction, err); 115 | }); 116 | 117 | const successCreatePlayerTrack = new EmbedBuilder() 118 | .setColor(client.config.Colors.Default) 119 | .setDescription(`**Success:** Successfully created **${event.name}** that will last **${event.time} minutes.**`) 120 | 121 | return interaction.send({ embeds: [successCreatePlayerTrack] }); 122 | 123 | } else if (args[0].name == 'delete') { 124 | if (GuildDB.events.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Events to Delete.')] }); 125 | 126 | let events = new StringSelectMenuBuilder() 127 | .setCustomId(`DeleteEvent-${interaction.member.user.id}`) 128 | .setPlaceholder(`Select an Event to Delete.`) 129 | 130 | for (let i = 0; i < GuildDB.events.length; i++) { 131 | events.addOptions({ 132 | label: GuildDB.events[i].name, 133 | description: `Delete this Event`, 134 | value: GuildDB.events[i].name 135 | }); 136 | } 137 | 138 | const eventsOptions = new ActionRowBuilder().addComponents(events); 139 | 140 | return interaction.send({ components: [eventsOptions], flags: (1 << 6) }); 141 | } 142 | } 143 | }, 144 | 145 | Interactions: { 146 | 147 | DeleteEvent: { 148 | run: async(client, interaction, GuildDB) => { 149 | if (!interaction.customId.endsWith(interaction.member.user.id)) 150 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 151 | 152 | let event = GuildDB.events.find(e => e.name == interaction.values[0]); 153 | 154 | client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { 155 | $pull: { 156 | 'server.events': event, 157 | } 158 | }, (err, res) => { 159 | if (err) return client.sendInternalError(interaction, err); 160 | }); 161 | 162 | let successEmbed = new EmbedBuilder() 163 | .setColor(client.config.Colors.Green) 164 | .setDescription(`**Success:** Successfully Deleted **${event.name} Event**`); 165 | 166 | return interaction.update({ embeds: [successEmbed], components: [] }); 167 | } 168 | } 169 | } 170 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /database/armbands.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Armbands: [ 3 | { 4 | name: "Black", 5 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/82/ArmbandBlack.png/revision/latest?cb=20161127174754" 6 | }, 7 | { 8 | name: "Blue", 9 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/bd/ArmbandBlue.png/revision/latest?cb=20161127174803" 10 | }, 11 | { 12 | name: "Green", 13 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/ce/ArmbandGreen.png/revision/latest?cb=20161127174812" 14 | }, 15 | { 16 | name: "Orange", 17 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e6/ArmbandOrange.png/revision/latest?cb=20161127174846" 18 | }, 19 | { 20 | name: "Pink", 21 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f7/ArmbandPink.png/revision/latest?cb=20161127174854" 22 | }, 23 | { 24 | name: "Red", 25 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/1/14/Armband.png/revision/latest?cb=20161127174901" 26 | }, 27 | { 28 | name: "Yellow", 29 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/81/ArmbandYellow.png/revision/latest?cb=20161127174918" 30 | }, 31 | { 32 | name: "White", 33 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c7/Armband_White.png/revision/latest?cb=20161127174926" 34 | }, 35 | { 36 | name: "Altis", 37 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ee/Flag_alti_co.png/revision/latest?cb=20200820222622" 38 | }, 39 | { 40 | name: "Asiain Pacific Alliance (APA)", 41 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c2/Flag_apa_co.png/revision/latest?cb=20200820222623" 42 | }, 43 | { 44 | name: "Bear", 45 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e1/Flag_bear_co.png/revision/latest?cb=20200820222626" 46 | }, 47 | { 48 | name: "Bohemia Interactive", 49 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ee/Flag_bi_co.png/revision/latest?cb=20200820222627" 50 | }, 51 | { 52 | name: "Brain", 53 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/7d/Flag_brain_co.png/revision/latest?cb=20200820222628" 54 | }, 55 | { 56 | name: "Chernarussian Defence Forces (CDF)", 57 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/d/d6/Flag_cdf_co.png/revision/latest?cb=20200820222629" 58 | }, 59 | { 60 | name: "Chedaki (CHED)", 61 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/96/Flag_ched_co.png/revision/latest?cb=20200820222630" 62 | }, 63 | { 64 | name: "CHEL", 65 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/98/Flag_chel_co.png/revision/latest?cb=20200820222631" 66 | }, 67 | { 68 | name: "Chernarus", 69 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ef/Flag_chern_co.png/revision/latest?cb=20200820222632" 70 | }, 71 | { 72 | name: "Chernarus Mining Corporation (CMC)", 73 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/d/da/Flag_cmc_co.png/revision/latest?cb=20200820222634" 74 | }, 75 | { 76 | name: "Rooster", 77 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/44/Flag_cock_co.png/revision/latest?cb=20200820222635" 78 | }, 79 | { 80 | name: "DayZ", 81 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b2/Flag_dayz_co.png/revision/latest?cb=20200820222636" 82 | }, 83 | { 84 | name: "North Sahrani (DROS)", 85 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/24/Flag_dros_co.png/revision/latest?cb=20200820222637" 86 | }, 87 | { 88 | name: "Fawn", 89 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/d/d2/Flag_fawn_co.png/revision/latest/scale-to-width-down/1000?cb=20200820222639" 90 | }, 91 | { 92 | name: "Pirates", 93 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/ab/Flag_jolly_co.png/revision/latest?cb=20200820222643" 94 | }, 95 | { 96 | name: "Cannibals", 97 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/42/Flag_jolly_c_co.png/revision/latest?cb=20200820222641" 98 | }, 99 | { 100 | name: "South Sahrani (KOS)", 101 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a1/Flag_kos_co.png/revision/latest?cb=20200820222644" 102 | }, 103 | { 104 | name: "Livonia Army (LDF)", 105 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c1/Flag_ldf_co.png/revision/latest?cb=20200820222645" 106 | }, 107 | { 108 | name: "Livonia", 109 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e6/Flag_livo_co.png/revision/latest?cb=20200820222647" 110 | }, 111 | { 112 | name: "NAPA", 113 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e4/Flag_napa_co.png/revision/latest?cb=20200820222648" 114 | }, 115 | { 116 | name: "Livonia Police", 117 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/63/Flag_police_co.png/revision/latest?cb=20200820222649" 118 | }, 119 | { 120 | name: "TEC", 121 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ea/Flag_tec_co.png/revision/latest?cb=20200820222650" 122 | }, 123 | { 124 | name: "United Earth Coalition (UEC)", 125 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/ca/Flag_uec_co.png/revision/latest?cb=20200820222651" 126 | }, 127 | { 128 | name: "Wolf", 129 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b2/Flag_wolf_co.png/revision/latest?cb=20200820222653" 130 | }, 131 | { 132 | name: "Zenit Radio Station", 133 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/05/Flag_zenit_co.png/revision/latest?cb=20200820222654" 134 | }, 135 | { 136 | name: "Zombie Hunters", 137 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/97/Flag_zhunters_co.png/revision/latest?cb=20200820222621" 138 | }, 139 | { 140 | name: "RSTA", 141 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/20/Flag_rsta_co.png/revision/latest/scale-to-width-down/1000?cb=20210216191221" 142 | }, 143 | { 144 | name: "Refuge", 145 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/8e/Flag_refuge_co.png/revision/latest/scale-to-width-down/1000?cb=20210216191205" 146 | }, 147 | { 148 | name: "Snake", 149 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/5/54/Flag_snake_co.png/revision/latest/scale-to-width-down/1000?cb=20210216191234" 150 | }, 151 | { 152 | name: "Zagorky", 153 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/75/Flag_zagorky_co.png/revision/latest/scale-to-width-down/1000?cb=20230619164704" 154 | }, 155 | { 156 | name: "Crook", 157 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c8/Flag_crook_co.png/revision/latest/scale-to-width-down/1000?cb=20230619164705" 158 | }, 159 | { 160 | name: "Rex", 161 | url: "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c5/Flag_rex_co.png/revision/latest/scale-to-width-down/1000?cb=20230619164706" 162 | }, 163 | ] 164 | } 165 | -------------------------------------------------------------------------------- /commands/bank.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { createUser, addUser } = require('../database/user'); 4 | 5 | module.exports = { 6 | name: "bank", 7 | debug: false, 8 | global: false, 9 | description: "Manage your banking", 10 | usage: "[command] [options]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [ 16 | { 17 | name: "balance", 18 | description: "View your bank balance", 19 | value: "balance", 20 | type: CommandOptions.SubCommand, 21 | options: [{ 22 | name: "user", 23 | description: "User to view ballance", 24 | value: "user", 25 | type: CommandOptions.User, 26 | required: false, 27 | }] 28 | }, 29 | { 30 | name: "transfer", 31 | description: "Transfer money to another user", 32 | value: "transfer", 33 | type: CommandOptions.SubCommand, 34 | options: [ 35 | { 36 | name: "user", 37 | description: "User to transfer to", 38 | value: "user", 39 | type: CommandOptions.User, 40 | required: true, 41 | }, 42 | { 43 | name: "amount", 44 | description: "The amount to transfer", 45 | value: "amount", 46 | type: CommandOptions.Float, 47 | min_value: 0.01, 48 | required: true, 49 | }, 50 | ] 51 | } 52 | ], 53 | SlashCommand: { 54 | /** 55 | * 56 | * @param {require("../structures/DayzRBot")} client 57 | * @param {import("discord.js").Message} message 58 | * @param {string[]} args 59 | * @param {*} param3 60 | */ 61 | run: async (client, interaction, args, { GuildDB }) => { 62 | if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { 63 | return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); 64 | } 65 | 66 | let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 67 | 68 | if (!banking) { 69 | banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) 70 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 71 | } 72 | banking = banking.user; 73 | 74 | if (!client.exists(banking.guilds[GuildDB.serverID])) { 75 | const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); 76 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 77 | } 78 | 79 | if (args[0].name == 'balance') { 80 | let balanceEmbed = new EmbedBuilder() 81 | .setColor(client.config.Colors.Default); 82 | 83 | if (args[0].options&&args[0].options[0]) { 84 | // Show target users balance 85 | 86 | let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); 87 | let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(targetUserBanking => targetUserBanking); 88 | 89 | if (!targetUserBanking) { 90 | targetUserBanking = await createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, client) 91 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 92 | } 93 | targetUserBanking = targetUserBanking.user; 94 | 95 | if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) { 96 | const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); 97 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 98 | } 99 | 100 | // This lame line of code to get username without ping on discord 101 | const DiscordUser = client.users.cache.get(targetUserID); 102 | 103 | balanceEmbed.setTitle(`${DiscordUser.tag.split("#")[0]}'s Bank Records`); 104 | balanceEmbed.addFields({ name: '**Bank**', value: `$${targetUserBanking.guilds[GuildDB.serverID].balance.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`, inline: true }); 105 | 106 | } else { 107 | // Show command authors balance 108 | 109 | balanceEmbed.setTitle('Personal Bank Records'); 110 | balanceEmbed.addFields({ name: '**Bank**', value: `$${banking.guilds[GuildDB.serverID].balance.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`, inline: true }); 111 | } 112 | 113 | return interaction.send({ embeds: [balanceEmbed] }); 114 | 115 | } else if (args[0].name == 'transfer') { 116 | // send money from bank 117 | 118 | // prevent sending transfering money to self 119 | const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); 120 | 121 | if (targetUserID == interaction.member.user.id) return interaction.send({ embeds: [new EmbedBuilder().setDescription('**Invalid** You may not transfer money to yourself').setColor(client.config.Colors.Yellow)], flags: (1 << 6) }) 122 | 123 | if (banking.guilds[GuildDB.serverID].balance.toFixed(2) - args[0].options[1].value < 0) { 124 | let embed = new EmbedBuilder() 125 | .setTitle('**Bank Notice:** NSF. Non sufficient funds') 126 | .setColor(client.config.Colors.Red); 127 | 128 | return interaction.send({ embeds: [embed] }); 129 | } 130 | 131 | const newBalance = banking.guilds[GuildDB.serverID].balance - args[0].options[1].value; 132 | 133 | client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => { 134 | if (err) return client.sendInternalError(interaction, err); 135 | }); 136 | 137 | let targetUserBanking = await client.dbo.collection("users").findOne({"user.userID": targetUserID}).then(targetUserBanking => targetUserBanking); 138 | 139 | if (!targetUserBanking) { 140 | targetUserBanking = await createUser(targetUserID, GuildDB.serverID, GuildDB.startingBalance, client) 141 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 142 | } 143 | targetUserBanking = targetUserBanking.user; 144 | 145 | if (!client.exists(targetUserBanking.guilds[GuildDB.serverID])) { 146 | const success = addUser(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); 147 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 148 | } 149 | 150 | const newTargetBalance = targetUserBanking.guilds[GuildDB.serverID].balance + args[0].options[1].value; 151 | 152 | client.dbo.collection("users").updateOne({"user.userID":targetUserID},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newTargetBalance}}, (err, res) => { 153 | if (err) return client.sendInternalError(interaction, err); 154 | }); 155 | 156 | const successEmbed = new EmbedBuilder() 157 | .setTitle('Bank Notice:') 158 | .setDescription(`Successfully transfered <@${targetUserID}> **$${args[0].options[1].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}**`) 159 | .setColor(client.config.Colors.Green); 160 | 161 | return interaction.send({ embeds: [successEmbed] }); 162 | } 163 | }, 164 | }, 165 | } -------------------------------------------------------------------------------- /database/weapons.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | weapons: { 3 | handguns: { 4 | "CR-75": "https://static.wikia.nocookie.net/dayz_gamepedia/images/4/40/CZ75.png/revision/latest/scale-to-width-down/112?cb=20210505021307", 5 | "Deagle": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/62/Deagle.png/revision/latest/scale-to-width-down/127?cb=20210512003023", 6 | "Derringer": "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/9f/Derringer_Black.png/revision/latest/scale-to-width-down/105?cb=20220521175445", 7 | "FX-45": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fd/FNX45.png/revision/latest/scale-to-width-down/104?cb=20210505025055", 8 | "IJ-70": "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/26/MakarovIJ70.png/revision/latest/scale-to-width-down/92?cb=20210209000551", 9 | "Kolt 1911": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f9/Colt1911.png/revision/latest/scale-to-width-down/112?cb=20210505030200", 10 | "Longhorn": "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/79/Longhorn.png/revision/latest/scale-to-width-down/222?cb=20220324214533", 11 | "MK II": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0d/MKII.png/revision/latest/scale-to-width-down/171?cb=20210210153348", 12 | "Mlock-91": "https://static.wikia.nocookie.net/dayz_gamepedia/images/9/9b/Glock19.png/revision/latest/scale-to-width-down/121?cb=20210505024259", 13 | "P1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cc/P1.png/revision/latest/scale-to-width-down/120?cb=20220518204515", 14 | "Revolver": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/6d/Revolver.png/revision/latest/scale-to-width-down/148?cb=20210208232303", 15 | "Signal Pistol": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a7/Flaregun.png/revision/latest/scale-to-width-down/107?cb=20210501150913", 16 | }, 17 | shotguns: { 18 | "BK-12": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cb/Izh18Shotgun.png/revision/latest/scale-to-width-down/256?cb=20220922184507", 19 | "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", 20 | "BK-43": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c7/Izh43Shotgun.png/revision/latest/scale-to-width-down/256?cb=20210210185835", 21 | "Vaiga": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/c8/Vaiga.png/revision/latest/scale-to-width-down/256?cb=20220220185225", 22 | }, 23 | subMachineGuns: { 24 | "Bizon": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/af/PP19.png/revision/latest/scale-to-width-down/251?cb=20220127132305", 25 | "CR-61 Skorpion": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/63/VZ61Scorpion.png/revision/latest/scale-to-width-down/222?cb=20220518204508", 26 | "SG5-K": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fc/MP5-K.png/revision/latest/scale-to-width-down/158?cb=20220221011343", 27 | "USG-45": "https://static.wikia.nocookie.net/dayz_gamepedia/images/d/d7/UMP45.png/revision/latest/scale-to-width-down/153?cb=20220221002354", 28 | }, 29 | assaultRifles: { 30 | "AUR A1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e6/AugShort.png/revision/latest/scale-to-width-down/173?cb=20211104175243", 31 | "AUR AX": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/be/Aug.png/revision/latest/scale-to-width-down/233?cb=20211104182427", 32 | "KA-101": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f2/AK101.png/revision/latest/scale-to-width-down/251?cb=20210207040122", 33 | "KA-74": "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/8b/AK74.png/revision/latest/scale-to-width-down/253?cb=20210505013141", 34 | "KAS-74U": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0b/AKS74U.png/revision/latest/scale-to-width-down/191?cb=20210505014222", 35 | "KA-M": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/6c/AKM.png/revision/latest/scale-to-width-down/244?cb=20210505011614", 36 | "LE-MAS": "https://static.wikia.nocookie.net/dayz_gamepedia/images/2/21/FAMAS.png/revision/latest/scale-to-width-down/197?cb=20210902183114", 37 | "M16-A2": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b3/M16-A2.png/revision/latest/scale-to-width-down/256?cb=20220221002601", 38 | "M4-A1": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a1/M4A1.png/revision/latest/scale-to-width-down/223?cb=20220330014851", 39 | "SVAL": "https://static.wikia.nocookie.net/dayz_gamepedia/images/3/39/ASVAL.png/revision/latest/scale-to-width-down/256?cb=20210208015731", 40 | "Vikhr": "https://static.wikia.nocookie.net/dayz_gamepedia/images/0/0d/Vikhr.png/revision/latest/scale-to-width-down/173?cb=20240116163108" 41 | }, 42 | battleRifles: { 43 | "LAR": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/e9/FAL.png/revision/latest/scale-to-width-down/256?cb=20220221001123", 44 | }, 45 | boltActionRifles: { 46 | "CR-527": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/f0/CR527Wood.png/revision/latest/scale-to-width-down/256?cb=20220518204503 ", 47 | "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", 48 | "M70 Tundra": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/62/Winchester70.png/revision/latest/scale-to-width-down/256?cb=20220517152918", 49 | "Mosin 91/30": "https://static.wikia.nocookie.net/dayz_gamepedia/images/a/a8/Mosin9130.png/revision/latest/scale-to-width-down/256?cb=20230126021955", 50 | "Pioneer": "https://static.wikia.nocookie.net/dayz_gamepedia/images/6/69/Scout.png/revision/latest/scale-to-width-down/256?cb=20220518204357", 51 | "SSG 82": "https://static.wikia.nocookie.net/dayz_gamepedia/images/1/10/SSG82.png/revision/latest/scale-to-width-down/256?cb=20220922192455", 52 | "VS-89": "https://static.wikia.nocookie.net/dayz_gamepedia/images/e/ea/SV98.png/revision/latest/scale-to-width-down/256?cb=20240424164607", 53 | }, 54 | breakActionRifles: { 55 | "BK-18": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/cb/IZH18_Rifle.png/revision/latest/scale-to-width-down/256?cb=20220517154121", 56 | "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", 57 | }, 58 | leverActionRifles: { 59 | "Repeater Carbine": "https://static.wikia.nocookie.net/dayz_gamepedia/images/c/ce/Repeater.png/revision/latest/scale-to-width-down/256?cb=20220517154151", 60 | }, 61 | marksmanRifles: { 62 | "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", 63 | "VSS": "https://static.wikia.nocookie.net/dayz_gamepedia/images/8/83/VSSVintorez.png/revision/latest/scale-to-width-down/256?cb=20210208202042", 64 | }, 65 | semiAutomaticRifles: { 66 | "DMR": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b4/M14.png/revision/latest/scale-to-width-down/350?cb=20231005142636", 67 | "SK 59/66": "https://static.wikia.nocookie.net/dayz_gamepedia/images/f/fe/SKS.png/revision/latest/scale-to-width-down/256?cb=20220517154633", 68 | "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", 69 | }, 70 | other: { 71 | "Crossbow": "https://static.wikia.nocookie.net/dayz_gamepedia/images/7/79/Crossbow.png/revision/latest/scale-to-width-down/212?cb=20180121164101", 72 | "M79": "https://static.wikia.nocookie.net/dayz_gamepedia/images/b/b7/M79.png/revision/latest/scale-to-width-down/256?cb=20220521184052", 73 | }, 74 | }, 75 | 76 | weaponClassOf: (weapon) => Object.keys(module.exports.weapons).filter(c => weapon in module.exports.weapons[c])[0], 77 | } 78 | -------------------------------------------------------------------------------- /commands/weapon-stats.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { weapons } = require('../database/weapons'); 4 | const { insertPVPstats, createWeaponStats } = require('../database/player'); 5 | 6 | module.exports = { 7 | name: "weapon-stats", 8 | debug: false, 9 | global: false, 10 | description: "Check player weapon statistics", 11 | usage: "[category] [user or gamertag]", 12 | permissions: { 13 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 14 | member: [], 15 | }, 16 | options: [{ 17 | name: "category", 18 | description: "Weapon category", 19 | value: "category", 20 | type: CommandOptions.String, 21 | required: true, 22 | choices: [ 23 | { name: "Handguns", value: "handguns" }, 24 | { name: "Shotguns", value: "shotguns" }, 25 | { name: "Submachine Guns", value: "subMachineGuns" }, 26 | { name: "Assault Rifles", value: "assaultRifles" }, 27 | { name: "Battle Rifles", value: "battleRifles" }, 28 | { name: "Bolt-action Rifles", value: "boltActionRifles" }, 29 | { name: "Break-action Rifles", value: "breakActionRifles" }, 30 | { name: "Lever-action Rifles", value: "leverActionRifles" }, 31 | { name: "Marksman Rifles", value: "marksmanRifles" }, 32 | { name: "Semi-automatic Rifles", value: "semiAutomaticRifles" }, 33 | { name: "Other", value: "other" }, 34 | ] 35 | }, { 36 | name: "discord", 37 | description: "Discord user to lookup stats", 38 | value: "discord", 39 | type: CommandOptions.User, 40 | required: false, 41 | }, { 42 | name: "gamertag", 43 | description: "Gamertag to lookup stats", 44 | type: CommandOptions.String, 45 | required: false, 46 | }], 47 | SlashCommand: { 48 | /** 49 | * 50 | * @param {require("../structures/DayzRBot")} client 51 | * @param {import("discord.js").Message} message 52 | * @param {string[]} args 53 | * @param {*} param3 54 | */ 55 | run: async (client, interaction, args, { GuildDB }) => { 56 | 57 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 58 | const warnNitradoNotInitialized = new EmbedBuilder() 59 | .setColor(client.config.Colors.Yellow) 60 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 61 | 62 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 63 | } 64 | 65 | let discord = args[1] && args[1].name == 'discord' ? args[1].value : undefined; 66 | let gamertag = args[1] && args[1].name == 'gamertag' ? args[1].value : undefined; 67 | let self = !discord && !gamertag; // searching for self if both discord and gamertag are undefined 68 | const weaponClass = args[0].value; 69 | 70 | let query; 71 | 72 | // Searching by Discord 73 | if (discord) query = await client.dbo.collection("players").findOne({"discordID": discord}); 74 | 75 | // Searching by Gamertag 76 | if (gamertag) query = await client.dbo.collection("players").findOne({"gamertag": gamertag}); 77 | 78 | // Searching for self 79 | if (self) query = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); 80 | 81 | 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.`)] }); 82 | 83 | let weaponSelect = new StringSelectMenuBuilder() 84 | .setCustomId(`ViewWeaponStats-${query.playerID}-${interaction.member.user.id}`) 85 | .setPlaceholder(`Select an weapon to view stat.`) 86 | 87 | for (const [name, _] of Object.entries(weapons[weaponClass])) { 88 | weaponSelect.addOptions({ 89 | label: name, 90 | description: `View this weapon's stats.`, 91 | value: `${weaponClass}_${name}`, 92 | }); 93 | } 94 | 95 | const opt = new ActionRowBuilder().addComponents(weaponSelect); 96 | 97 | return interaction.send({ components: [opt] }); 98 | }, 99 | }, 100 | 101 | Interactions: { 102 | ViewWeaponStats: { 103 | run: async(client, interaction, GuildDB) => { 104 | if (!interaction.customId.endsWith(interaction.member.user.id)) 105 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 106 | 107 | const weapon = interaction.values[0].split("_")[1]; 108 | const weaponClass = interaction.values[0].split("_")[0]; 109 | const playerID = interaction.customId.split('-')[1]; 110 | let player = await client.dbo.collection("players").findOne({"playerID": playerID}); 111 | const tag = player.discordID != "" ? `<@${player.discordID}>'s` : `**${player.gamertag}'s**`; 112 | 113 | if (!client.exists(player.shotsLanded)) player = insertPVPstats(player); 114 | if (!client.exists(player.weaponStats[weapon])) player = createWeaponStats(player, weapon); 115 | 116 | let stats = new EmbedBuilder() 117 | .setColor(client.config.Colors.Default) 118 | .setDescription(`${tag} stats for the **${weapon}**`) 119 | .setThumbnail(weapons[weaponClass][weapon]) 120 | .addFields( 121 | { name: `Kills`, value: `${player.weaponStats[weapon].kills}`, inline: true }, 122 | { name: `Deaths`, value: `${player.weaponStats[weapon].deaths}`, inline: true }, 123 | { name: `Shots Landed`, value: `${player.weaponStats[weapon].shotsLanded}`, inline: true }, 124 | { name: `Times Shot`, value: `${player.weaponStats[weapon].timesShot}`, inline: true }, 125 | ); 126 | 127 | const chart = { 128 | type: 'bar', 129 | data: { 130 | labels: ['Head', 'Torso', 'Left Arm', 'Right Arm', 'Left Leg', 'Right Leg'], 131 | datasets: [{ 132 | label: `Shots landed with a ${weapon}`, 133 | data: [ 134 | player.weaponStats[weapon].shotsLandedPerBodyPart.Head, 135 | player.weaponStats[weapon].shotsLandedPerBodyPart.Torso, 136 | player.weaponStats[weapon].shotsLandedPerBodyPart.LeftArm, 137 | player.weaponStats[weapon].shotsLandedPerBodyPart.RightArm, 138 | player.weaponStats[weapon].shotsLandedPerBodyPart.LeftLeg, 139 | player.weaponStats[weapon].shotsLandedPerBodyPart.RightLeg, 140 | ], 141 | }, { 142 | label: `Times Shot by a ${weapon}`, 143 | data: [ 144 | player.weaponStats[weapon].timesShotPerBodyPart.Head, 145 | player.weaponStats[weapon].timesShotPerBodyPart.Torso, 146 | player.weaponStats[weapon].timesShotPerBodyPart.LeftArm, 147 | player.weaponStats[weapon].timesShotPerBodyPart.RightArm, 148 | player.weaponStats[weapon].timesShotPerBodyPart.LeftLeg, 149 | player.weaponStats[weapon].timesShotPerBodyPart.RightLeg, 150 | ], 151 | }], 152 | }, 153 | options: { 154 | legend: { 155 | labels: { 156 | fontSize: 14, 157 | fontStyle: 'bold', 158 | } 159 | }, 160 | scales: { 161 | yAxes: [{ ticks: { fontStyle: 'bold' } }], 162 | xAxes: [{ ticks: { fontStyle: 'bold' } }], 163 | }, 164 | }, 165 | }; 166 | 167 | const encodedChart = encodeURIComponent(JSON.stringify(chart)); 168 | const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}`; 169 | 170 | stats.setImage(chartURL); 171 | 172 | return interaction.update({ components: [], embeds: [stats] }); 173 | } 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /commands/bounty.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { createUser, addUser } = require('../database/user'); 4 | const { UpdatePlayer } = require('../database/player'); 5 | 6 | module.exports = { 7 | name: "bounty", 8 | debug: false, 9 | global: false, 10 | description: "Set or view bounties", 11 | usage: "[command] [options]", 12 | permissions: { 13 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 14 | member: [], 15 | }, 16 | options: [{ 17 | name: "set", 18 | description: "Set a bounty on a player", 19 | value: "set", 20 | type: CommandOptions.SubCommand, 21 | options: [{ 22 | name: "gamertag", 23 | description: "Gamertag of player for bounty", 24 | value: "gamertag", 25 | type: CommandOptions.String, 26 | required: true, 27 | }, { 28 | name: "value", 29 | description: "Amount of the bounty", 30 | value: "value", 31 | type: CommandOptions.Float, 32 | min_value: 0.01, 33 | required: true 34 | }, { 35 | name: "anonymous", 36 | description: "Make this bounty anonymous (does not show your name)", 37 | value: false, 38 | type: CommandOptions.Boolean, 39 | required: false 40 | }] 41 | }, { 42 | name: "pay", 43 | description: "Pay off your bounty", 44 | value: "pay", 45 | type: CommandOptions.SubCommand, 46 | }, { 47 | name: "view", 48 | description: "View all active bounties", 49 | value: "view", 50 | type: CommandOptions.SubCommand, 51 | }], 52 | SlashCommand: { 53 | /** 54 | * 55 | * @param {require("../structures/DayzRBot")} client 56 | * @param {import("discord.js").Message} message 57 | * @param {string[]} args 58 | * @param {*} param3 59 | */ 60 | run: async (client, interaction, args, { GuildDB }) => { 61 | 62 | if (!client.exists(GuildDB.Nitrado) || !client.exists(GuildDB.Nitrado.ServerID) || !client.exists(GuildDB.Nitrado.UserID) || !client.exists(GuildDB.Nitrado.Auth)) { 63 | const warnNitradoNotInitialized = new EmbedBuilder() 64 | .setColor(client.config.Colors.Yellow) 65 | .setDescription("**WARNING:** The DayZ Nitrado Server has not been configured for this guild yet. This command or feature is currently unavailable."); 66 | 67 | return interaction.send({ embeds: [warnNitradoNotInitialized], flags: (1 << 6) }); 68 | } 69 | 70 | let banking; 71 | if (args[0].name == 'set' || args[0].name == 'pay') { 72 | banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking); 73 | 74 | if (!banking) { 75 | banking = await createUser(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, client) 76 | if (!client.exists(banking)) return client.sendInternalError(interaction, err); 77 | } 78 | banking = banking.user; 79 | 80 | if (!client.exists(banking.guilds[GuildDB.serverID])) { 81 | const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance); 82 | if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); 83 | } 84 | } 85 | 86 | if (args[0].name == 'set') { 87 | 88 | let playerStat = await client.dbo.collection("players").findOne({"gamertag": args[0].options[0].value}); 89 | 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 `.')] }); 90 | 91 | if (args[0].options[1].value > banking.guilds[GuildDB.serverID].balance) { 92 | let nsf = new EmbedBuilder() 93 | .setDescription('**Bank Notice:** NSF. Non sufficient funds') 94 | .setColor(client.config.Colors.Red); 95 | 96 | return interaction.send({ embeds: [nsf] }); 97 | } 98 | 99 | const newBalance = banking.guilds[GuildDB.serverID].balance - args[0].options[1].value; 100 | 101 | client.dbo.collection("users").updateOne({ "user.userID": interaction.member.user.id }, { 102 | $set: { 103 | [`user.guilds.${GuildDB.serverID}.balance`]: newBalance, 104 | } 105 | }, (err, res) => { 106 | if (err) return client.sendInternalError(interaction, err); 107 | }); 108 | 109 | let anonymous = args[0].options[2]; 110 | 111 | playerStat.bounties.push({ 112 | setBy: (anonymous && !anonymous.value) ? interaction.member.user.id : null, 113 | value: args[0].options[1].value, 114 | }); 115 | playerStat.bountiesLength = playerStat.bounties.length; // Will ensure bounties length = # of bounties, even if bountiesLength does not exists in player stat. 116 | 117 | await UpdatePlayer(client, playerStat, interaction); 118 | 119 | const successEmbed = new EmbedBuilder() 120 | .setTitle('Success') 121 | .setDescription(`Successfully set a **$${args[0].options[1].value.toFixed(2).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** bounty on \` ${playerStat.gamertag} \`\nThis can be viewed using `) 122 | .setColor(client.config.Colors.Green); 123 | 124 | return interaction.send({ embeds: [successEmbed], flags: (1 << 6) }); 125 | 126 | } else if (args[0].name == 'pay') { 127 | 128 | let playerStat = await client.dbo.collection("players").findOne({"discordID": interaction.member.user.id}); 129 | 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.')] }); 130 | 131 | if (playerStat.bounties.length == 0) { 132 | const noBounty = new EmbedBuilder() 133 | .setColor(client.config.Colors.Yellow) 134 | .setDescription(`You have no bounties to pay off.`) 135 | 136 | return interaction.send({ embeds: [noBounty] }); 137 | } 138 | 139 | let totalBounty = 0; 140 | for (let i = 0; i < playerStat.bounties.length; i++) { 141 | totalBounty += playerStat.bounties[i].value; 142 | } 143 | 144 | if (banking.guilds[GuildDB.serverID].balance.toFixed(2) - (totalBounty * 2) < 0) { 145 | let embed = new EmbedBuilder() 146 | .setTitle('**Bank Notice:** NSF. Non sufficient funds') 147 | .setColor(client.config.Colors.Red); 148 | 149 | return interaction.send({ embeds: [embed], flags: (1 << 6) }); 150 | } 151 | 152 | const newBalance = banking.guilds[GuildDB.serverID].balance - (totalBounty * 2); 153 | 154 | await client.dbo.collection("users").updateOne({"user.userID":interaction.member.user.id},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => { 155 | if (err) return client.sendInternalError(interaction, err); 156 | }); 157 | 158 | playerStat.bounties = []; 159 | playerStat.bountiesLength = 0; 160 | 161 | await UpdatePlayer(client, playerStat, interaction); 162 | 163 | const payedOff = new EmbedBuilder() 164 | .setColor(client.config.Colors.Green) 165 | .setDescription(`Successfully paid off **$${(totalBounty * 2).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** in bounties.`); 166 | 167 | return interaction.send({ embeds: [payedOff] }); 168 | 169 | } else if (args[0].name == 'view') { 170 | 171 | const activeBounties = await client.dbo.collection("players").find({ 172 | "bountiesLength": { $gt: 0 } 173 | }).toArray(); 174 | 175 | let bountiesEmbed = new EmbedBuilder() 176 | .setColor(client.config.Colors.Default) 177 | .setDescription('**Active Boutnies**'); 178 | 179 | if (activeBounties.length == 0) bountiesEmbed.setDescription('**There are No Active Boutnies**') 180 | for (let i = 0; i < activeBounties.length; i++) { 181 | for (let j = 0; j < activeBounties[i].bounties.length; j++) { 182 | bountiesEmbed.addFields({ name: `${activeBounties[i].gamertag} has a:`, value: `**$${activeBounties[i].bounties[j].value.toFixed(2).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** bounty set by ${activeBounties[i].bounties[j].setBy == null ? 'Anonymous' : `<@${activeBounties[i].bounties[j].setBy}>`}`, inline: false }); 183 | } 184 | } 185 | 186 | return interaction.send({ embeds: [bountiesEmbed] }); 187 | } 188 | }, 189 | }, 190 | } -------------------------------------------------------------------------------- /commands/claim.js: -------------------------------------------------------------------------------- 1 | const { ActionRowBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js'); 2 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 3 | const { Armbands } = require('../database/armbands.js'); 4 | 5 | module.exports = { 6 | name: "claim", 7 | debug: false, 8 | global: false, 9 | description: "Claim an available armband for your faction", 10 | usage: "[role]", 11 | permissions: { 12 | channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], 13 | member: [], 14 | }, 15 | options: [{ 16 | name: "faction_role", 17 | description: "Claim an armband for this faction role", 18 | value: "faction_role", 19 | type: CommandOptions.Role, 20 | required: true, 21 | }], 22 | SlashCommand: { 23 | /** 24 | * 25 | * @param {require("../structures/DayzRBot")} client 26 | * @param {import("discord.js").Message} message 27 | * @param {string[]} args 28 | * @param {*} param3 29 | */ 30 | run: async (client, interaction, args, { GuildDB }) => { 31 | if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) 32 | return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); 33 | 34 | // Handle invalid roles 35 | let des; 36 | if (GuildDB.excludedRoles.includes(args[0].value)) des = '**Notice:**\n> This role has been configured to be excluded to claim an armband.'; 37 | if (!interaction.member.roles.includes(args[0].value)) des = '**Notice:**\n> You cannot claim an armband for a role you don\'t have.'; 38 | if (des) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(des)], flags: (1 << 6) }); 39 | 40 | for (let roleID in Object(GuildDB.factionArmbands)) { 41 | if (interaction.member.roles.includes(roleID) && roleID != args[0].value) { 42 | return interaction.send({ embeds: [ 43 | new EmbedBuilder() 44 | .setColor(client.config.Colors.Yellow) 45 | .setDescription('**Notice:**\n> You already have another role with a claimed flag.') 46 | ], flags: (1 << 6) }) 47 | } 48 | } 49 | 50 | // If this faction has an existing record in the db 51 | if (GuildDB.factionArmbands[args[0].value]) { 52 | const warnArmbadChange = new EmbedBuilder() 53 | .setColor(client.config.Colors.Yellow) 54 | .setDescription(`**Notice:**\n> The faction <@&${args[0].value}> already has an armband selected. Are you sure you would like to change this?`) 55 | 56 | const opt = new ActionRowBuilder() 57 | .addComponents( 58 | new ButtonBuilder() 59 | .setCustomId(`ChangeArmband-yes-${args[0].value}-${interaction.member.user.id}`) 60 | .setLabel("Yes") 61 | .setStyle(ButtonStyle.Success), 62 | new ButtonBuilder() 63 | .setCustomId(`ChangeArmband-no-${args[0].value}-${interaction.member.user.id}`) 64 | .setLabel("No") 65 | .setStyle(ButtonStyle.Secondary) 66 | ) 67 | 68 | return interaction.send({ embeds: [warnArmbadChange], components: [opt] }); 69 | } 70 | 71 | let available = new StringSelectMenuBuilder() 72 | .setCustomId(`Claim-${args[0].value}-1-${interaction.member.user.id}`) 73 | .setPlaceholder('Select an armband from list 1 to claim') 74 | 75 | let availableNext = new StringSelectMenuBuilder() 76 | .setCustomId(`Claim-${args[0].value}-2-${interaction.member.user.id}`) 77 | .setPlaceholder('Select an armband from list 2 to claim') 78 | 79 | let tracker = 0; 80 | for (let i = 0; i < Armbands.length; i++) { 81 | if (!GuildDB.usedArmbands.includes(Armbands[i].name)) { 82 | tracker++; 83 | data = { 84 | label: Armbands[i].name, 85 | description: 'Select this armband', 86 | value: Armbands[i].name, 87 | } 88 | if (tracker > 25) availableNext.addOptions(data); 89 | else available.addOptions(data); 90 | } 91 | } 92 | 93 | let compList = [] 94 | 95 | let opt = new ActionRowBuilder().addComponents(available); 96 | compList.push(opt) 97 | let opt2 = undefined; 98 | if (tracker > 25) { 99 | opt2 = new ActionRowBuilder().addComponents(availableNext); 100 | compList.push(opt2); 101 | } 102 | 103 | return interaction.send({ components: compList }); 104 | }, 105 | }, 106 | Interactions: { 107 | Claim: { 108 | run: async (client, interaction, GuildDB) => { 109 | if (!interaction.customId.endsWith(interaction.member.user.id)) 110 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 111 | 112 | let factionID = interaction.customId.split('-')[1]; 113 | 114 | let data = { 115 | faction: factionID, 116 | armband: interaction.values[0], 117 | }; 118 | 119 | let query = { 120 | $push: { 121 | 'server.usedArmbands': interaction.values[0] 122 | }, 123 | $set: { 124 | [`server.factionArmbands.${factionID}`]: data 125 | }, 126 | }; 127 | 128 | if (interaction.customId.split('-')[2] == 'update') { 129 | let removeQuery; 130 | for (const [fid, data] of Object.entries(GuildDB.factionArmbands)) { 131 | if (fid == factionID) removeQuery = data.armband; 132 | } 133 | client.dbo.collection("guilds").updateOne({'server.serverID': GuildDB.serverID}, {$pull: {'server.usedArmbands': removeQuery}}, (err, res) => { 134 | if (err) return client.sendInternalError(interaction, err); 135 | }) 136 | } 137 | 138 | client.dbo.collection("guilds").updateOne({'server.serverID': GuildDB.serverID}, query, (err, res) => { 139 | if (err) return client.sendInternalError(interaction, err); 140 | }) 141 | 142 | let armbandURL; 143 | 144 | for (let i = 0; i < Armbands.length; i++) { 145 | if (Armbands[i].name == interaction.values[0]) { 146 | armbandURL = Armbands[i].url; 147 | break; 148 | } 149 | } 150 | 151 | const success = new EmbedBuilder() 152 | .setColor(client.config.Colors.Default) 153 | .setDescription(`**Success!**\n> The faction <@&${factionID}> has now claimed ***${interaction.values[0]}***`) 154 | .setImage(armbandURL); 155 | 156 | return interaction.update({ embeds: [success], components: [] }); 157 | } 158 | }, 159 | 160 | ChangeArmband: { 161 | run: async (client, interaction, GuildDB) => { 162 | if (!interaction.customId.endsWith(interaction.member.user.id)) 163 | return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); 164 | 165 | if (interaction.customId.split('-')[1]=='yes') { 166 | let available = new StringSelectMenuBuilder() 167 | .setCustomId(`Claim-${interaction.customId.split('-')[2]}-update-1-${interaction.member.user.id}`) 168 | .setPlaceholder('Select an armband from list 1 to claim') 169 | 170 | let availableNext = new StringSelectMenuBuilder() 171 | .setCustomId(`Claim-${interaction.customId.split('-')[2]}-update-2-${interaction.member.user.id}`) 172 | .setPlaceholder('Select an armband from list 2 to claim') 173 | 174 | let tracker = 0; 175 | for (let i = 0; i < Armbands.length; i++) { 176 | if (!GuildDB.usedArmbands.includes(Armbands[i].name)) { 177 | tracker++; 178 | data = { 179 | label: Armbands[i].name, 180 | description: 'Select this armband', 181 | value: Armbands[i].name, 182 | } 183 | if (tracker > 25) availableNext.addOptions(data); 184 | else available.addOptions(data); 185 | } 186 | } 187 | 188 | let compList = [] 189 | 190 | let opt = new ActionRowBuilder().addComponents(available); 191 | compList.push(opt) 192 | let opt2 = undefined; 193 | if (tracker > 25) { 194 | opt2 = new ActionRowBuilder().addComponents(availableNext); 195 | compList.push(opt2); 196 | } 197 | 198 | return interaction.update({ embeds: [], components: compList }); 199 | 200 | } else { 201 | const cancel = new EmbedBuilder() 202 | .setColor(client.config.Colors.Default) 203 | .setDescription('**Canceled**\n> Your factions armband will remain the same'); 204 | 205 | return interaction.update({ embeds: [cancel], components: [] }); 206 | } 207 | } 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributing 3 | 4 | Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. 5 | 6 | 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. 7 | Don't forget to give the project a star! Thanks again! 8 | 9 | ***Explore the docs »*** 10 | * [README](#readme) 11 | * [License](#license) 12 | * [General Contributing Guidelines](#general-contributing-guidlines) 13 | * [Creating A New Command](#creating-a-new-command) 14 | * [Handling Non Command Interactions](#handling-non-command-interactions) 15 | * 16 | 17 | ## README 18 | 19 | Before you get started contributing, it would be an excellent idea to checkout the `README.md` file! 20 | [» README](/README.md) 21 | 22 | ## License 23 | 24 | [» License](/LICENSE) 25 | 26 | ## General Contributing Guidlines 27 | 28 | When you are ready to start work on your own feature and would like to push it to the main repository. Follow these guidelines. 29 | 30 | 1. Clone the Project 31 | 2. Create your Feature Branch (`git checkout -b update/AmazingFeature`) 32 | 3. Commit your Changes (`git commit -m 'update/your-update'`) please use the following for your commits: 33 | i. `update/your-update` 34 | ii. `fix/your-fix` 35 | iii. `refactor/your-refactor` (Refactoring code, doesn't change behavior) 36 | iv. `change/your-change` (Changing existing code behavior) 37 | 4. Push to the Branch (`git push origin update/AmazingFeature`) 38 | 5. Open a Pull Request 39 | 40 | Do keep in mind of the [package.json](/package.json) version. Version structure is as follows: `(major).(minor).(patch)` 41 | 42 | ## Creating A New Command 43 | 44 | 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. 45 | 46 | 1. Create a new command file in the `/commands` folder. 47 | 2. Name this file as the name of the command. E.g. `new-command.js` 48 | 3. Use the following template to start your command file: 49 | ```javascript 50 | const { EmbedBuilder } = require('discord.js'); // Not required, but encouraged to use embeds to reply to commands. 51 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; // Not required but recommended for clear cmd options. 52 | 53 | module.exports = { 54 | name: "new-command", // Insert your command name here, I encourage that you use hyphens `-` to seperate words. 55 | debug: false, // Do not change this 56 | global: false, // Do not change this 57 | description: "My command Description", // Describe your command 58 | usage: "", // Insert command parameters here E.g. useage: "[cmd param 1] [cmd param 2]" 59 | options: [ 60 | // Below example of a command option 61 | { 62 | name: "cmd_param_1", 63 | description: "What this parameter is for", 64 | value: "cmd_param_1_default", // Default value of this parameter 65 | type: CommandOptions.String, 66 | required: true, 67 | } 68 | ], 69 | SlashCommand: { // Do not change the name of this funciton 70 | /** 71 | * 72 | * @param {require("../structures/DayzRBot")} client 73 | * @param {import("discord.js").Message} message 74 | * @param {string[]} args 75 | * @param {*} param3 76 | */ 77 | run: async (client, interaction, args, { GuildDB }, start) => { // Do not change the name of this function, or change the parameters. 78 | 79 | // Do your command stuff here ... 80 | 81 | /* 82 | Optionally if your command will take longer than 3 seconds to do its stuff 83 | You can easily defer your interaction reply as seen below: 84 | 85 | await interaction.deferReply({ optional_data_here }); 86 | 87 | If you use the deferReply, in order to update the message when the command is complete, use the following: 88 | 89 | return interaction.editReply({ return_data_here }) 90 | */ 91 | 92 | // If you do not use defer reply, you can use this to complete your command interaction. 93 | return interaction.send({ embeds: [ 94 | new EmbedBuilder() 95 | .setColor(client.config.Colors.Green) 96 | .setDescription("Hooray! Your command is complete.") 97 | ] 98 | }); 99 | }, 100 | }, 101 | } 102 | ``` 103 | 104 | 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. 105 | All commands are automatically loaded from the `/commands` folder when the bot is started. 106 | 107 | ## Handling Non Command Interactions 108 | 109 | Adding additional interactions to your command? Buttons, Select Menus, etc? You can easily handle those interactions by doing the following. 110 | 111 | 1. Create an `Interactions` object within your command file. E.g. my new command `/commands/greet.js` will have the following: 112 | ```javascript 113 | const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, } = require('discord.js'); // Some additional imported definitions for our button. 114 | const CommandOptions = require('../util/CommandOptionTypes').CommandOptionTypes; 115 | 116 | module.exports = { 117 | name: "greet", 118 | debug: false, 119 | global: false, 120 | description: "Greet a name", 121 | usage: "", 122 | options: [{ 123 | name: "name", 124 | description: "Name to greet", 125 | value: "name", // Default value of this parameter 126 | type: CommandOptions.String, 127 | required: true, 128 | }], 129 | SlashCommand: { 130 | 131 | run: async (client, interaction, args, { GuildDB }, start) => { 132 | // Here is a simple example of this command using a button. 133 | 134 | let name = args[0].value 135 | 136 | /* 137 | Here are the button options, Hello and GoodBye. 138 | The custom ID for each button is VERY IMPORTANT, 139 | this is how we know what non-cmd interaction to 140 | call, and the values we choose to pass. 141 | 142 | E.g. 143 | The first part of the custom ID is Greet, the name 144 | of our non-cmd interaction handler. 145 | 146 | SEPERATING THE VALUES ARE HYPHENS "-" 147 | 148 | Next value is in this example, hello or goodbye 149 | depending on the button. 150 | 151 | The final value is the variable name we want to 152 | pass to our non-cmd interaciton. 153 | */ 154 | const opt = new ActionRowBuilder() 155 | .addComponents( 156 | 157 | new ButtonBuilder() 158 | .setCustomId(`Greet-hello-${name}`) 159 | .setLabel("Hello") 160 | .setStyle(ButtonStyle.Success), 161 | 162 | new ButtonBuilder() 163 | .setCustomId(`Greet-goodbye-${name}`) 164 | .setLabel("GoodBye") 165 | .setStyle(ButtonStyle.Secondary) 166 | 167 | ) 168 | 169 | // The cmd-interaction sends the two button options to the user to click. That is the end of our CMD-INTERACTION. 170 | return interaction.send({ components: [opt] }); 171 | } 172 | }, 173 | 174 | // Below is my Interactions object that will define any non-cmd interactions this command will use. 175 | Interactions: { 176 | 177 | // 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. 178 | // It is very important the name of our non-cmd interaction matches the name we call in our Button's custom ID. 179 | Greet: { 180 | // The handler I've written connects our button interaction to this function, and passes the following variables to this run function. 181 | run: async (client, interaction, GuildDB) => { 182 | 183 | // Here is the code we'll write to complete our button interaction. 184 | 185 | let greeting = interaction.customId.split('-')[1]; // Get either hello or goodbye as our greeting 186 | let name = interaction.customId.split('-')[2]; // Get the name from the interaction id. 187 | 188 | let phrase = `${greeting} ${name}!`; 189 | 190 | // We clear the buttons away, and send our phrase with our greeting from the buttons. 191 | return interaction.update({ content: phrase, components: [] }); 192 | } 193 | } 194 | } 195 | } 196 | ``` 197 | 198 | This is all you need to do to create a non-cmd interaction for buttons, menus, etc. 199 | -------------------------------------------------------------------------------- /util/AlarmsHandler.js: -------------------------------------------------------------------------------- 1 | const { BanPlayer, UnbanPlayer } = require('./NitradoAPI'); 2 | const { EmbedBuilder } = require('discord.js'); 3 | const { nearest } = require('../database/destinations'); 4 | const { GetGuild } = require('../database/guild'); 5 | const { GetWebhook, WebhookSend } = require("../util/WebhookHandler"); 6 | 7 | // Private functions (only called locally) 8 | 9 | const ExpireEvent = async(client, guild, e) => { 10 | let hasMR = (guild.memberRole != ""); 11 | const channel = client.GetChannel(e.channel); 12 | if (client.exists(e.channel)) channel.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription(`${hasMR ? `<@&${guild.memberRole}>\n`:''}**The ${e.name} Event has ended!**`)] }); 13 | 14 | client.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, { 15 | $pull: { 16 | "server.events": e 17 | } 18 | }, (err, res) => { 19 | if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err); 20 | }); 21 | } 22 | 23 | const HandlePlayerTrackEvent = async (client, guild, e) => { 24 | if (!client.exists(e.channel)) return ExpireEvent(client, guild, e); // Expire event since it has invalid channel. 25 | const channel = client.GetChannel(e.channel); 26 | if (!channel) return; 27 | 28 | let player = await client.dbo.collection("players").findOne({"gamertag": e.gamertag}); 29 | 30 | let newDt = await client.getDateEST(player.time); 31 | let unixTime = Math.floor(newDt.getTime()/1000); 32 | 33 | const destination = nearest(player.pos, guild.Nitrado.Mission); 34 | 35 | const trackEvent = new EmbedBuilder() 36 | .setColor(client.config.Colors.Default) 37 | .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 \n${destination}`); 38 | 39 | const NAME = "DayZ.R Player Tracker"; 40 | const webhook = await GetWebhook(client, NAME, e.channel); 41 | 42 | let content = { embeds: [trackEvent] }; 43 | if (client.exists(guild.adminRole)) content.content = `<@&${e.role}>`; 44 | WebhookSend(client, webhook, content); 45 | 46 | // if (e.role) channel.send({ content: `<@&${e.role}>`, embeds: [trackEvent] }); 47 | // else channel.send({ embeds: [trackEvent] }); 48 | 49 | let now = new Date(); 50 | let diff = ((now - e.creationDate) / 1000) / 60; 51 | let minutesBetweenDates = Math.abs(Math.round(diff)); 52 | 53 | if (minutesBetweenDates >= e.time) ExpireEvent(client, guild, e); 54 | } 55 | 56 | // Public functions (called externally) 57 | 58 | module.exports = { 59 | 60 | HandleAlarmsAndUAVs: async (client, guild, data) => { 61 | 62 | for (let i = 0; i < guild.alarms.length; i++) { 63 | let alarm = guild.alarms[i]; 64 | let now = new Date(); 65 | if (alarm.uavExpire!=null&&alarm.uavExpire**\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`) 86 | .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) 87 | ); 88 | 89 | BanPlayer(client, data.player); 90 | return; 91 | } 92 | 93 | client.alarmPingQueue.get(guild.serverID).get(alarm.channel).get(route).push( 94 | new EmbedBuilder() 95 | .setColor(client.config.Colors.Default) 96 | .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`) 97 | .addFields({ name: '**Location**', value: `**[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})**`, inline: false }) 98 | ); 99 | 100 | return; 101 | } 102 | } 103 | 104 | for (let i = 0; i < guild.uavs.length; i++) { 105 | let uav = guild.uavs[i]; 106 | 107 | let diff = [Math.round(uav.origin[0] - data.pos[0]), Math.round(uav.origin[1] - data.pos[1])]; 108 | let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2); 109 | 110 | if (distance < uav.radius) { 111 | let newDt = await client.getDateEST(data.time); 112 | let unixTime = Math.floor(newDt.getTime()/1000); 113 | 114 | const destination = nearest(data.pos, guild.Nitrado.Mission); 115 | 116 | let uavEmbed = new EmbedBuilder() 117 | .setColor(client.config.Colors.Default) 118 | .setDescription(`**UAV Detection - **\n**${data.player}** was spotted in the UAV zone at **[${data.pos[0]}, ${data.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.pos[0]};${data.pos[1]})\n${destination}**`) 119 | 120 | client.users.fetch(uav.owner, false).then((user) => { 121 | user.send({ embeds: [uavEmbed] }); 122 | }); 123 | } 124 | } 125 | }, 126 | 127 | HandleExpiredUAVs: async (client, guild) => { 128 | let uavs = guild.uavs; 129 | let update = false; 130 | 131 | for (let i = 0; i < uavs.length; i++) { 132 | let uav = uavs[i]; 133 | 134 | let now = new Date(); 135 | let diff = Math.round((now.getTime() - uav.creationDate.getTime()) / 1000 / 60); // diff minutes 136 | 137 | if (diff <= 30) continue; 138 | 139 | uavs.splice(i, 1); 140 | update = true; 141 | 142 | let expired = new EmbedBuilder().setColor(client.config.Colors.Red).setDescription("**Low Battery**\nUAV has run out of battery and is no longer active."); 143 | 144 | client.users.fetch(uav.owner, false).then((user) => { 145 | user.send({ embeds: [expired] }); 146 | }); 147 | } 148 | 149 | if (update) { 150 | client.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, {$set: { "server.uavs": uavs }}, (err, res) => { 151 | if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err); 152 | }); 153 | } 154 | }, 155 | 156 | KillInAlarm: async (client, guildId, data) => { 157 | 158 | let guild = await GetGuild(client, guildId); 159 | 160 | for (let i = 0; i < guild.alarms.length; i++) { 161 | let alarm = guild.alarms[i]; 162 | if (alarm.disabled || !alarm.rules.includes('ban_on_kill')) continue; // ignore if alarm is disabled or not ban on kill; 163 | if (alarm.ignoredPlayers.includes(data.killerID)) continue; 164 | 165 | let diff = [Math.round(alarm.origin[0] - data.killerPOS[0]), Math.round(alarm.origin[1] - data.killerPOS[1])]; 166 | let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2) 167 | 168 | if (distance < alarm.radius) { 169 | const channel = client.GetChannel(alarm.channel); 170 | if (!channel) continue; 171 | 172 | let newDt = await client.getDateEST(data.time); 173 | let unixTime = Math.floor(newDt.getTime()/1000); 174 | 175 | let alarmEmbed = new EmbedBuilder() 176 | .setColor(client.config.Colors.Default) 177 | .setDescription(`**Zone Ping - **\n**${data.killer}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for killing **${data.victim}**.__`) 178 | .addFields({ name: '**Location**', value: `**[${data.killerPOS[0]}, ${data.killerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${data.killerPOS[0]};${data.killerPOS[1]})**`, inline: false }) 179 | 180 | const NAME = "DayZ.R Zone Alert"; 181 | const webhook = await GetWebhook(client, NAME, alarm.channel); 182 | 183 | let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }; 184 | WebhookSend(client, webhook, content); 185 | 186 | // channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }); 187 | 188 | BanPlayer(client, data.killer); 189 | break; 190 | } 191 | } 192 | return; 193 | }, 194 | 195 | PlaceFireplaceInAlarm: async (client, guild, line) => { 196 | 197 | let fireplacePlacement = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\) placed Fireplace/g; 198 | let data = [...line.matchAll(fireplacePlacement)][0]; 199 | if (!data) return; 200 | 201 | let info = { 202 | time: data[1], 203 | player: data[2], 204 | playerID: data[3], 205 | playerPOS: data[4].split(', ').map(v => parseFloat(v)), 206 | }; 207 | 208 | for (let i = 0; i < guild.alarms.length; i++) { 209 | let alarm = guild.alarms[i]; 210 | if (alarm.disabled || !alarm.rules.includes('ban_on_fireplace_placement')) continue; 211 | if (alarm.ignoredPlayers.includes(info.playerID)) continue; 212 | 213 | let diff = [Math.round(alarm.origin[0] - info.playerPOS[0]), Math.round(alarm.origin[1] - info.playerPOS[1])]; 214 | let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2); 215 | 216 | if (distance < alarm.radius) { 217 | const channel = client.GetChannel(alarm.channel); 218 | if (!channel) return; 219 | 220 | let newDt = await client.getDateEST(info.time); 221 | let unixTime = Math.floor(newDt.getTime()/1000); 222 | 223 | let alarmEmbed = new EmbedBuilder() 224 | .setColor(client.config.Colors.Default) 225 | .setDescription(`**Zone Ping - **\n**${info.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned for **placing a fireplace**.__`) 226 | .addFields({ name: '**Location**', value: `**[${info.playerPOS[0]}, ${info.playerPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.playerPOS[0]};${info.playerPOS[1]})**`, inline: false }) 227 | 228 | const NAME = "DayZ.R Zone Alert"; 229 | const webhook = await GetWebhook(client, NAME, alarm.channel); 230 | 231 | let content = { content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }; 232 | WebhookSend(client, webhook, content); 233 | 234 | // channel.send({ content: `<@&${alarm.role}>`, embeds: [alarmEmbed] }); 235 | 236 | BanPlayer(client, info.player); 237 | break; 238 | } 239 | } 240 | return; 241 | }, 242 | 243 | HandleEvents: async (client, guild) => { 244 | for (let i = 0; i < guild.events.length; i++) { 245 | let event = guild.events[i]; 246 | if (event.type == 'player-track') HandlePlayerTrackEvent(client, guild, event); 247 | } 248 | }, 249 | } 250 | -------------------------------------------------------------------------------- /config/config.js: -------------------------------------------------------------------------------- 1 | const package = require('../package.json'); 2 | require('dotenv').config(); 3 | 4 | const PresenceTypes = { 5 | Playing: 0, 6 | Streaming: 1, 7 | Listening: 2, 8 | Watching: 3, 9 | Custom: 4, 10 | Competing: 5, 11 | }; 12 | 13 | const PresenceStatus = { 14 | Online: "online", 15 | Offline: "offline", 16 | Idle: "idle", 17 | DoNotDisturb: "dnd", 18 | }; 19 | 20 | module.exports = { 21 | Dev: process.env.Dev || "DEV.", 22 | Version: package.version, // (major).(minor).(patch) 23 | Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot 24 | SupportServer: "https://discord.gg/KVFJCvvFtK", // Support Server Link 25 | Token: process.env.token || "", //Discord Bot Token 26 | SecretKey: process.env.key || "01234567891", 27 | SecretIv: process.env.iv || "9876543210", 28 | EncryptionMethod: process.env.encryptionMethod || "aes-256-cbc", 29 | Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes 30 | IconURL: "https://cdn.discordapp.com/app-icons/1049045393415098450/f8e7f76ac9e843360b989c796fc21990.png?size=256", 31 | AvatarData: "data:image/png;base64,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", 32 | Colors: { 33 | Default: "#8a7c72", 34 | DarkRed: "#ba0f0f", 35 | Red: "#f55c5c", 36 | Green: "#32a852", 37 | Yellow: "#ffb01f" 38 | }, 39 | Permissions: 2205281600, 40 | mongoURI: process.env.mongoURI || "mongodb://localhost:27017", 41 | dbo: process.env.dbo || "knoldus", 42 | Presence: { 43 | type: PresenceTypes.Watching, 44 | name: "DayZ Logs", // What message you want after type 45 | status: PresenceStatus.Online 46 | }, 47 | } 48 | -------------------------------------------------------------------------------- /util/LogsHandler.js: -------------------------------------------------------------------------------- 1 | const { EmbedBuilder } = require('discord.js'); 2 | const { HandleAlarmsAndUAVs } = require('./AlarmsHandler'); 3 | const { SendConnectionLogs, DetectCombatLog } = require('./AdminLogsHandler'); 4 | const { getDefaultPlayer } = require('../database/player'); 5 | const { FetchServerSettings } = require('../util/NitradoAPI'); 6 | const { UpdatePlayer, insertPVPstats, createWeaponStats } = require('../database/player') 7 | const { Missions } = require('../database/destinations'); 8 | const { GetWebhook, WebhookSend, WebhookMessageEdit } = require("../util/WebhookHandler"); 9 | 10 | module.exports = { 11 | 12 | HandlePlayerLogs: async (NitradoServerID, client, GuildDB, line, combatLogTimer = 5) => { 13 | 14 | const connectTemplate = /(.*) \| Player \"(.*)\" is connected \(id=(.*)\)/g; 15 | const disconnectTemplate = /(.*) \| Player \"(.*)\"\(id=(.*)\) has been disconnected/g; 16 | const positionTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g; 17 | const damageTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; 18 | const deadTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; 19 | 20 | if (line.includes(' connected')) { 21 | const data = [...line.matchAll(connectTemplate)][0]; 22 | if (!data) return; 23 | 24 | const info = { 25 | time: data[1], 26 | player: data[2], 27 | playerID: data[3], 28 | }; 29 | 30 | if (!client.exists(info.player) || !client.exists(info.playerID)) return; 31 | 32 | let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID}); 33 | if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID); 34 | const newDt = await client.getDateEST(info.time); 35 | 36 | playerStat.lastConnectionDate = newDt; 37 | playerStat.connected = true; 38 | if (!client.exists(playerStat.connections)) playerStat.connections = 0; 39 | playerStat.connections++; 40 | 41 | // Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts). 42 | if (client.playerSessions.get(NitradoServerID).has(info.playerID)) { 43 | // Player is already in a session, update the session's end time. 44 | const session = client.playerSessions.get(NitradoServerID).get(info.playerID); 45 | session.endTime = newDt; // Update end time. 46 | } else { 47 | // Player is not in a session, create a new session. 48 | const newSession = { 49 | startTime: newDt, 50 | endTime: null, // Initialize end time as null. 51 | }; 52 | client.playerSessions.get(NitradoServerID).set(info.playerID, newSession); 53 | } 54 | 55 | await SendConnectionLogs(client, GuildDB, { 56 | time: info.time, 57 | player: info.player, 58 | connected: true, 59 | lastConnectionDate: null, 60 | }); 61 | 62 | await UpdatePlayer(client, playerStat); 63 | } 64 | 65 | if (line.includes(' disconnected')) { 66 | const data = [...line.matchAll(disconnectTemplate)][0]; 67 | if (!data) return; 68 | 69 | const info = { 70 | time: data[1], 71 | player: data[2], 72 | playerID: data[3], 73 | }; 74 | 75 | if (!client.exists(info.player) || !client.exists(info.playerID)) return; 76 | 77 | let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID}); 78 | if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID); 79 | 80 | let oldUnixTime; 81 | let sessionTimeSeconds; 82 | const newDt = await client.getDateEST(info.time); 83 | const unixTime = Math.round(newDt.getTime() / 1000); // Seconds 84 | if (playerStat.lastConnectionDate != null) { 85 | oldUnixTime = Math.round(playerStat.lastConnectionDate.getTime() / 1000); // Seconds 86 | sessionTimeSeconds = unixTime - oldUnixTime; 87 | } else sessionTimeSeconds = 0; 88 | if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0; 89 | 90 | playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds; 91 | playerStat.lastSessionTime = sessionTimeSeconds; 92 | playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime; 93 | playerStat.lastDisconnectionDate = newDt; 94 | playerStat.connected = false; 95 | 96 | await SendConnectionLogs(client, GuildDB, { 97 | time: info.time, 98 | player: info.player, 99 | connected: false, 100 | lastConnectionDate: playerStat.lastConnectionDate, 101 | }); 102 | 103 | if (combatLogTimer != 0) { 104 | await DetectCombatLog(client, GuildDB, { 105 | time: info.time, 106 | player: info.player, 107 | pos: playerStat.pos, 108 | lastDamageDate: playerStat.lastDamageDate, 109 | lastHitBy: playerStat.lastHitBy, 110 | lastDeathDate: playerStat.lastDeathDate, 111 | combatLogTimer: combatLogTimer, 112 | }); 113 | } 114 | 115 | await UpdatePlayer(client, playerStat); 116 | } 117 | 118 | if (line.includes('pos=<') && !line.includes('hit by')) { 119 | const data = [...line.matchAll(positionTemplate)][0]; 120 | if (!data) return; 121 | 122 | const info = { 123 | time: data[1], 124 | player: data[2], 125 | playerID: data[3], 126 | pos: data[4].split(', ').map(v => parseFloat(v)) 127 | }; 128 | 129 | if (!client.exists(info.player) || !client.exists(info.playerID)) return; 130 | 131 | let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID}); 132 | if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID); 133 | if (!client.exists(playerStat.lastConnectionDate)) playerStat.lastConnectionDate = await client.getDateEST(info.time); 134 | 135 | playerStat.lastPos = playerStat.pos; 136 | playerStat.pos = info.pos; 137 | playerStat.lastTime = playerStat.time; 138 | playerStat.lastDate = playerStat.date; 139 | playerStat.time = `${info.time} EST`; 140 | playerStat.date = await client.getDateEST(info.time); 141 | 142 | if (line.includes('hit by') || line.includes('killed by')) return; // prevent additional information from being fed to Alarms & UAVs 143 | 144 | await HandleAlarmsAndUAVs(client, GuildDB, { 145 | time: info.time, 146 | player: info.player, 147 | playerID: info.playerID, 148 | pos: info.pos, 149 | }); 150 | 151 | await UpdatePlayer(client, playerStat) 152 | } 153 | 154 | if (line.includes('hit by Player')) { 155 | const data = line.includes('(DEAD)') ? [...line.matchAll(deadTemplate)][0] : [...line.matchAll(damageTemplate)][0]; 156 | if (!data) return; 157 | 158 | const info = { 159 | time: data[1], 160 | player: data[2], 161 | playerID: data[3], 162 | attacker: data[6], 163 | attackerID: data[7], 164 | bodyPart: data[9].split("(")[0], 165 | weapon: data[12], 166 | }; 167 | 168 | if (!client.exists(info.player) || !client.exists(info.playerID) || !client.exists(info.attacker) || !client.exists(info.attackerID)) return; 169 | 170 | let playerStat = await client.dbo.collection("players").findOne({"playerID": info.playerID}); 171 | let attackerStat = await client.dbo.collection("players").findOne({"playerID": info.attackerID}); 172 | if (!client.exists(playerStat)) playerStat = getDefaultPlayer(info.player, info.playerID, NitradoServerID); 173 | if (!client.exists(attackerStat)) attackerStat = getDefaultPlayer(info.attacker, info.attackerID, NitradoServerID); 174 | 175 | playerStat.lastDamageDate = await client.getDateEST(info.time); 176 | playerStat.lastHitBy = info.attacker; 177 | 178 | if (!client.exists(playerStat.shotsLanded)) playerStat = insertPVPstats(playerStat); 179 | if (!client.exists(attackerStat.shotsLanded)) attackerStat = insertPVPstats(attackerStat); 180 | 181 | // Update in depth PVP stats if non Melee weapon 182 | if (info.weapon.includes("Engraved")) info.weapon = info.weapon.split("Engraved ")[1]; 183 | if (info.weapon.includes("Sawed-off")) info.weapon = info.weapon.split("Sawed-off ")[1]; 184 | if (info.weapon in playerStat.weaponStats) { 185 | playerStat.timesShot++; 186 | playerStat.timesShotPerBodyPart[info.bodyPart]++; 187 | if (!client.exists(playerStat.weaponStats[info.weapon])) playerStat = createWeaponStats(playerStat, info.weapon); 188 | playerStat.weaponStats[info.weapon].timesShot++; 189 | playerStat.weaponStats[info.weapon].timesShotPerBodyPart[info.bodyPart]++; 190 | 191 | attackerStat.shotsLanded++; 192 | attackerStat.shotsLandedPerBodyPart[info.bodyPart]++; 193 | if (!client.exists(attackerStat.weaponStats[info.weapon])) attackerStat = createWeaponStats(attackerStat, info.weapon); 194 | attackerStat.weaponStats[info.weapon].shotsLanded++; 195 | attackerStat.weaponStats[info.weapon].shotsLandedPerBodyPart[info.bodyPart]++; 196 | } 197 | 198 | await UpdatePlayer(client, playerStat); 199 | await UpdatePlayer(client, attackerStat); 200 | } 201 | 202 | return; 203 | }, 204 | 205 | HandleActivePlayersList: async (nitrado_cred, client, guild) => { 206 | client.activePlayersTick = 0; // reset hour tick 207 | 208 | if (!client.exists(guild.activePlayersChannel)) return; 209 | const channel = client.GetChannel(guild.activePlayersChannel); 210 | if (!channel) return; 211 | 212 | const data = await FetchServerSettings(nitrado_cred, client, 'HandleActivePlayersList'); // Fetch server status 213 | const e = data && data !== 1; // Check if data exists 214 | 215 | const hostname = e ? data.data.gameserver.settings.config.hostname : 'N/A'; 216 | const map = Missions[data.data.gameserver.settings.config.mission]; 217 | const status = e ? data.data.gameserver.status : 'N/A'; 218 | const slots = e ? data.data.gameserver.slots : 'N/A'; 219 | const playersOnline = e ? data.data.gameserver.query.player_current : undefined; 220 | 221 | const Statuses = { 222 | "started": {emoji: "🟢", text: "Active"}, 223 | "stopped": {emoji: "🔴", text: "Stopped"}, 224 | "restarting": {emoji: "↻", text: "Restarting"}, 225 | }; 226 | 227 | const emojiStatus = Statuses[status].emoji || "❓"; 228 | const textStatus = Statuses[status].text || "Unknown Status"; 229 | 230 | let activePlayers = await client.dbo.collection("players").find({"nitradoServerID": nitrado_cred.ServerID}).toArray().filter(player => player.connected); 231 | 232 | let des = activePlayers.length > 0 ? `` : `**No Players Online**`; 233 | for (let i = 0; i < activePlayers.length; i++) { 234 | des += `**- ${activePlayers[i].gamertag}**\n`; 235 | } 236 | 237 | const nodes = activePlayers.length === 0; 238 | const serverEmbed = new EmbedBuilder() 239 | .setColor(client.config.Colors.Default) 240 | .setTitle(`Online List - \` ${playersOnline === undefined ? activePlayers.length : playersOnline} \` Player${playersOnline !== 1 ? 's' : ''} Online`) 241 | .addFields( 242 | { name: 'Server:', value: `\` ${hostname} \``, inline: false }, 243 | { name: 'Map:', value: `\` ${map} \``, inline: true }, 244 | { name: 'Status:', value: `\` ${emojiStatus} ${textStatus} \``, inline: true }, 245 | { name: 'Slots:', value: `\` ${slots} \``, inline: true } 246 | ); 247 | 248 | const activePlayersEmbed = new EmbedBuilder() 249 | .setColor(client.config.Colors.Default) 250 | .setTimestamp() 251 | .setTitle(`Players Online:`) 252 | .setDescription(des || (nodes ? "No Players Online :(" : "")); 253 | 254 | const NAME = "DayZ.R Admin Logs"; 255 | const webhook = await GetWebhook(client, NAME, guild.connectionLogsChannel); 256 | 257 | let id = client.playerListMsgIds.get(guild.serverID); 258 | if (id == "") { 259 | id = await WebhookSend(client, webhook, { embeds: [serverEmbed, activePlayersEmbed] }).id; 260 | client.playerListMsgIds.set(guild.serverID, id); 261 | } else { 262 | WebhookMessageEdit(client, webhook, id, { embeds: [serverEmbed, activePlayersEmbed] }); 263 | } 264 | } 265 | }; 266 | -------------------------------------------------------------------------------- /util/NitradoAPI.js: -------------------------------------------------------------------------------- 1 | const { finished } = require('stream/promises'); 2 | const concat = require('concat-stream'); 3 | const { Readable } = require('stream'); 4 | const FormData = require('form-data'); 5 | const fs = require('fs'); 6 | const maxRetries = 5; 7 | const retryDelay = 5000; // 5 seconds 8 | 9 | // Private functions (only called locally) 10 | 11 | const UploadNitradoFile = async (nitrado_cred, client, remoteDir, remoteFilename, localFileDir) => { 12 | for (let retries = 0; retries <= maxRetries; retries++) { 13 | try { 14 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/upload?` + new URLSearchParams({ 15 | path: remoteDir, 16 | file: remoteFilename 17 | }), { 18 | method: "POST", 19 | headers: { 20 | "Authorization": nitrado_cred.Auth 21 | }, 22 | }).then(response => response.json()); 23 | 24 | let contents = fs.readFileSync(localFileDir, 'utf8'); 25 | 26 | const uploadRes = await fetch(res.data.token.url, { 27 | method: "POST", 28 | headers: { 29 | 'Content-Type': 'application/binary', 30 | token: res.data.token.token 31 | }, 32 | body: contents, 33 | }) 34 | if (!uploadRes.ok) { 35 | client.error(`Failed to upload file to Nitrado (${nitrado_cred.ServerID}): status: ${uploadRes.status}, message: ${res.statusText}: UploadNitradoFile`); 36 | if (retries === 2) return 1; // Return error status on the second failed status code. 37 | } else { 38 | return uploadRes; 39 | } 40 | } catch (error) { 41 | client.error(`UploadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`); 42 | if (retries === maxRetries) { 43 | client.error(`UploadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 44 | return 1; 45 | } 46 | } 47 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 48 | } 49 | } 50 | 51 | const HandlePlayerBan = async (nitrado_cred, client, gamertag, ban) => { 52 | const data = await module.exports.FetchServerSettings(nitrado_cred, client, 'HandlePlayerBan'); // Fetch server status 53 | 54 | if (data && data != 1) { 55 | let bans = data.data.gameserver.settings.general.bans; 56 | if (ban) bans += `\r\n${gamertag}`; 57 | else if (!ban) bans = bans.replace(gamertag, ''); 58 | else client.error("Incorrect Ban Option: HandlePlayerBan"); 59 | 60 | let category = 'general'; 61 | let key = 'bans'; 62 | return await module.exports.PostServerSettings(nitrado_cred, client, category, key, bans); // returns 1 (failed) or 0 (not failed) 63 | } 64 | } 65 | 66 | const GetRemoteDir = async (nitrado_cred, client, dir="") => { 67 | const dirParam = client.exists(dir) ? `?dir=${dir}` : ""; 68 | for (let retries = 0; retries <= maxRetries; retries++) { 69 | try { 70 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/list${dirParam}`, { 71 | headers: { 72 | "Authorization": nitrado_cred.Auth 73 | } 74 | }).then(response => 75 | response.json().then(data => data) 76 | ).then(res => res); 77 | 78 | if (res.status === "error") return 1; 79 | 80 | return res.data.entries; 81 | } catch (error) { 82 | client.error(`GetRemoteDir: Error connecting to server (${nitrado_cred.ServerID}): ${error}`); 83 | if (retries == maxRetries) { 84 | client.error(`GetRemoteDir: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 85 | return 1; 86 | } 87 | } 88 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 89 | } 90 | } 91 | 92 | // Public functions (called externally) 93 | 94 | module.exports = { 95 | 96 | DownloadNitradoFile: async(nitrado_cred, client, filename, outputDir) => { 97 | for (let retries = 0; retries <= maxRetries; retries++) { 98 | try { 99 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/file_server/download?file=${filename}`, { 100 | headers: { 101 | "Authorization": nitrado_cred.Auth 102 | } 103 | }).then(response => 104 | response.json().then(data => data) 105 | ).then(res => res); 106 | 107 | const stream = fs.createWriteStream(outputDir); 108 | if (!res.data || !res.data.token) { 109 | client.error(`Error downloading File "${filename}": message: ${res.message}: DownloadNitradoFile`); 110 | return 1; 111 | } 112 | const { body } = await fetch(res.data.token.url); 113 | await finished(Readable.fromWeb(body).pipe(stream)); 114 | return 0; 115 | } catch (error) { 116 | client.error(`DownloadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`); 117 | if (retries === maxRetries) { 118 | client.error(`DownloadNitradoFile: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 119 | return 1; 120 | } 121 | } 122 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 123 | } 124 | }, 125 | 126 | /* 127 | Export explicit function names; i.e BanPlayer() & UnbanPlayer() 128 | that call to the private parent function HandlePlayerBan() 129 | rather than write two whole different functions for each. 130 | */ 131 | 132 | BanPlayer: async (nitrado_cred, client, gamertag) => await HandlePlayerBan(nitrado_cred, client, gamertag, true), 133 | UnbanPlayer: async (nitrado_cred, client, gamertag) => await HandlePlayerBan(nitrado_cred, client, gamertag, false), 134 | 135 | RestartServer: async (nitrado_cred, client, restart_message, message) => { 136 | const params = { 137 | restart_message: restart_message, 138 | message: message 139 | }; 140 | for (let retries = 0; retries < maxRetries; retries++) { 141 | try { 142 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/restart`, { 143 | method: "POST", 144 | headers: { 145 | "Authorization": nitrado_cred.Auth, 146 | }, 147 | body: JSON.stringify(params) 148 | }); 149 | 150 | if (!res.ok) { 151 | client.error(`Failed to restart Nitrado server (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: RestartServer`); 152 | return 1; // Return error status on failed status code. 153 | } else { 154 | return 0; 155 | } 156 | } catch (error) { 157 | client.error(`RestartServer: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`); 158 | if (retries === maxRetries) { 159 | client.error(`RestartServer: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 160 | return 1; 161 | } 162 | } 163 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 164 | } 165 | }, 166 | 167 | FetchServerSettings: async (nitrado_cred, client, fetcher) => { 168 | for (let retries = 0; retries <= maxRetries; retries++) { 169 | try { 170 | // get current status 171 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers`, { 172 | headers: { 173 | "Authorization": nitrado_cred.Auth 174 | } 175 | }); 176 | 177 | if (!res.ok) { 178 | client.error(`Failed to get Nitrado server stats (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: ${fetcher} via FetchServerSettings`); 179 | if (res.status == 401) return 1; // return immediately if unauthorized 180 | if (retries === 2) return 1; // Return error status on the second failed status code. 181 | } else { 182 | const data = await res.json(); 183 | return data; 184 | } 185 | } catch (error) { 186 | client.error(`${fetcher} via FetchServerSettings: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`); 187 | if (retries === maxRetries) { 188 | client.error(`${fetcher} via FetchServerSettings: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 189 | return 1; 190 | } 191 | } 192 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 193 | } 194 | }, 195 | 196 | PostServerSettings: async (nitrado_cred, client, category, key, value) => { 197 | for (let retries = 0; retries <= maxRetries; retries++) { 198 | try { 199 | const formData = new FormData(); 200 | formData.append("category", category); 201 | formData.append("key", key); 202 | formData.append("value", value); 203 | formData.pipe(concat(data => { 204 | async function postData() { 205 | const res = await fetch(`https://api.nitrado.net/services/${nitrado_cred.ServerID}/gameservers/settings`, { 206 | method: "POST", 207 | credentials: 'include', 208 | headers: { 209 | ...formData.getHeaders(), 210 | "Authorization": nitrado_cred.Auth 211 | }, 212 | body: data, 213 | }); 214 | if (!res.ok) { 215 | client.error(`Failed to get post Nitrado server settings (${nitrado_cred.ServerID}): status: ${res.status}, message: ${res.statusText}: PostServerSettings`); 216 | if (retries === 2) return 1; // Return error status on the second failed status code. 217 | } else { 218 | const data = await res.json(); 219 | return data; 220 | } 221 | } 222 | postData(); 223 | })); 224 | return 0; 225 | } catch (error) { 226 | client.error(`PostServerSettings: Error connecting to server (${nitrado_cred.ServerID}): ${error.message}`); 227 | if (retries === maxRetries) { 228 | client.error(`PostServerSettings: Error connecting to server (${nitrado_cred.ServerID}) after ${maxRetries} retries`); 229 | return 1; 230 | } 231 | } 232 | await new Promise(resolve => setTimeout(resolve, retryDelay)); // Delay before retrying 233 | } 234 | }, 235 | 236 | CheckServerStatus: async (nitrado_cred, client) => { 237 | const data = await module.exports.FetchServerSettings(nitrado_cred, client, 'CheckServerStatus'); // Fetch server status 238 | 239 | if (data && data != 1) { 240 | if (data && data.data.gameserver.status === 'stopped') { 241 | 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}".`); 242 | // Write optional "restart_message" to set in the Nitrado server logs and send a notice "message" to your server community. 243 | restart_message = 'Server being restarted by periodic bot check.'; 244 | message = 'The server was restarted by periodic bot check!'; 245 | 246 | module.exports.RestartServer(nitrado_cred, client, restart_message, message); 247 | } 248 | } 249 | }, 250 | 251 | DisableBaseDamage: async (nitrado_cred, client, preference) => { 252 | const pref = preference ? '1' : '0'; 253 | const posted = await module.exports.PostServerSettings(nitrado_cred, client, "config", "disableBaseDamage", pref); 254 | if (posted == 1) return 1; 255 | 256 | const remoteDirs = await GetRemoteDir(nitrado_cred, client); 257 | if (remoteDirs == 1) return 1; 258 | const basePath = remoteDirs.filter(dir => dir.type == 'dir')[0].path 259 | const remoteDirsFromBase = await GetRemoteDir(nitrado_cred, client, basePath); 260 | if (remoteDirsFromBase == 1) return 1; 261 | const missionPath = remoteDirsFromBase[0].path; 262 | const cfggameplayPath = `${missionPath}/cfggameplay.json`; 263 | 264 | const jsonDir = `./logs/cfggameplay.json`; 265 | await module.exports.DownloadNitradoFile(nitrado_cred, client, cfggameplayPath, jsonDir); 266 | 267 | let gameplay = JSON.parse(fs.readFileSync(jsonDir)); 268 | gameplay.GeneralData.disableBaseDamage = preference; 269 | 270 | // write JSON to file 271 | fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2)); 272 | 273 | const uploaded = await UploadNitradoFile(nitrado_cred, client, missionPath, 'cfggameplay.json', jsonDir); 274 | if (uploaded == 1) return 1; 275 | 276 | return 0; 277 | }, 278 | 279 | DisableContainerDamage: async (nitrado_cred, client, preference) => { 280 | const pref = preference ? '1' : '0'; 281 | const posted = await module.exports.PostServerSettings(nitrado_cred, client, "config", "disableContainerDamage", pref); 282 | if (posted == 1) return 1; 283 | 284 | const remoteDirs = await GetRemoteDir(nitrado_cred, client); 285 | if (remoteDirs == 1) return 1; 286 | const basePath = remoteDirs.filter(dir => dir.type == 'dir')[0].path 287 | const remoteDirsFromBase = await GetRemoteDir(nitrado_cred, client, basePath); 288 | if (remoteDirsFromBase == 1) return 1; 289 | const missionPath = remoteDirsFromBase[0].path; 290 | const cfggameplayPath = `${missionPath}/cfggameplay.json`; 291 | 292 | const jsonDir = `./logs/cfggameplay.json`; 293 | await module.exports.DownloadNitradoFile(nitrado_cred, client, cfggameplayPath, jsonDir); 294 | 295 | let gameplay = JSON.parse(fs.readFileSync(jsonDir)); 296 | gameplay.GeneralData.disableContainerDamage = preference; 297 | 298 | // write JSON to file 299 | fs.writeFileSync(jsonDir, JSON.stringify(gameplay, null, 2)); 300 | 301 | const uploaded = await UploadNitradoFile(nitrado_cred, client, missionPath, 'cfggameplay.json', jsonDir); 302 | if (uploaded == 1) return 1; 303 | 304 | return 0; 305 | }, 306 | 307 | NitradoCredentialStatus: { 308 | FAILED: "FAILED", 309 | OK: "OK", 310 | }, 311 | } 312 | --------------------------------------------------------------------------------