diff --git a/commands/config.js b/commands/config.js index e8ceda5..ab8b2c1 100644 --- a/commands/config.js +++ b/commands/config.js @@ -90,6 +90,20 @@ module.exports = { required: true, }] }, + { + name: "active_players_channel", + description: "Set the channel for active players update", + value: "active_players_channel", + type: 1, + options: [{ + name: "channel", + description: "The channel to configure", + value: "channel", + type: 7, + channel_types: [0], // Restrict to text channel + required: true, + }] + }, { name: "linked_gt_role", description: "Access Role to give to users", @@ -382,6 +396,19 @@ module.exports = { return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].name == 'active_players_channel') { + const channel = args[0].options[0].value; + + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.activePlayersChannel": channel}}, function(err, res) { + if (err) return client.sendInternalError(interaction, err); + }); + + const successEmbed = new EmbedBuilder() + .setDescription(`Successfully set <#${channel}> as the Active Players Channel.`) + .setColor(client.config.Colors.Green); + + return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].name == 'linked_gt_role') { const role = args[0].options[0].value; diff --git a/commands/player-list.js b/commands/player-list.js index e69de29..624386a 100644 --- a/commands/player-list.js +++ b/commands/player-list.js @@ -0,0 +1,39 @@ +const { EmbedBuilder } = require('discord.js'); + +module.exports = { + name: "stats", + debug: true, + global: true, + description: "check bot statistics", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + options: [], + SlashCommand: { + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }, start) => { + + let activePlayers = GuildDB.playerstats.filter(p => p.connected); + + let des = ``; + for (let i = 0; i < activePlayers.length; i++) { + des += `**- ${activePlayers[i].gamertag}\n`; + } + + const activePlayersEmbed = new EmbedBuilder() + .setColor(this.config.Colors.Default) + .setTitle(`Online List - ${activePlayers.length} Player${(activePlayers.length>1||activePlayers.length==0)?'s':''} Online`) + .setDescription(des); + + return interaction.send({ embeds: [activePlayersEmbed] }); + }, + }, +} \ No newline at end of file diff --git a/package.json b/package.json index d96d34e..fb428cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "5.6.3.7", + "version": "5.7.0", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzArmbands.js b/structures/DayzArmbands.js index 3e38021..29e7309 100644 --- a/structures/DayzArmbands.js +++ b/structures/DayzArmbands.js @@ -35,6 +35,7 @@ class DayzArmbands extends Client { this.LoadEvents(); this.Ready = false; + this.activePlayersTick = 0; this.ws.on("INTERACTION_CREATE", async (interaction) => { const start = new Date().getTime(); @@ -428,7 +429,33 @@ class DayzArmbands extends Client { } } - async readLogs() { + async handleActivePlayersList(guildId) { + this.activePlayersTick = 0; // reset hour tick + + let guild = await this.GetGuild(guildId); + if (!this.exists(guild.playerstats)) guild.playerstats = []; + if (!this.exists(guild.activePlayersChannel)) return; + + const channel = this.channels.cache.get(guild.activePlayersChannel); + + let activePlayers = guild.playerstats.filter(p => p.connected); + + if (activePlayers.length == 0) return; + + let des = ``; + for (let i = 0; i < activePlayers.length; i++) { + des += `**- ${activePlayers[i].gamertag}\n`; + } + + const activePlayersEmbed = new EmbedBuilder() + .setColor(this.config.Colors.Default) + .setTitle(`Online List - ${activePlayers.length} Player${activePlayers.length>1?'s':''} Online`) + .setDescription(des); + + return channel.send({ embeds: [activePlayersEmbed] }); + } + + async readLogs(guildId) { const fileStream = fs.createReadStream('./logs/server-logs.ADM'); let logHistoryDir = path.join(__dirname, '..', 'logs', 'history-logs.ADM.json'); @@ -461,14 +488,15 @@ class DayzArmbands extends Client { async logsUpdateTimer() { setTimeout(async () => { - this.readLogs('992982520591294524'); - // await this.downloadFile(`/games/${this.config.Nitrado.UserID}/noftp/dayzxb/config/DayZServer_X1_x64.ADM`, './logs/server-logs.ADM').then(() => { - // this.guilds.cache.forEach((guild) => { - // this.killfeed(guild.id); // Check logs for killfeed - // // this.alarms(); // check for base alarms (+ rules that may apply such as safe zone) - // // this.adminLogs(); // check for combat logs / connect + deconnect events - // }); - // }); + this.activePlayersTick++; + + await this.downloadFile(`/games/${this.config.Nitrado.UserID}/noftp/dayzxb/config/DayZServer_X1_x64.ADM`, './logs/server-logs.ADM').then(() => { + this.guilds.cache.forEach(async (guild) => { + await this.readLogs(guild.id).then(() => { + if (this.activePlayersTick == 12) this.handleActivePlayersList(guild.id); + }); + }); + }); this.logsUpdateTimer(); // restart this function }, minute * 5); // restart every 5 minutes } @@ -599,6 +627,7 @@ class DayzArmbands extends Client { allowedChannels: [], killfeedChannel: "", connectionLogsChannel: "", + activePlayersChannel: "", welcomeChannel: "", factionArmbands: {}, usedArmbands: [], @@ -657,6 +686,7 @@ class DayzArmbands extends Client { killfeedChannel: guild.server.killfeedChannel, connectionLogsChannel: guild.server.connectionLogsChannel, welcomeChannel: guild.server.welcomeChannel, + activePlayersChannel: guild.server.activePlayersChannel, }; }