diff --git a/Indo.md b/Indo.md
index 7ec23b7..a41df97 100644
--- a/Indo.md
+++ b/Indo.md
@@ -114,11 +114,9 @@ Kamu bisa memasukan lebih dari 1 node untuk di blacklist
-## Permission apikey
+## Nodenya online tapi di embed dibilang offline
-Jika kamu mengalami error 403 coba aktifkan `read & write` di semua opsi permission
-
-
+Jika kamu mengalami isu ini, atur `log_error` menjadi true di file config dan beri tahu kami di [Support Server](https://discord.gg/zv6maQRah3)
## Links
diff --git a/README.md b/README.md
index 3fe7082..7baa5bd 100644
--- a/README.md
+++ b/README.md
@@ -114,11 +114,9 @@ You can add more than one node in the blacklist
-## Apikey permission
+## The node is online but the embed is read as offline
-If you having issue with 403 error try to enable `read & write` on all options
-
-
+If you having this issue, you can enable `log_error` on the config file and report it to our discord server at [Support Server](https://discord.gg/zv6maQRah3)
## Links
diff --git a/config.yml b/config.yml
index b29fb40..434817c 100644
--- a/config.yml
+++ b/config.yml
@@ -10,7 +10,8 @@ presence:
# Discord Channel and Refresh Time Configuration
channel: 'Put channel id here'
-refresh: 60
+refresh: 60 # How much time the bot will refresh the stats
+timeout: 1 # How much time to wait some node to respond to the bot (if you change this, it will add more time to refresh the stats)
# Panel Configuration
panel:
@@ -73,4 +74,13 @@ nodes_settings:
# Panel Users and Servers Settings
panel_settings:
servers: true
- users: true
\ No newline at end of file
+ users: true
+
+# Mentions a User or Role if some nodes are offline (this feature is still in testing, please report if you have a problem)
+mentions: # to enable atleast put 1 ID on user or role bellow
+ user: [] # Put User ID here (Example: "user: ['548867757517570058', '816219634390663230']")
+ role: [] # Put Role ID here (Example: "role: ['796083838236622858', '858198863973187585']")
+ channel: '' # Put Channel ID here for the logging
+
+# Log error to console if server offline (enable this if you have a problem that you wanted to report)
+log_error: false # set to "true" to enable
\ No newline at end of file
diff --git a/events/ready.js b/events/ready.js
index c02c793..e222be0 100644
--- a/events/ready.js
+++ b/events/ready.js
@@ -8,9 +8,19 @@ module.exports = {
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.yellow('If some node is online but the embed is read as offline, please enable ') + chalk.green('log_error') + chalk.yellow(' on config file and report it at https://discord.gg/zv6maQRah3'))
if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! This bot is not on any discord servers'))
- if (client.config.refresh < 10) console.log(chalk.cyan('[PteroStats] ') + chalk.red('Refresh lower than 10 seconds is not recommended!'))
+ if (client.config.timeout < 1) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Timeout cannot be less than 1 seconds!'))
+ client.config.timeout = 1
+ }
+
+ if (client.config.refresh > 1 && client.config.refresh < 10) console.log(chalk.cyan('[PteroStats] ') + chalk.red('Refresh Time below 10 seconds is not recommended!'))
+ else if (client.config.refresh < 1) {
+ console.log(chalk.cyan('[PteroStats] ') + chalk.red('Refresh Time cannot be less than 1 seconds!'))
+ client.config.refresh = 10
+ }
if (client.config.bot_status || client.config.nodes_resource || client.config.panel_resource) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('You used `bot_status`, `panel_resource` and `nodes_resource` instead of `presence`, `panel_settings` and `nodes_settings` in the config, please update your config file at ') + chalk.green('https://github.com/HirziDevs/PteroStats/blob/main/config.yml ') + chalk.red('before it can no longer be supported'))
diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js
index ef1d119..0b21feb 100644
--- a/handlers/checkStatus.js
+++ b/handlers/checkStatus.js
@@ -1,3 +1,4 @@
+const { EmbedBuilder } = require('discord.js')
const axios = require('axios')
const chalk = require('chalk')
@@ -5,6 +6,15 @@ const postStatus = require('./postStatus')
module.exports = function checkStatus({ client }) {
+ function Embed({ node }) {
+ return new EmbedBuilder()
+ .setTitle('Node Logging') //if you wanted to change this please change at line 175 too
+ .setDescription('`' + node.name + '` is down!')
+ .setFooter({ text: 'Please see console for more details' })
+ .setTimestamp()
+ .setColor('ED4245')
+ }
+
if (client.config.channel.startsWith('Put')) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! Invalid Channel ID'))
process.exit()
@@ -23,6 +33,7 @@ module.exports = function checkStatus({ client }) {
if (client.config.panel.url.endsWith('/')) client.config.panel.url = client.config.panel.url.slice(0, -1)
const nodes = []
+ const embeds = []
const panel = {
status: false,
@@ -113,14 +124,21 @@ module.exports = function checkStatus({ client }) {
}
}).then(() => {
return statsResolve()
- }).catch(() => {
+ }).catch((error) => {
+ if (client.config.log_error) console.log(chalk.cyan('[PteroStats] ') + chalk.yellow('[Node: ' + node.attributes.name + '] ') + chalk.red(error))
+ embeds.push(Embed({ node: body }))
body.status = false
return statsResolve()
})
setTimeout(() => {
- body.status = false
- return statsResolve()
- }, 1000)
+ if (body.status === undefined) {
+ console.log(body.status)
+ if (client.config.log_error) console.log(chalk.cyan('[PteroStats] ') + chalk.yellow('[Node: ' + node.attributes.name + '] ') + chalk.red('Timeout!'))
+ embeds.push(Embed({ node: body }))
+ body.status = false
+ return statsResolve()
+ }
+ }, client.config.timeout * 1000)
})
stats.then(() => {
nodes.push(body)
@@ -132,9 +150,41 @@ module.exports = function checkStatus({ client }) {
})
panelStats.then(() => {
- nodeStats.then(() => {
+ nodeStats.then(async () => {
nodes.sort(function (a, b) { return a.id - b.id })
postStatus({ client: client, panel: panel, nodes: nodes })
+
+ // this feature is still in testing
+ if (client.config.mentions.user.length > 0 || client.config.mentions.role.length > 0 && client.config.mentions.channel) {
+ if (Array.isArray(client.config.mentions.user) || Array.isArray(client.config.mentions.role)) {
+ let mentions = ''
+
+ await client.config.mentions.user.forEach((user) => {
+ if (!isNaN(Number(user))) {
+ mentions = mentions + ' <@' + user + '>'
+ }
+ })
+ await client.config.mentions.role.forEach((role) => {
+ if (!isNaN(Number(role))) {
+ mentions = mentions + ' <@&' + role + '>'
+ }
+ })
+
+ const channel = await client.channels.cache.get(client.config.mentions.channel)
+ if (channel) {
+ const messages = await channel.messages.fetch({ limit: 10 }).then(msg => msg.filter(m => m.author.id === client.user.id && m.embeds[0].data.title === 'Node Logging').first())
+ if (messages) messages.embeds.forEach((MsgEmbed) => {
+ embeds.forEach((embed, i) => {
+ if (MsgEmbed.data.description === embed.data.description) embeds.splice(i, 1)
+ nodes.forEach((node) => {
+ if (MsgEmbed.data.description.startsWith('`' + node.name) && node.status === true) messages.delete()
+ })
+ })
+ })
+ if (embeds.length > 0) channel.send({ content: mentions, embeds: embeds })
+ }
+ }
+ }
})
})
}
\ No newline at end of file
diff --git a/handlers/postStatus.js b/handlers/postStatus.js
index c34cae5..2389473 100644
--- a/handlers/postStatus.js
+++ b/handlers/postStatus.js
@@ -85,10 +85,12 @@ module.exports = async function postStatus({ client, panel, nodes }) {
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]
+ if (messages.embeds.length > 0 && client.config.embed.title && messages.embeds[0].data.title === client.config.embed.title) {
+ 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()
}
diff --git a/index.js b/index.js
index 6d3bffb..82a7657 100644
--- a/index.js
+++ b/index.js
@@ -1,21 +1,10 @@
const fs = require('fs');
const child = require('child_process');
-const chalk = require('chalk');
-const yaml = require('js-yaml');
-if (Number(process.version.split('.')[0]) < 16) {
- 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()
- }
-} else {
+function InstallPackages() {
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')
+ console.log('If the bot can\'t install the package please install it manually')
try {
child.execSync('npm i')
console.log('Install complete!, please run "node index" command again!')
@@ -27,6 +16,37 @@ if (fs.existsSync('./node_modules')) {
}
}
+if (Number(process.version.split('.')[0]) < 16) {
+ console.log('Invalid NodeJS Version!, Please use NodeJS 16.x or upper')
+ process.exit()
+}
+if (fs.existsSync('./node_modules')) {
+ if (fs.existsSync('./node_modules/discord.js')) {
+ 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 InstallPackages()
+ if (fs.existsSync('./node_modules/axios')) {
+ const check = require('./node_modules/axios/package.json')
+ if (Number(check.version.split('.')[1]) > 1) {
+ console.log('Invalid Axios Version!, Please use Axios 1.1.3')
+ process.exit()
+ }
+ } else InstallPackages()
+ if (fs.existsSync('./node_modules/chalk')) {
+ const check = require('./node_modules/chalk/package.json')
+ if (Number(check.version.split('.')[0]) > 4) {
+ console.log('Invalid Chalk Version!, Please use Chalk 4.1.2')
+ process.exit()
+ }
+ } else InstallPackages()
+ if (!fs.existsSync('./node_modules/js-yaml')) InstallPackages()
+} else InstallPackages()
+
+const chalk = require('chalk');
+const yaml = require('js-yaml');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
diff --git a/package.json b/package.json
index 61efb73..9a00948 100644
--- a/package.json
+++ b/package.json
@@ -14,11 +14,11 @@
},
"dependencies": {
"axios": "1.1.3",
- "chalk": "4.1.1",
- "discord.js": "^14.6.0",
+ "chalk": "4.1.2",
+ "discord.js": "^14.7.1",
"js-yaml": "^4.1.0"
},
"engines": {
- "node": "^16.x"
+ "node": ">=16.9.0"
}
}
\ No newline at end of file