mirror of
https://github.com/HirziDevs/PteroStats
synced 2026-01-10 07:58:01 +00:00
feat: Nodes error logging
This commit is contained in:
6
Indo.md
6
Indo.md
@@ -114,11 +114,9 @@ Kamu bisa memasukan lebih dari 1 node untuk di blacklist
|
||||
|
||||
<img alt="Blacklist Config" src="https://usercontent.catto.pictures/hirzi/85b6a9b1-8ec9-4395-b5b1-6f85d3f52162.png" width="400"/>
|
||||
|
||||
## Permission apikey
|
||||
## Nodenya online tapi di embed dibilang offline
|
||||
|
||||
Jika kamu mengalami error 403 coba aktifkan `read & write` di semua opsi permission
|
||||
|
||||
<img alt="Application API Permission" src="https://usercontent.catto.pictures/hirzi/273d5b86-5249-42d0-bfc6-1dcfcae4efe7.png" width="400"/>
|
||||
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
|
||||
|
||||
|
||||
@@ -114,11 +114,9 @@ You can add more than one node in the blacklist
|
||||
|
||||
<img alt="Blacklist Config" src="https://usercontent.catto.pictures/hirzi/85b6a9b1-8ec9-4395-b5b1-6f85d3f52162.png" width="400"/>
|
||||
|
||||
## 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
|
||||
|
||||
<img alt="Application API Permission" src="https://usercontent.catto.pictures/hirzi/273d5b86-5249-42d0-bfc6-1dcfcae4efe7.png" width="400"/>
|
||||
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
|
||||
|
||||
|
||||
14
config.yml
14
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
|
||||
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
|
||||
@@ -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'))
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
46
index.js
46
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] });
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user