feat: Nodes error logging

This commit is contained in:
Hirzi
2022-12-25 12:39:53 +00:00
parent 991f42aec0
commit fa062bb42e
8 changed files with 124 additions and 36 deletions
+2 -4
View File
@@ -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"/> <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 Jika kamu mengalami isu ini, atur `log_error` menjadi true di file config dan beri tahu kami di [Support Server](https://discord.gg/zv6maQRah3)
<img alt="Application API Permission" src="https://usercontent.catto.pictures/hirzi/273d5b86-5249-42d0-bfc6-1dcfcae4efe7.png" width="400"/>
## Links ## Links
+2 -4
View File
@@ -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"/> <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 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)
<img alt="Application API Permission" src="https://usercontent.catto.pictures/hirzi/273d5b86-5249-42d0-bfc6-1dcfcae4efe7.png" width="400"/>
## Links ## Links
+12 -2
View File
@@ -10,7 +10,8 @@ presence:
# Discord Channel and Refresh Time Configuration # Discord Channel and Refresh Time Configuration
channel: 'Put channel id here' 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 Configuration
panel: panel:
@@ -73,4 +74,13 @@ nodes_settings:
# Panel Users and Servers Settings # Panel Users and Servers Settings
panel_settings: panel_settings:
servers: true 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
+11 -1
View File
@@ -8,9 +8,19 @@ module.exports = {
execute(client) { execute(client) {
console.log(chalk.cyan('[PteroStats] ') + chalk.green('Bot is up!')) 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('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.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) { 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')) 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'))
+55 -5
View File
@@ -1,3 +1,4 @@
const { EmbedBuilder } = require('discord.js')
const axios = require('axios') const axios = require('axios')
const chalk = require('chalk') const chalk = require('chalk')
@@ -5,6 +6,15 @@ const postStatus = require('./postStatus')
module.exports = function checkStatus({ client }) { 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')) { if (client.config.channel.startsWith('Put')) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! Invalid Channel ID')) console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! Invalid Channel ID'))
process.exit() 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) if (client.config.panel.url.endsWith('/')) client.config.panel.url = client.config.panel.url.slice(0, -1)
const nodes = [] const nodes = []
const embeds = []
const panel = { const panel = {
status: false, status: false,
@@ -113,14 +124,21 @@ module.exports = function checkStatus({ client }) {
} }
}).then(() => { }).then(() => {
return statsResolve() 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 body.status = false
return statsResolve() return statsResolve()
}) })
setTimeout(() => { setTimeout(() => {
body.status = false if (body.status === undefined) {
return statsResolve() console.log(body.status)
}, 1000) 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(() => { stats.then(() => {
nodes.push(body) nodes.push(body)
@@ -132,9 +150,41 @@ module.exports = function checkStatus({ client }) {
}) })
panelStats.then(() => { panelStats.then(() => {
nodeStats.then(() => { nodeStats.then(async () => {
nodes.sort(function (a, b) { return a.id - b.id }) nodes.sort(function (a, b) { return a.id - b.id })
postStatus({ client: client, panel: panel, nodes: nodes }) 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 })
}
}
}
}) })
}) })
} }
+6 -4
View File
@@ -85,10 +85,12 @@ module.exports = async function postStatus({ client, panel, nodes }) {
text = '\nThere is no nodes to display' text = '\nThere is no nodes to display'
resolve() resolve()
} else { } else {
text = messages.embeds[0].description.replaceAll(client.config.status.online, client.config.status.offline) if (messages.embeds.length > 0 && client.config.embed.title && messages.embeds[0].data.title === client.config.embed.title) {
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] !== '`') { text = messages.embeds[0].description.replaceAll(client.config.status.online, client.config.status.offline)
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] 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_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] 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() resolve()
} }
+33 -13
View File
@@ -1,21 +1,10 @@
const fs = require('fs'); const fs = require('fs');
const child = require('child_process'); const child = require('child_process');
const chalk = require('chalk');
const yaml = require('js-yaml');
if (Number(process.version.split('.')[0]) < 16) { function InstallPackages() {
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 {
console.log('You didn\'t install the required node packages first!') 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('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 { try {
child.execSync('npm i') child.execSync('npm i')
console.log('Install complete!, please run "node index" command again!') 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, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); const client = new Client({ intents: [GatewayIntentBits.Guilds] });
+3 -3
View File
@@ -14,11 +14,11 @@
}, },
"dependencies": { "dependencies": {
"axios": "1.1.3", "axios": "1.1.3",
"chalk": "4.1.1", "chalk": "4.1.2",
"discord.js": "^14.6.0", "discord.js": "^14.7.1",
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
}, },
"engines": { "engines": {
"node": "^16.x" "node": ">=16.9.0"
} }
} }