diff --git a/Indo.md b/Indo.md
index 4e3306b..3436700 100644
--- a/Indo.md
+++ b/Indo.md
@@ -17,7 +17,7 @@ PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl da
- [Calvs Cloud](https://discord.gg/ssCQjhrBJN)
-
+
## Instalasi
1. [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl)
diff --git a/README.md b/README.md
index 6b496aa..e8a4391 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and pos
- [Calvs Cloud](https://discord.gg/ssCQjhrBJN)
-
+
## Installation
1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)
diff --git a/events/ready.js b/events/ready.js
index 5f0f683..0927b0e 100644
--- a/events/ready.js
+++ b/events/ready.js
@@ -2,28 +2,28 @@ const chalk = require('chalk')
const checkStatus = require('../handlers/checkStatus')
module.exports = {
- name: 'ready',
- once: true,
- execute(client) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.green('Bot is up!'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.green('If you need support you can join our discord server https://discord.gg/zv6maQRah3'))
+ name: 'ready',
+ once: true,
+ execute(client) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.green('Bot is up!'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.green('If you need support you can join our discord server https://discord.gg/zv6maQRah3'))
- if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
+ if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
- if (client.config.bot_status.enable && client.config.bot_status.text.length > 0) {
- if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase() || client.config.bot_status.type.length < 1 )) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Status Type!, Can be "WATCHING", "PLAYING", "LISTENING", or "COMPETING"'))
- } else {
- client.user.setActivity(client.config.bot_status.text, { type: client.config.bot_status.type.toUpperCase() })
- }
- }
+ if (client.config.bot_status.enable && client.config.bot_status.text.length > 0) {
+ if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase() || client.config.bot_status.type.length < 1)) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Status Type!, Can be "WATCHING", "PLAYING", "LISTENING", or "COMPETING"'))
+ } else {
+ client.user.setActivity(client.config.bot_status.text, { type: client.config.bot_status.type.toUpperCase() })
+ }
+ }
- if (client.config.refresh < 10) console.log('Refresh lower than 10 seconds is not recommended!')
+ if (client.config.refresh < 10) console.log('Refresh lower than 10 seconds is not recommended!')
- checkStatus(client)
+ checkStatus(client)
- setInterval(() => {
- checkStatus(client)
- }, client.config.refresh * 1000)
- }
+ setInterval(() => {
+ checkStatus(client)
+ }, client.config.refresh * 1000)
+ }
}
\ No newline at end of file
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index 48e2ded..2bab4e7 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -5,140 +5,140 @@ const postStatus = require('./postStatus')
module.exports = function checkStatus(client) {
- if (client.config.channel.startsWith('Put')) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Channel ID'))
- process.exit()
- } else if (client.config.panel.url.startsWith('Put')) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
- process.exit()
- } else if (client.config.panel.key.startsWith('Put')) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Apikey'))
- process.exit()
- } else if (!client.config.panel.url.startsWith('http')) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the panel url is starts with "https://" or "http://"'))
- process.exit()
- }
+ if (client.config.channel.startsWith('Put')) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Channel ID'))
+ process.exit()
+ } else if (client.config.panel.url.startsWith('Put')) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
+ process.exit()
+ } else if (client.config.panel.key.startsWith('Put')) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Apikey'))
+ process.exit()
+ } else if (!client.config.panel.url.startsWith('http')) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the panel url is starts with "https://" or "http://"'))
+ process.exit()
+ }
- if (client.config.panel.url.endsWith('/')) client.config.panel.url = client.config.panel.url.slice(0, -1)
+ if (client.config.panel.url.endsWith('/')) client.config.panel.url = client.config.panel.url.slice(0, -1)
- const nodes = []
+ const nodes = []
- const panel = {
- status: false,
- total_servers: -1,
- total_users: -1,
- }
+ const panel = {
+ status: false,
+ total_servers: -1,
+ total_users: -1,
+ }
- console.log(chalk.cyan('[PteroStats] ') + chalk.green('Getting nodes stats'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.green('Getting nodes stats'))
- const panelStats = new Promise((resolve, reject) => {
- axios(client.config.panel.url + '/api/application/users', {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- Authorization: 'Bearer ' + client.config.panel.key
- }
- }).then((usr) => {
- axios(client.config.panel.url + '/api/application/servers', {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- Authorization: 'Bearer ' + client.config.panel.key
- }
- }).then((ser) => {
- panel.total_users = usr.data.meta.pagination.total
- panel.total_servers = ser.data.meta.pagination.total
- panel.status = true
+ const panelStats = new Promise((resolve, reject) => {
+ axios(client.config.panel.url + '/api/application/users', {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + client.config.panel.key
+ }
+ }).then((usr) => {
+ axios(client.config.panel.url + '/api/application/servers', {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + client.config.panel.key
+ }
+ }).then((ser) => {
+ panel.total_users = usr.data.meta.pagination.total
+ panel.total_servers = ser.data.meta.pagination.total
+ panel.status = true
- resolve()
- })
- }).catch((err) => {
- if (err.response) {
- if (err.response.status === 403) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid apikey'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the apikey is from admin page not account page'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('2. Make sure the apikey has read permission on all options'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('3. Make sure the apikey is exist'))
- } else if (err.response.status === 404) {
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
- console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the panel url is like "https://panel.example.com"'))
- } else console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! ' + err))
- } else console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! ' + err))
- resolve()
- })
- })
+ resolve()
+ })
+ }).catch((err) => {
+ if (err.response) {
+ if (err.response.status === 403) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid apikey'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the apikey is from admin page not account page'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('2. Make sure the apikey has read permission on all options'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('3. Make sure the apikey is exist'))
+ } else if (err.response.status === 404) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Panel URL'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('1. Make sure the panel url is like "https://panel.example.com"'))
+ } else console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! ' + err))
+ } else console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! ' + err))
+ resolve()
+ })
+ })
- const nodeStats = new Promise((resolve, reject) => {
- axios(client.config.panel.url + '/api/application/nodes?include=servers,location,allocations', {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- Authorization: 'Bearer ' + client.config.panel.key
- }
- }).then((res) => {
- res.data.data.forEach((node, i) => {
- axios(client.config.panel.url + '/api/application/nodes/' + node.attributes.id + '/configuration', {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- Authorization: 'Bearer ' + client.config.panel.key
- }
- }).then((data) => {
- const body = {
- id: node.attributes.id,
- name: node.attributes.name,
- location: node.attributes.relationships.location.attributes.short,
- allocations: node.attributes.relationships.allocations.data.length,
- status: true,
- maintenance: node.attributes.maintenance_mode,
- total_servers: node.attributes.relationships.servers.data.length,
- memory_min: node.attributes.allocated_resources.memory,
- memory_max: node.attributes.memory,
- disk_min: node.attributes.allocated_resources.disk,
- disk_max: node.attributes.disk,
- }
+ const nodeStats = new Promise((resolve, reject) => {
+ axios(client.config.panel.url + '/api/application/nodes?include=servers,location,allocations', {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + client.config.panel.key
+ }
+ }).then((res) => {
+ res.data.data.forEach((node, i) => {
+ axios(client.config.panel.url + '/api/application/nodes/' + node.attributes.id + '/configuration', {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + client.config.panel.key
+ }
+ }).then((data) => {
+ const body = {
+ id: node.attributes.id,
+ name: node.attributes.name,
+ location: node.attributes.relationships.location.attributes.short,
+ allocations: node.attributes.relationships.allocations.data.length,
+ status: true,
+ maintenance: node.attributes.maintenance_mode,
+ total_servers: node.attributes.relationships.servers.data.length,
+ memory_min: node.attributes.allocated_resources.memory,
+ memory_max: node.attributes.memory,
+ disk_min: node.attributes.allocated_resources.disk,
+ disk_max: node.attributes.disk,
+ }
- const stats = new Promise((statsResolve, statsReject) => {
- axios(node.attributes.scheme + '://' + node.attributes.fqdn + ':' + node.attributes.daemon_listen + '/api/servers', {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- Authorization: 'Bearer ' + data.data.token
- }
- }).then((status) => {
- return statsResolve()
- }).catch((err) => {
- body.status = false
- return statsResolve()
- })
- setTimeout(() => {
- body.status = false
- return statsResolve()
- }, 1000)
- })
- stats.then(() => {
- nodes.push(body)
- if (nodes.length === res.data.data.length) resolve()
- })
- }).catch((err) => {
- resolve()
- })
- })
- }).catch((err) => {
- resolve()
- })
- })
+ const stats = new Promise((statsResolve, statsReject) => {
+ axios(node.attributes.scheme + '://' + node.attributes.fqdn + ':' + node.attributes.daemon_listen + '/api/servers', {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ Authorization: 'Bearer ' + data.data.token
+ }
+ }).then((status) => {
+ return statsResolve()
+ }).catch((err) => {
+ body.status = false
+ return statsResolve()
+ })
+ setTimeout(() => {
+ body.status = false
+ return statsResolve()
+ }, 1000)
+ })
+ stats.then(() => {
+ nodes.push(body)
+ if (nodes.length === res.data.data.length) resolve()
+ })
+ }).catch((err) => {
+ resolve()
+ })
+ })
+ }).catch((err) => {
+ resolve()
+ })
+ })
- panelStats.then(() => {
- nodeStats.then(() => {
- nodes.sort(function (a, b) { return a.id - b.id })
- postStatus(client, panel, nodes)
- })
- })
+ panelStats.then(() => {
+ nodeStats.then(() => {
+ nodes.sort(function (a, b) { return a.id - b.id })
+ postStatus(client, panel, nodes)
+ })
+ })
}
\ No newline at end of file
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index 369f466..7c57495 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -1,176 +1,176 @@
-const { EmbedBuilder, time, ActionRowBuilder, ButtonBuilder, AttachmentBuilder, ButtonStyle } = require('discord.js')
+const { EmbedBuilder, time, ActionRowBuilder, ButtonBuilder, ButtonStyle, AttachmentBuilder } = require('discord.js')
const chalk = require('chalk')
module.exports = async function postStatus(client, panel, nodes) {
- if (!client.config.nodes_resource) client.config.nodes_resource = client.config.resource
- if (!client.config.nodes_resource.blacklist) client.config.nodes_resource.blacklist = []
- if (!Array.isArray(client.config.nodes_resource.blacklist) && Number.isInteger(client.config.nodes_resource.blacklist)) client.config.nodes_resource.blacklist = [client.config.nodes_resource.blacklist]
- if (!client.config.message.attachment) client.config.message.attachment = client.config.message.image
+ if (!client.config.nodes_resource) client.config.nodes_resource = client.config.resource
+ if (!client.config.nodes_resource.blacklist) client.config.nodes_resource.blacklist = []
+ if (!Array.isArray(client.config.nodes_resource.blacklist) && Number.isInteger(client.config.nodes_resource.blacklist)) client.config.nodes_resource.blacklist = [client.config.nodes_resource.blacklist]
+ if (!client.config.message.attachment) client.config.message.attachment = client.config.message.image
- if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
+ if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
- const channel = await client.channels.cache.get(client.config.channel)
+ const channel = await client.channels.cache.get(client.config.channel)
- if (!channel) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Channel ID'))
+ if (!channel) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Channel ID'))
- let messages = await channel.messages.fetch({ limit: 10 })
- messages = messages.filter(m => m.author.id === client.user.id).last();
- if (messages && messages.embeds.length < 1) {
- messages.delete()
- messages = null
- }
+ let messages = await channel.messages.fetch({ limit: 10 })
+ messages = messages.filter(m => m.author.id === client.user.id).last();
+ if (messages && messages.embeds.length < 1) {
+ messages.delete()
+ messages = null
+ }
- const embed = new EmbedBuilder()
+ const embed = new EmbedBuilder()
- let text = ''
- let desc = ''
- let blacklist = 0
+ let text = ''
+ let desc = ''
+ let blacklist = 0
- let content = null
- const files = []
+ let content = null
+ const files = []
- if (client.config.message.content) content = client.config.message.content
- if (client.config.message.attachment) files.push(new AttachmentBuilder(client.config.message.attachment))
+ if (client.config.message.content) content = client.config.message.content
+ if (client.config.message.attachment) files.push(new AttachmentBuilder(client.config.message.attachment))
- if (client.config.embed.title) embed.setTitle(client.config.embed.title)
- if (client.config.embed.description) desc = client.config.embed.description + '\n'
- if (client.config.embed.color) embed.setColor(client.config.embed.color)
- if (client.config.embed.footer) embed.setFooter({ text: client.config.embed.footer })
- if (client.config.embed.thumbnail) embed.setThumbnail(client.config.embed.thumbnail)
- if (client.config.embed.image) embed.setImage(client.config.embed.image)
+ if (client.config.embed.title) embed.setTitle(client.config.embed.title)
+ if (client.config.embed.description) desc = client.config.embed.description + '\n'
+ if (client.config.embed.color) embed.setColor(client.config.embed.color)
+ if (client.config.embed.footer) embed.setFooter({ text: client.config.embed.footer })
+ if (client.config.embed.thumbnail) embed.setThumbnail(client.config.embed.thumbnail)
+ if (client.config.embed.image) embed.setImage(client.config.embed.image)
- panel.total_users = panel.total_users.toLocaleString()
- panel.total_servers = panel.total_servers.toLocaleString()
+ panel.total_users = panel.total_users.toLocaleString()
+ panel.total_servers = panel.total_servers.toLocaleString()
- const stats = new Promise((resolve, reject) => {
- if (nodes.length !== 0) {
- nodes.forEach((data, i) => {
- if (!client.config.nodes_resource.blacklist.includes(data.id)) {
- const title = data.name + ': ' + String(data.status).replace('true', client.config.status.online).replace('false', client.config.status.offline)
- let description = '```'
- switch (client.config.nodes_resource.unit.toLowerCase()) {
- case 'tb':
- description = description +
- '\nMemory : ' + Math.floor(data.memory_min / 1000000).toLocaleString() + ' TB / ' + Math.floor(data.memory_max / 1000000).toLocaleString() + ' TB' +
- '\nDisk : ' + Math.floor(data.disk_min / 1000000).toLocaleString() + ' TB / ' + Math.floor(data.disk_max / 1000000).toLocaleString() + ' TB'
- break;
- case 'gb':
- description = description +
- '\nMemory : ' + Math.floor(data.memory_min / 1000).toLocaleString() + ' GB / ' + Math.floor(data.memory_max / 1000).toLocaleString() + ' GB' +
- '\nDisk : ' + Math.floor(data.disk_min / 1000).toLocaleString() + ' GB / ' + Math.floor(data.disk_max / 1000).toLocaleString() + ' GB'
- break;
- case 'percent':
- description = description +
- '\nMemory : ' + Math.floor(data.memory_min / data.memory_max * 100) + ' %' +
- '\nDisk : ' + Math.floor(data.disk_min / data.disk_max * 100) + ' %'
- break;
- default:
- description = description +
- '\nMemory : ' + data.memory_min.toLocaleString() + ' MB / ' + data.memory_max.toLocaleString() + ' MB' +
- '\nDisk : ' + data.disk_min.toLocaleString() + ' MB / ' + data.disk_max.toLocaleString() + ' MB'
- }
+ const stats = new Promise((resolve, reject) => {
+ if (nodes.length !== 0) {
+ nodes.forEach((data, i) => {
+ if (!client.config.nodes_resource.blacklist.includes(data.id)) {
+ const title = data.name + ': ' + String(data.status).replace('true', client.config.status.online).replace('false', client.config.status.offline)
+ let description = '```'
+ switch (client.config.nodes_resource.unit.toLowerCase()) {
+ case 'tb':
+ description = description +
+ '\nMemory : ' + Math.floor(data.memory_min / (1024 * 1000)).toLocaleString() + ' TB / ' + Math.floor(data.memory_max / (1024 * 1000)).toLocaleString() + ' TB' +
+ '\nDisk : ' + Math.floor(data.disk_min / (1024 * 1000)).toLocaleString() + ' TB / ' + Math.floor(data.disk_max / (1024 * 1000)).toLocaleString() + ' TB'
+ break;
+ case 'gb':
+ description = description +
+ '\nMemory : ' + Math.floor(data.memory_min / 1024).toLocaleString() + ' GB / ' + Math.floor(data.memory_max / 1024).toLocaleString() + ' GB' +
+ '\nDisk : ' + Math.floor(data.disk_min / 1024).toLocaleString() + ' GB / ' + Math.floor(data.disk_max / 1024).toLocaleString() + ' GB'
+ break;
+ case 'percent':
+ description = description +
+ '\nMemory : ' + Math.floor(data.memory_min / data.memory_max * 100) + ' %' +
+ '\nDisk : ' + Math.floor(data.disk_min / data.disk_max * 100) + ' %'
+ break;
+ default:
+ description = description +
+ '\nMemory : ' + data.memory_min.toLocaleString() + ' MB / ' + data.memory_max.toLocaleString() + ' MB' +
+ '\nDisk : ' + data.disk_min.toLocaleString() + ' MB / ' + data.disk_max.toLocaleString() + ' MB'
+ }
- if (client.config.nodes_resource.servers) description = description + '\nServers : ' + data.total_servers.toLocaleString()
- if (client.config.nodes_resource.location) description = description + '\nLocation : ' + data.location
- if (client.config.nodes_resource.allocations) description = description + '\nAllocations : ' + data.allocations.toLocaleString()
+ if (client.config.nodes_resource.servers) description = description + '\nServers : ' + data.total_servers.toLocaleString()
+ if (client.config.nodes_resource.location) description = description + '\nLocation : ' + data.location
+ if (client.config.nodes_resource.allocations) description = description + '\nAllocations : ' + data.allocations.toLocaleString()
- description = description + '\n```'
+ description = description + '\n```'
- if (client.config.nodes_resource.enable) {
- text = text + '\n**' + title.replace(':', ':**') + '\n' + description
- } else {
- text = text + '\n**' + title.replace(':', ':**')
- }
- } else {
- blacklist = blacklist + 1
- if (nodes.length - client.config.nodes_resource.blacklist.length < 1) text = '\nThere is no nodes to display'
- }
+ if (client.config.nodes_resource.enable) {
+ text = text + '\n**' + title.replace(':', ':**') + '\n' + description
+ } else {
+ text = text + '\n**' + title.replace(':', ':**')
+ }
+ } else {
+ blacklist = blacklist + 1
+ if (nodes.length - client.config.nodes_resource.blacklist.length < 1) text = '\nThere is no nodes to display'
+ }
- if (i + 1 === nodes.length) resolve()
- })
- } else if (nodes.length < 1) {
- if (!messages) {
- text = '\nThere is no nodes to display'
- resolve()
- } else {
- text = messages.embeds[0].description.replaceAll(client.config.status.online, client.config.status.offline)
- if (!panel.status && String(String(messages.embeds[0].fields[0].value).split('\n')[2]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[2]).length - 1] !== '`') {
- panel.total_users = String(String(messages.embeds[0].fields[0].value).split('\n')[2]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[2]).length - 1]
- panel.total_servers = String(String(messages.embeds[0].fields[0].value).split('\n')[3]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[3]).length - 1]
- }
- resolve()
- }
- }
- })
+ if (i + 1 === nodes.length) resolve()
+ })
+ } else if (nodes.length < 1) {
+ if (!messages) {
+ text = '\nThere is no nodes to display'
+ resolve()
+ } else {
+ text = messages.embeds[0].description.replaceAll(client.config.status.online, client.config.status.offline)
+ if (!panel.status && String(String(messages.embeds[0].fields[0].value).split('\n')[2]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[2]).length - 1] !== '`') {
+ panel.total_users = String(String(messages.embeds[0].fields[0].value).split('\n')[2]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[2]).length - 1]
+ panel.total_servers = String(String(messages.embeds[0].fields[0].value).split('\n')[3]).split('')[String(String(messages.embeds[0].fields[0].value).split('\n')[3]).length - 1]
+ }
+ resolve()
+ }
+ }
+ })
- stats.then(async () => {
- const format = await time(new Date(Date.now() + client.config.refresh * 1000), 'R')
- embed.setDescription(desc.replaceAll('{{time}}', format) + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text)
- const EmbedFields = []
+ stats.then(async () => {
+ const format = await time(new Date(Date.now() + client.config.refresh * 1000), 'R')
+ embed.setDescription(desc.replaceAll('{{time}}', format) + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text)
+ const EmbedFields = []
- if (client.config.panel_resource.enable) {
- let stats = '**Status:** ' + String(panel.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) + '\n\n'
+ if (client.config.panel_resource.enable) {
+ let stats = '**Status:** ' + String(panel.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) + '\n\n'
- if (client.config.panel_resource.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n'
- if (client.config.panel_resource.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`')
+ if (client.config.panel_resource.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n'
+ if (client.config.panel_resource.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`')
- EmbedFields.push({ name: 'Panel Stats', value: stats })
- }
+ EmbedFields.push({ name: 'Panel Stats', value: stats })
+ }
- if (client.config.embed.field.enable) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) })
- if (client.config.embed.timestamp) embed.setTimestamp()
- if (EmbedFields.length > 0) embed.addFields(EmbedFields)
-
- const row = []
+ if (client.config.embed.field.enable) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) })
+ if (client.config.embed.timestamp) embed.setTimestamp()
+ if (EmbedFields.length > 0) embed.addFields(EmbedFields)
- if (client.config.button.enable) {
- const button = new ActionRowBuilder
- if (client.config.button.btn1.label.length !== 0 && client.config.button.btn1.url.length !== 0) {
- button.addComponents(
- new ButtonBuilder()
- .setLabel(client.config.button.btn1.label)
- .setStyle(ButtonStyle.Link)
- .setURL(client.config.button.btn1.url)
- )
- }
- if (client.config.button.btn2.label.length !== 0 && client.config.button.btn2.url.length !== 0) {
- button.addComponents(
- new ButtonBuilder()
- .setLabel(client.config.button.btn2.label)
- .setStyle(ButtonStyle.Link)
- .setURL(client.config.button.btn2.url)
- )
- }
- if (client.config.button.btn3.label.length !== 0 && client.config.button.btn3.url.length !== 0) {
- button.addComponents(
- new ButtonBuilder()
- .setLabel(client.config.button.btn3.label)
- .setStyle(ButtonStyle.Link)
- .setURL(client.config.button.btn3.url)
- )
- }
- if (client.config.button.btn4.label.length !== 0 && client.config.button.btn4.url.length !== 0) {
- button.addComponents(
- new ButtonBuilder()
- .setLabel(client.config.button.btn4.label)
- .setStyle(ButtonStyle.Link)
- .setURL(client.config.button.btn4.url)
- )
- }
- if (client.config.button.btn5.label.length !== 0 && client.config.button.btn5.url.length !== 0) {
- button.addComponents(
- new ButtonBuilder()
- .setLabel(client.config.button.btn5.label)
- .setStyle(ButtonStyle.Link)
- .setURL(client.config.button.btn5.url)
- )
- }
- row.push(button)
- }
+ const row = []
- if (!messages) channel.send({ content: content, embeds: [embed], components: row, files: files })
- else messages.edit({ content: content, embeds: [embed], components: row, files: files })
- console.log(chalk.cyan('[PteroStats] ') + chalk.green('Stats posted!'))
- })
+ if (client.config.button.enable) {
+ const button = new ActionRowBuilder
+ if (client.config.button.btn1.label.length !== 0 && client.config.button.btn1.url.length !== 0) {
+ button.addComponents(
+ new ButtonBuilder()
+ .setLabel(client.config.button.btn1.label)
+ .setStyle(ButtonStyle.Link)
+ .setURL(client.config.button.btn1.url)
+ )
+ }
+ if (client.config.button.btn2.label.length !== 0 && client.config.button.btn2.url.length !== 0) {
+ button.addComponents(
+ new ButtonBuilder()
+ .setLabel(client.config.button.btn2.label)
+ .setStyle(ButtonStyle.Link)
+ .setURL(client.config.button.btn2.url)
+ )
+ }
+ if (client.config.button.btn3.label.length !== 0 && client.config.button.btn3.url.length !== 0) {
+ button.addComponents(
+ new ButtonBuilder()
+ .setLabel(client.config.button.btn3.label)
+ .setStyle(ButtonStyle.Link)
+ .setURL(client.config.button.btn3.url)
+ )
+ }
+ if (client.config.button.btn4.label.length !== 0 && client.config.button.btn4.url.length !== 0) {
+ button.addComponents(
+ new ButtonBuilder()
+ .setLabel(client.config.button.btn4.label)
+ .setStyle(ButtonStyle.Link)
+ .setURL(client.config.button.btn4.url)
+ )
+ }
+ if (client.config.button.btn5.label.length !== 0 && client.config.button.btn5.url.length !== 0) {
+ button.addComponents(
+ new ButtonBuilder()
+ .setLabel(client.config.button.btn5.label)
+ .setStyle(ButtonStyle.Link)
+ .setURL(client.config.button.btn5.url)
+ )
+ }
+ row.push(button)
+ }
+
+ if (!messages) channel.send({ content: content, embeds: [embed], components: row, files: files })
+ else messages.edit({ content: content, embeds: [embed], components: row, files: files })
+ console.log(chalk.cyan('[PteroStats] ') + chalk.green('Stats posted!'))
+ })
}
\ No newline at end of file
diff --git a/index.js b/index.js
index b1694be..9098250 100644
--- a/index.js
+++ b/index.js
@@ -2,55 +2,51 @@ const fs = require('fs');
const child = require('child_process');
if (Number(process.version.split('.')[0]) < 16) {
- console.log('Invalid NodeJS Version!, Please use NodeJS 16.x or upper')
- process.exit()
+ console.log('Invalid NodeJS Version!, Please use NodeJS 16.x or upper')
+ process.exit()
}
if (fs.existsSync('./node_modules')) {
- const check = require('./node_modules/discord.js/package.json')
- if (Number(check.version.split('.')[0]) !== 14) {
- console.log('Invalid Discord.JS Version!, Please use Discord.JS 14.x')
- process.exit()
- }
+ const check = require('./node_modules/discord.js/package.json')
+ if (Number(check.version.split('.')[0]) !== 14) {
+ console.log('Invalid Discord.JS Version!, Please use Discord.JS 14.x')
+ process.exit()
+ }
} else {
- console.log('You didn\'t install the required node packages first!')
- console.log('Please wait... starting to install all required node packages using child process')
- try {
- child.execSync('npm i')
- console.log('Install complete!, please run "node index" command again!')
- process.exit()
- } catch (err) {
- console.log('Err! ', err)
- console.log('Support Server: https://discord.gg/zv6maQRah3')
- process.exit()
- }
+ console.log('You didn\'t install the required node packages first!')
+ console.log('Please wait... starting to install all required node packages using child process')
+ try {
+ child.execSync('npm i')
+ console.log('Install complete!, please run "node index" command again!')
+ process.exit()
+ } catch (err) {
+ console.log('Err! ', err)
+ console.log('Support Server: https://discord.gg/zv6maQRah3')
+ process.exit()
+ }
}
-const path = require('node:path');
const chalk = require('chalk');
const yaml = require('js-yaml');
const { Client, GatewayIntentBits } = require('discord.js');
+const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const config = yaml.load(fs.readFileSync('./config.yml', 'utf8'));
client.config = config
-const client = new Client({ intents: [GatewayIntentBits.Guilds] });
-
-const eventsPath = path.join(__dirname, 'events');
-const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
+const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
- const filePath = path.join(eventsPath, file);
- const event = require(filePath);
- if (event.once) {
- client.once(event.name, (...args) => event.execute(...args));
- } else {
- client.on(event.name, (...args) => event.execute(...args));
- }
+ const event = require(`./events/${file}`);
+ if (event.once) {
+ client.once(event.name, (...args) => event.execute(...args));
+ } else {
+ client.on(event.name, (...args) => event.execute(...args));
+ }
}
if (client.config.token.startsWith('Put') || client.config.token.length < 1) {
- console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Discord Bot Token'))
- process.exit()
+ console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Discord Bot Token'))
+ process.exit()
}
client.login(config.token);
\ No newline at end of file
diff --git a/package.json b/package.json
index 90846dd..36fbe00 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,24 @@
{
- "name": "pterostats",
- "version": "v3.0.0",
- "description": "PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server",
- "license": "MIT",
- "repository": "HirziDevs/PteroStats",
- "homepage": "https://pterostats.hirzidevs.net",
- "bugs": {
- "email": "hirzidevs@gmail.com",
- "url": "https://github.com/HirziDevs/PteroStats"
- },
- "scripts": {
- "start": "node index.js"
- },
- "dependencies": {
- "axios": "^0.27.2",
- "chalk": "4.1.1",
- "discord.js": "^14.6.0",
- "js-yaml": "^4.1.0"
- },
- "engines": {
- "node": "^16.x"
- }
+ "name": "pterostats",
+ "version": "v3.0.0",
+ "description": "PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server",
+ "license": "MIT",
+ "repository": "HirziDevs/PteroStats",
+ "homepage": "https://pterostats.hirzidevs.net",
+ "bugs": {
+ "email": "hirzidevs@gmail.com",
+ "url": "https://github.com/HirziDevs/PteroStats"
+ },
+ "scripts": {
+ "start": "node index.js"
+ },
+ "dependencies": {
+ "axios": "^1.1.3",
+ "chalk": "4.1.1",
+ "discord.js": "^14.6.0",
+ "js-yaml": "^4.1.0"
+ },
+ "engines": {
+ "node": "^16.x"
+ }
}
\ No newline at end of file