From 7c9ab231bcd2e05104a5e0c67ee7ee8711475aed Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Sun, 29 May 2022 19:28:04 +0700 Subject: [PATCH 01/27] 2.0 ? --- Indo.md | 81 +++++++++++ README.md | 136 +++++++----------- config.yml | 83 ++++++----- events/ready.js | 308 +++------------------------------------- handlers/checkStatus.js | 125 ++++++++++++++++ handlers/postStatus.js | 153 ++++++++++++++++++++ index.js | 56 ++++++-- package.json | 15 +- 8 files changed, 529 insertions(+), 428 deletions(-) create mode 100644 Indo.md create mode 100644 handlers/checkStatus.js create mode 100644 handlers/postStatus.js diff --git a/Indo.md b/Indo.md new file mode 100644 index 0000000..74b6970 --- /dev/null +++ b/Indo.md @@ -0,0 +1,81 @@ +
## Bahasa / Language
[[Indonesia]](https://github.com/HirziDevs/PteroStats/blob/dev/Indo.md) | [[Inggris]](https://github.com/HirziDevs/PteroStats/blob/dev/README.md)
@@ -10,91 +10,109 @@
## Pengenalan
PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord
+## Contoh
+
+
## Instalasi
- - [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl)
- - [Membuat Discord Bot](#membuat-discord-bot)
- - [Menginvite Discord Bot](#menginvite-discord-bot)
- - [Mendapatkan Channel ID](#mendapatkan-channel-id)
- - [Memulai Bot](#memulai-bot)
+ 1. [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl)
+ 2. [Membuat Discord Bot](#membuat-discord-bot)
+ 3. [Menginvite Discord Bot](#menginvite-discord-bot)
+ 4. [Mendapatkan Channel ID](#mendapatkan-channel-id)
+ 5. [Memulai Bot](#memulai-bot)
+
- [Mengunakan custom emoji](#mengunakan-custom-emoji)
- [Blacklist Nodes](#blacklist-nodes)
### Mendapatkan apikey dari pterodactyl
-- Pergi ke `panel admin pterodactyl` dan pergi ke `Application API`
+1. Pergi ke `panel admin pterodactyl` dan pergi ke `Application API`
- 
+
-- Klik tombol `Create New`
+2. Klik tombol `Create New`
- 
+
-- Set semua permission ke `read` dan untuk description kamu bisa mengisi apa saja
+3. Set semua permission ke `read` dan untuk description kamu bisa mengisi apa saja
- 
+
-- Copy apikey-nya.
+4. Copy apikey-nya.
- 
+
+
+5. Paste panel apikeynya dan panel urlnya di config
+
+
### Membuat Discord Bot
Kalian bisa cek [website ini](https://discordjs.guide/preparations/setting-up-a-bot-application.html)
+Paste bot tokennya di config
+
+
+
### Menginvite Discord Bot
Kalian bisa cek [website ini](https://discordjs.guide/preparations/adding-your-bot-to-servers.html)
### Mendapatkan Channel ID
1. Aktifkan `Developer Mode` di settings discord kamu
- 
+
2. Klik kanan teks channel dan pilih `Copy ID`
- 
+
+
+3. Paste id channelnya di config
+
+
### Memulai Bot
-- Masukan `token` bot discord di `line token` yang terdapat di file `config.yml`
-- Copy `id channel` diserver discord kamu dan masukan ke line `channel` di file `config.yml`
-- Masukan `apikey` dan `url` pterodactyl di `line panel` di file `config.yml`
-- Jalankan command `npm install` di folder yang berisi file bot
-- Jalankan command `node index` dan kamu selesai!
+1. Pastikan kamu telah melakukan semua yang ada diatas
+2. Jalankan command `npm install` di folder yang berisi file bot
+3. Jalankan command `node index` dan kamu selesai!
Jika kamu mendapat masalah bisa dm `Hirzi#8701` didiscord atau join [server support kami](https://discord.gg/zv6maQRah3)
### Mengunakan custom emoji
1. ketik `\` di server yang ada custom emojinya
- 
+
2. Pilih custom emoji yang kamu mau
- 
+
3. Copy textnya!
- 
+
+
+4. Paste id emojinya di config
+
+
### Blacklist Nodes
1. Pilih node yang ada di node list admin page
-
- 
+
+
2. Cek urlnya dan copy id nodenya
- 
+
3. Masukan ke blacklist di config
- 
+
Kamu bisa memasukan lebih dari 1 node untuk di blacklist
-
+
## Permission apikey
-Pilih Aktifkan `read` di semua opsi permission, jika tetap error pilih `read & write` di semua opsi permission
+Jika kamu mengalami error 403 coba aktifkan `read & write` di semua opsi permission
-
+
## Links
diff --git a/README.md b/README.md
index 88d5880..2a46ba9 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
## Language / Bahasa
[[English]](https://github.com/HirziDevs/PteroStats/blob/dev/README.md) | [[Indonesia]](https://github.com/HirziDevs/PteroStats/blob/dev/Indo.md)
@@ -10,91 +10,109 @@
## Introduction
PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server
+## Example
+
+
## Installation
-- [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)
-- [Creating Discord Bot](#creating-discord-bot)
-- [Inviting Discord Bot](#inviting-discord-bot)
-- [Getting Channel ID](#getting-channel-id)
-- [Starting bot](#starting-bot)
+1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)
+2. [Creating Discord Bot](#creating-discord-bot)
+3. [Inviting Discord Bot](#inviting-discord-bot)
+4. [Getting Channel ID](#getting-channel-id)
+5. [Starting bot](#starting-bot)
+
- [Using Custom Emoji](#using-custom-emoji)
- [Blacklist Nodes](#blacklist-nodes)
### Getting apikey from pterodactyl
-- Go to your `pterodactyl admin page` and go to `Application API`.
+1. Go to your `pterodactyl admin page` and go to `Application API`.
- 
+
-- Click on the `Create New` button
+2. Click on the `Create New` button
- 
+
-- Set all options permission to `read` and for description you can put whatever you want
+3. Set all options permission to `read` and for description you can put whatever you want
- 
+
-- Copy the apikey.
+4. Copy the apikey.
- 
+
+
+5. Paste the panel apikey and panel url at the config
+
+
### Creating Discord Bot
Please refer to [this website](https://discordjs.guide/preparations/setting-up-a-bot-application.html)
+Paste the bot token at the config
+
+
+
### Inviting Discord Bot
Please refer to [this website](https://discordjs.guide/preparations/adding-your-bot-to-servers.html)
### Getting Channel ID
1. Enable Developer Feature at your discord settings
- 
+
2. Right Click text channel and select `Copy ID`
- 
+
+
+3. Paste the channel id at the config
+
+
### Starting bot
-- Put discord bot token in `config.yml` at `token line`.
-- Put your pterodactyl `apikey` and `url` in `config.yml` at `panel line`.
-- Copy `channel id` from your discord server and put it in `config.yml` file at `channel line`.
-- Run `npm install` in the root directory of the bot files.
-- Run `node index` and you are done.
+1. Make sure you have done the things above
+2. Run `npm install` in the root directory of the bot files.
+3. Run `node index` and you are done.
if you need help contact me on discord `Hirzi#8701` or join [our discord support server](https://discord.gg/zv6maQRah3)
### Using Custom Emoji
1. type `\` in guild that has custom emoji you want
- 
+
2. Select custom emoji you want
- 
+
3. Copy the text!
- 
+
+
+4. Paste the emoji id at the config
+
+
### Blacklist Nodes
1. Select node from node list on admin page
-
- 
+
+
2. Check the url and copy the node id
- 
+
-3. Add the id to the blacklist on config
+3. Paste the id to the blacklist on config
- 
+
You can add more than one node in the blacklist
-
+
-## Admin Apikey Permission
+## Apikey permission
-enable `read` on all options, if still didn't work enable `read & write` on all options
+If you having issue with 403 error try to enable `read & write` on all options
-
+
## Links
diff --git a/events/ready.js b/events/ready.js
index 234338e..fd993af 100644
--- a/events/ready.js
+++ b/events/ready.js
@@ -5,14 +5,14 @@ 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'))
+ 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(' There is bot is not in servers, please invite the bot first!'))
+ 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) {
if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type)) {
- console.log('Invalid Status Type!, Can be "WATCHING", "PLAYING", "LISTENING", or "COMPETING"')
+ 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 })
}
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index 2f2f53e..06f5b08 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -6,17 +6,17 @@ 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'))
+ 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'))
+ 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'))
+ 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://"'))
+ 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()
}
@@ -30,7 +30,7 @@ module.exports = function checkStatus(client) {
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', {
@@ -58,15 +58,15 @@ module.exports = function checkStatus(client) {
}).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'))
+ 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] ') + err)
- } else console.log(chalk.cyan('[PteroStats] ') + err)
+ 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()
})
})
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index c738889..8483e95 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -7,11 +7,11 @@ module.exports = async function postStatus(client, panel, nodes) {
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.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats]') + chalk.red(' 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)
- if (!channel) return console.log(chalk.cyan('[PteroStats]') + chalk.red(' 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();
@@ -162,6 +162,6 @@ module.exports = async function postStatus(client, panel, nodes) {
if (!messages) channel.send({ embeds: [embed], components: row })
else messages.edit({ embeds: [embed], components: row })
- console.log(chalk.cyan('[PteroStats]') + chalk.green(' Stats posted!'))
+ console.log(chalk.cyan('[PteroStats] ') + chalk.green('Stats posted!'))
})
}
\ No newline at end of file
From 9b962d0edde0760753e9ab11798e26675f4d0165 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Wed, 29 Jun 2022 07:20:40 +0700
Subject: [PATCH 21/27] FIx bot only show 1 nodes
---
handlers/checkStatus.js | 4 ++--
handlers/postStatus.js | 1 +
package.json | 6 +++---
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index 06f5b08..03b15c0 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -80,7 +80,7 @@ module.exports = function checkStatus(client) {
Authorization: 'Bearer ' + client.config.panel.key
}
}).then((res) => {
- res.data.data.forEach((node) => {
+ res.data.data.forEach((node, i) => {
axios(client.config.panel.url + '/api/application/nodes/' + node.attributes.id + '/configuration', {
method: 'GET',
headers: {
@@ -120,7 +120,7 @@ module.exports = function checkStatus(client) {
})
stats.then(() => {
nodes.push(body)
- resolve()
+ if (i + 1 === res.data.data.length) resolve()
})
}).catch((err) => {
resolve()
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index 8483e95..f804519 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -6,6 +6,7 @@ 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 (!['mb', 'gb', 'percent'].includes(client.config.nodes_resource.unit)) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Unit at nodes_resource'))
if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
diff --git a/package.json b/package.json
index 59559dd..5f0b5ac 100644
--- a/package.json
+++ b/package.json
@@ -13,12 +13,12 @@
"start": "node index.js"
},
"dependencies": {
- "axios": "^0.26.1",
+ "axios": "^0.27.2",
"chalk": "4.1.1",
- "discord.js": "^13.8.0",
+ "discord.js": "^13.8.1",
"js-yaml": "^4.1.0"
},
"engines": {
- "node": "16.x"
+ "node": "^16.x"
}
}
\ No newline at end of file
From 6f4c3f59fa37b5bfcbecc3bd98cbb7a29a9e4179 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Wed, 29 Jun 2022 09:08:43 +0700
Subject: [PATCH 22/27] Now you can add message content and image
---
config.yml | 8 ++++++--
events/ready.js | 6 +++---
handlers/postStatus.js | 32 ++++++++++++++++----------------
3 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/config.yml b/config.yml
index a049ef8..0382d39 100644
--- a/config.yml
+++ b/config.yml
@@ -17,8 +17,12 @@ panel:
url: 'Put panel url here'
key: 'Put panel apikey here'
-# Embed Configuration
-# set to false if you want to disable embed option
+# Message Configuration
+# set to false if you want to disable option
+message:
+ content: false
+ image: false # If you enable image on message it upload the image first before sending or editing message and it will delay stats
+
embed:
title: 'PteroStats'
color: '5865F2'
diff --git a/events/ready.js b/events/ready.js
index fd993af..c486380 100644
--- a/events/ready.js
+++ b/events/ready.js
@@ -11,14 +11,14 @@ module.exports = {
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) {
- if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type)) {
+ if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase())) {
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 })
+ client.user.setActivity(client.config.bot_status.text, { type: client.config.bot_status.type.toUpperCase() })
}
}
- if (client.config.refresh < 10) console.log('Refresh below 10 seconds is not recommended!')
+ if (client.config.refresh < 10) console.log('Refresh lower than 10 seconds is not recommended!')
checkStatus(client)
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index f804519..79fd8bc 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -1,4 +1,4 @@
-const { MessageEmbed, Formatters, MessageActionRow, MessageButton } = require('discord.js')
+const { MessageEmbed, Formatters, MessageActionRow, MessageButton, MessageAttachment } = require('discord.js')
const chalk = require('chalk')
module.exports = async function postStatus(client, panel, nodes) {
@@ -6,7 +6,7 @@ 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 (!['mb', 'gb', 'percent'].includes(client.config.nodes_resource.unit)) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Unit at nodes_resource'))
+ if (!['mb', 'gb', 'percent'].includes(client.config.nodes_resource.unit.toLowerCase())) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Unit at nodes config'))
if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers'))
@@ -21,7 +21,6 @@ module.exports = async function postStatus(client, panel, nodes) {
messages = null
}
- const format = await Formatters.time(new Date(Date.now() + client.config.refresh * 1000), 'R')
const embed = new MessageEmbed()
let text = ''
@@ -29,7 +28,7 @@ module.exports = async function postStatus(client, panel, nodes) {
let blacklist = 0
if (client.config.embed.title) embed.setTitle(client.config.embed.title)
- if (client.config.embed.description) desc = client.config.embed.description.replaceAll('{{time}}', format) + '\n'
+ 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)
@@ -44,7 +43,7 @@ module.exports = async function postStatus(client, panel, nodes) {
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) {
+ switch (client.config.nodes_resource.unit.toLowerCase()) {
case 'gb':
description = description +
'\nMemory : ' + Math.floor(data.memory_min / 1000).toLocaleString() + ' GB / ' + Math.floor(data.memory_max / 1000).toLocaleString() + ' GB' +
@@ -94,9 +93,9 @@ module.exports = async function postStatus(client, panel, nodes) {
}
})
- stats.then(() => {
-
- embed.setDescription(desc + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text)
+ stats.then(async () => {
+ const format = await Formatters.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)
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'
@@ -107,11 +106,8 @@ module.exports = async function postStatus(client, panel, nodes) {
embed.addField('Panel Stats', stats)
}
- if (client.config.embed.field.enable) {
- embed.addField(client.config.embed.field.title, client.config.embed.field.description.replaceAll('{{time}}', format))
- }
-
- embed.setTimestamp()
+ if (client.config.embed.field.enable) embed.addField(client.config.embed.field.title, client.config.embed.field.description.replaceAll('{{time}}', format))
+ if (client.config.embed.timestamp) embed.setTimestamp()
const row = []
@@ -157,12 +153,16 @@ module.exports = async function postStatus(client, panel, nodes) {
.setURL(client.config.button.btn5.url)
)
}
-
row.push(button)
}
+ let content = null
+ const files = []
- if (!messages) channel.send({ embeds: [embed], components: row })
- else messages.edit({ embeds: [embed], components: row })
+ if (client.config.message.content) content = client.config.message.content
+ if (client.config.message.image) files.push(new MessageAttachment(client.config.message.image))
+
+ 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
From d919cd370d115e9c2d3ddc9e182bacb8432f3b75 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Wed, 29 Jun 2022 09:12:31 +0700
Subject: [PATCH 23/27] Update readme
---
Indo.md | 2 +-
README.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Indo.md b/Indo.md
index c9e0003..2f22582 100644
--- a/Indo.md
+++ b/Indo.md
@@ -11,7 +11,7 @@
PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord
## Contoh
-
+
## Instalasi
1. [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl)
diff --git a/README.md b/README.md
index 2a46ba9..5be47c7 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@
PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server
## Example
-
+
## Installation
1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)
From eff98bb8d221069274968a2bfe924c80ac1d5537 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Thu, 30 Jun 2022 11:25:02 +0700
Subject: [PATCH 24/27] Fix if nodes is down the stats not updated
---
handlers/checkStatus.js | 10 +++++++++-
handlers/postStatus.js | 11 ++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index 03b15c0..0222e34 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -104,6 +104,7 @@ module.exports = function checkStatus(client) {
}
const stats = new Promise((statsResolve, statsReject) => {
+ let done = false
axios(node.attributes.scheme + '://' + node.attributes.fqdn + ':' + node.attributes.daemon_listen + '/api/servers', {
method: 'GET',
headers: {
@@ -112,15 +113,21 @@ module.exports = function checkStatus(client) {
Authorization: 'Bearer ' + data.data.token
}
}).then((status) => {
+ done = true
statsResolve()
}).catch((err) => {
body.status = false
+ done = true
statsResolve()
})
+ setTimeout(() => {
+ if (!done) body.status = false
+ statsResolve()
+ }, 1000)
})
stats.then(() => {
nodes.push(body)
- if (i + 1 === res.data.data.length) resolve()
+ if (nodes.length === res.data.data.length) resolve()
})
}).catch((err) => {
resolve()
@@ -133,6 +140,7 @@ module.exports = function checkStatus(client) {
panelStats.then(() => {
nodeStats.then(() => {
+ nodes.sort(function (a, b) { return a.id - b.id })
postStatus(client, panel, nodes)
})
})
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index 79fd8bc..87a8a51 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -27,6 +27,12 @@ module.exports = async function postStatus(client, panel, nodes) {
let desc = ''
let blacklist = 0
+ let content = null
+ const files = []
+
+ if (client.config.message.content) content = client.config.message.content
+ if (client.config.message.image) files.push(new MessageAttachment(client.config.message.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)
@@ -155,11 +161,6 @@ module.exports = async function postStatus(client, panel, nodes) {
}
row.push(button)
}
- let content = null
- const files = []
-
- if (client.config.message.content) content = client.config.message.content
- if (client.config.message.image) files.push(new MessageAttachment(client.config.message.image))
if (!messages) channel.send({ content: content, embeds: [embed], components: row, files: files })
else messages.edit({ content: content, embeds: [embed], components: row, files: files })
From 3d0512c3323ecf079101104c7ecf3c94d265e298 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Sat, 2 Jul 2022 16:35:26 +0700
Subject: [PATCH 25/27] Add TB Unit and other thing
---
config.yml | 4 ++--
events/ready.js | 4 ++--
handlers/checkStatus.js | 11 ++++-------
handlers/postStatus.js | 9 +++++++--
4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/config.yml b/config.yml
index 0382d39..fe1759b 100644
--- a/config.yml
+++ b/config.yml
@@ -21,7 +21,7 @@ panel:
# set to false if you want to disable option
message:
content: false
- image: false # If you enable image on message it upload the image first before sending or editing message and it will delay stats
+ attachment: false # If you enable attachment on message it upload the attachment first before sending or editing message and it will delay the stats
embed:
title: 'PteroStats'
@@ -67,7 +67,7 @@ nodes_resource:
servers: true
location: true
allocations: true
- unit: 'gb' # You can use "gb", "mb", or "percent"
+ unit: 'gb' # You can use "gb", "mb", "tb", or "percent"
# Panel Users and Servers
panel_resource:
diff --git a/events/ready.js b/events/ready.js
index c486380..5f0f683 100644
--- a/events/ready.js
+++ b/events/ready.js
@@ -10,8 +10,8 @@ module.exports = {
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) {
- if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(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() })
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index 0222e34..48e2ded 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -104,7 +104,6 @@ module.exports = function checkStatus(client) {
}
const stats = new Promise((statsResolve, statsReject) => {
- let done = false
axios(node.attributes.scheme + '://' + node.attributes.fqdn + ':' + node.attributes.daemon_listen + '/api/servers', {
method: 'GET',
headers: {
@@ -113,16 +112,14 @@ module.exports = function checkStatus(client) {
Authorization: 'Bearer ' + data.data.token
}
}).then((status) => {
- done = true
- statsResolve()
+ return statsResolve()
}).catch((err) => {
body.status = false
- done = true
- statsResolve()
+ return statsResolve()
})
setTimeout(() => {
- if (!done) body.status = false
- statsResolve()
+ body.status = false
+ return statsResolve()
}, 1000)
})
stats.then(() => {
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index 87a8a51..1cbe00a 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -6,7 +6,7 @@ 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 (!['mb', 'gb', 'percent'].includes(client.config.nodes_resource.unit.toLowerCase())) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Unit at nodes config'))
+ 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'))
@@ -31,7 +31,7 @@ module.exports = async function postStatus(client, panel, nodes) {
const files = []
if (client.config.message.content) content = client.config.message.content
- if (client.config.message.image) files.push(new MessageAttachment(client.config.message.image))
+ if (client.config.message.attachment) files.push(new MessageAttachment(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'
@@ -50,6 +50,11 @@ module.exports = async function postStatus(client, panel, nodes) {
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' +
From 623d0a611cdbcfaa118fe2d0856fafc1e31773fe Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Wed, 2 Nov 2022 12:21:12 +0000
Subject: [PATCH 26/27] Update to discordjs 14
---
Indo.md | 8 +++++++-
README.md | 8 +++++++-
handlers/postStatus.js | 38 ++++++++++++++++++++------------------
index.js | 28 ++++++++++++++++------------
package.json | 18 +++++++++---------
5 files changed, 59 insertions(+), 41 deletions(-)
diff --git a/Indo.md b/Indo.md
index 2f22582..4e3306b 100644
--- a/Indo.md
+++ b/Indo.md
@@ -11,7 +11,13 @@
PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord
## Contoh
-
+- Test Panel
+
+
+
+- [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 5be47c7..6b496aa 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,13 @@
PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server
## Example
-
+- Test Panel
+
+
+
+- [Calvs Cloud](https://discord.gg/ssCQjhrBJN)
+
+
## Installation
1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl)
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index 1cbe00a..369f466 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -1,4 +1,4 @@
-const { MessageEmbed, Formatters, MessageActionRow, MessageButton, MessageAttachment } = require('discord.js')
+const { EmbedBuilder, time, ActionRowBuilder, ButtonBuilder, AttachmentBuilder, ButtonStyle } = require('discord.js')
const chalk = require('chalk')
module.exports = async function postStatus(client, panel, nodes) {
@@ -21,7 +21,7 @@ module.exports = async function postStatus(client, panel, nodes) {
messages = null
}
- const embed = new MessageEmbed()
+ const embed = new EmbedBuilder()
let text = ''
let desc = ''
@@ -31,7 +31,7 @@ module.exports = async function postStatus(client, panel, nodes) {
const files = []
if (client.config.message.content) content = client.config.message.content
- if (client.config.message.attachment) files.push(new MessageAttachment(client.config.message.attachment))
+ 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'
@@ -105,8 +105,9 @@ module.exports = async function postStatus(client, panel, nodes) {
})
stats.then(async () => {
- const format = await Formatters.time(new Date(Date.now() + client.config.refresh * 1000), 'R')
+ 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'
@@ -114,53 +115,54 @@ module.exports = async function postStatus(client, panel, nodes) {
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`')
- embed.addField('Panel Stats', stats)
+ EmbedFields.push({ name: 'Panel Stats', value: stats })
}
- if (client.config.embed.field.enable) embed.addField(client.config.embed.field.title, client.config.embed.field.description.replaceAll('{{time}}', format))
+ 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.button.enable) {
- const button = new MessageActionRow
+ const button = new ActionRowBuilder
if (client.config.button.btn1.label.length !== 0 && client.config.button.btn1.url.length !== 0) {
button.addComponents(
- new MessageButton()
+ new ButtonBuilder()
.setLabel(client.config.button.btn1.label)
- .setStyle('LINK')
+ .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 MessageButton()
+ new ButtonBuilder()
.setLabel(client.config.button.btn2.label)
- .setStyle('LINK')
+ .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 MessageButton()
+ new ButtonBuilder()
.setLabel(client.config.button.btn3.label)
- .setStyle('LINK')
+ .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 MessageButton()
+ new ButtonBuilder()
.setLabel(client.config.button.btn4.label)
- .setStyle('LINK')
+ .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 MessageButton()
+ new ButtonBuilder()
.setLabel(client.config.button.btn5.label)
- .setStyle('LINK')
+ .setStyle(ButtonStyle.Link)
.setURL(client.config.button.btn5.url)
)
}
diff --git a/index.js b/index.js
index 5df5536..b1694be 100644
--- a/index.js
+++ b/index.js
@@ -7,8 +7,8 @@ if (Number(process.version.split('.')[0]) < 16) {
}
if (fs.existsSync('./node_modules')) {
const check = require('./node_modules/discord.js/package.json')
- if (Number(check.version.split('.')[0]) !== 13) {
- console.log('Invalid Discord.JS Version!, Please use Discord.JS 13.x')
+ if (Number(check.version.split('.')[0]) !== 14) {
+ console.log('Invalid Discord.JS Version!, Please use Discord.JS 14.x')
process.exit()
}
} else {
@@ -25,26 +25,30 @@ if (fs.existsSync('./node_modules')) {
}
}
+const path = require('node:path');
const chalk = require('chalk');
const yaml = require('js-yaml');
-const { Client, Intents } = require('discord.js');
-const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
+const { Client, GatewayIntentBits } = require('discord.js');
const config = yaml.load(fs.readFileSync('./config.yml', 'utf8'));
client.config = config
-const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
+const client = new Client({ intents: [GatewayIntentBits.Guilds] });
+
+const eventsPath = path.join(__dirname, 'events');
+const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
- 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));
- }
+ 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));
+ }
}
-if (client.config.token.startsWith('Put')) {
+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()
}
diff --git a/package.json b/package.json
index 5f0b5ac..90846dd 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,24 @@
{
"name": "pterostats",
- "version": "v2.0.0",
+ "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"
+ "email": "hirzidevs@gmail.com",
+ "url": "https://github.com/HirziDevs/PteroStats"
},
"scripts": {
- "start": "node index.js"
+ "start": "node index.js"
},
"dependencies": {
- "axios": "^0.27.2",
- "chalk": "4.1.1",
- "discord.js": "^13.8.1",
- "js-yaml": "^4.1.0"
+ "axios": "^0.27.2",
+ "chalk": "4.1.1",
+ "discord.js": "^14.6.0",
+ "js-yaml": "^4.1.0"
},
"engines": {
- "node": "^16.x"
+ "node": "^16.x"
}
}
\ No newline at end of file
From f3e192720acb053827aac3863c228fcb5dc54db1 Mon Sep 17 00:00:00 2001
From: Hirzi <64255651+HirziDevs@users.noreply.github.com>
Date: Thu, 3 Nov 2022 04:44:11 +0000
Subject: [PATCH 27/27] Some changes
---
Indo.md | 2 +-
README.md | 2 +-
events/ready.js | 38 ++---
handlers/checkStatus.js | 254 +++++++++++++++++-----------------
handlers/postStatus.js | 298 ++++++++++++++++++++--------------------
index.js | 60 ++++----
package.json | 44 +++---
7 files changed, 347 insertions(+), 351 deletions(-)
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