From 5ab426ce5b9995817747270a11fcac0f495e1a01 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:30:26 +0700 Subject: [PATCH 1/9] v1.4.0 --- events/ready.js | 437 ++++++++++++++++++++++-------------------------- 1 file changed, 198 insertions(+), 239 deletions(-) diff --git a/events/ready.js b/events/ready.js index 3ef88a3..7a299d5 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,11 +1,13 @@ module.exports = client => { + + //Code are very sensitive, please changes things on config.yml instead + const { MessageEmbed } = require('discord.js') const axios = require('axios') const db = require('quick.db') const nodetable = new db.table('nodetable') const chalk = require('chalk') const config = client.config - const nodelist = client.nodelist let enablecs = config.botstatus.enable let cs = config.botstatus.text @@ -14,7 +16,6 @@ module.exports = client => { let time = config.refreshtime let hosturl = config.panel.url - let apikey = config.panel.clientkey let adminapikey = config.panel.adminkey let statusonline = config.status.online @@ -63,266 +64,224 @@ module.exports = client => { console.log(chalk.green('Version: ') + chalk.cyan('Stable v1.4.0')) console.log(chalk.green('Refresh Time: ') + chalk.cyan(time + ' Seconds')) console.log(chalk.green('Bot Status: ') + chalk.cyan('Online')) - console.log(chalk.green('Support: ') + chalk.cyan('https://discord.gg/9Z7zpdwATZ')) + console.log(chalk.green('Support: ') + chalk.cyan('https://discord.gg/zv6maQRah3')) console.log(chalk.red('=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')) setInterval(() => { if (isNaN(time)) return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red(time + ' is not a number!')) if (!hosturl.includes('.')) return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red(hosturl + ' is invalid url!')) - if (apikey.length < 48) return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Invalid Client Apikey!!')) if (adminapikey.length < 48) return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Invalid Admin Apikey!!')) let list = [] - nodelist.forEach(data => { - if (data.id === 'Server ID') return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('You need to use a valid server')) - axios(api + '/client/servers/' + data.id + '/resources', { + axios(api + '/application/nodes/', { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + adminapikey + } + }).then(response => { + let data = response.data.data + data.forEach(nodes => { + let id = nodes.attributes.id + axios(api + '/application/nodes/' + id + '?include=servers,location,allocations', { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + adminapikey + } + }).then(node => { + axios(api + '/application/nodes/' + id + '/configuration', { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + adminapikey + } + }).then(data => { + axios(node.data.attributes.scheme + '://' + node.data.attributes.fqdn + ':' + node.data.attributes.daemon_listen + '/api/servers', { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + data.data.token + } + }).then(status => { + let ram = 'temp' + let disk = 'temp' + + const mode = node.data.attributes.maintenance_mode + const loc = '[Locations: ' + node.data.attributes.relationships.location.attributes.short + ']' + const port = '[Allocations: ' + node.data.attributes.relationships.allocations.data.length + ']' + const servers = '[Servers: ' + node.data.attributes.relationships.servers.data.length + ']' + const rampercent = '[Ram: ' + Math.floor(node.data.attributes.allocated_resources.memory / node.data.attributes.memory * 100) + '%/100%]' + const diskpercent = '[Disk: ' + Math.floor(node.data.attributes.allocated_resources.disk / node.data.attributes.disk * 100) + '%/100%]' + const rammega = '[Ram: ' + node.data.attributes.allocated_resources.memory + 'MB/' + node.data.attributes.memory + 'MB]' + const diskmega = '[Disk: ' + node.data.attributes.allocated_resources.disk + 'MB/' + node.data.attributes.disk + 'MB]' + const ramgiga = '[Ram: ' + Math.floor(node.data.attributes.allocated_resources.memory / 1000) + 'GB/' + Math.floor(node.data.attributes.memory / 1000) + 'GB]' + const diskgiga = '[Disk: ' + Math.floor(node.data.attributes.allocated_resources.disk / 1000) + 'GB/' + Math.floor(node.data.attributes.disk / 1000) + 'GB]' + if (unit === 'mb') { + disk = diskmega + ram = rammega + } + if (unit === 'gb') { + disk = diskgiga + ram = ramgiga + } + if (unit === 'percent') { + disk = diskpercent + ram = rampercent + } + + nodetable.set('node' + id, { + ram: ram, + disk: disk, + status: true, + servers: servers, + location: loc, + port: port, + mode: mode + }) + + }).catch((err) => { + let servers = '[Servers: N/A]' + let loc = '[Location: N/A]' + let port = '[Allocations: N/A]' + let ram = '[Ram: N/A]' + let disk = '[Disk: N/A]' + + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red(node.data.attributes.name + ' is down!')) + if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + chalk.red(err) + chalk.cyan(' Need Support? https://discord.gg/zv6maQRah3')) + + nodetable.set('node' + id, { + ram: ram, + disk: disk, + status: false, + servers: servers, + location: loc, + port: port, + mode: false + }) + }) + }).catch((err) => { + console.log(chalk.magenta('[PteroStats Debug] ') + chalk.red(err) + chalk.cyan(' Need Support? https://discord.gg/zv6maQRah3')) + }) + }).catch((err) => { + console.log(chalk.magenta('[PteroStats Debug] ') + chalk.red(err) + chalk.cyan(' Need Support? https://discord.gg/zv6maQRah3')) + }) + + let stats = nodetable.get('node' + id) + let msgStats = '' + if (!stats) msgStats = '**' + nodes.attributes.name + '**: ' + checking + if (stats) { + let statsname = '**' + nodes.attributes.name + '**: ' + + if (stats.status === true) statsname = statsname + statusonline + if (stats.status === false) statsname = statsname + statusoffline + + if (stats.mode === true) statsname = stats.status + " [Maintance]" + + if (resource === true) statsname = statsname + '\n```\n' + stats.ram + '\n' + stats.disk + if (serverloc === true) statsname = statsname + '\n' + stats.location + if (serverport === true) statsname = statsname + '\n' + stats.port + if (serverres === true) statsname = statsname + '\n' + stats.servers + if (resource === false) statsname = statsname + '\n' + + if (resource === true) msgStats = statsname + '```\n' + } + + if (debug === true) console.log(chalk.magenta('[PteroStats Debug] ') + chalk.blue(nodes.attributes.name + ': ' + stats.status)) + list.push(msgStats) + }) + + axios(api + '/application/servers', { method: 'GET', headers: { Accept: 'application/json', 'Content-Type': 'application/json', - Authorization: 'Bearer ' + apikey + Authorization: 'Bearer ' + adminapikey } - }).then((response) => { - axios(api + '/application/nodes/' + data.nodeid + '?include=servers,location,allocations', { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + adminapikey - } - }).then(response => { - - let ram = 'temp' - let disk = 'temp' - - const mode = response.data.attributes.maintenance_mode - const loc = '[Locations: ' + response.data.attributes.relationships.location.attributes.short + ']' - const port = '[Allocations: ' + response.data.attributes.relationships.allocations.data.length + ']' - const servers = '[Servers: ' + response.data.attributes.relationships.servers.data.length + ']' - const rampercent = '[Ram: ' + Math.floor(response.data.attributes.allocated_resources.memory / response.data.attributes.memory * 100) + '%/100%]' - const diskpercent = '[Disk: ' + Math.floor(response.data.attributes.allocated_resources.disk / response.data.attributes.disk * 100) + '%/100%]' - const rammega = '[Ram: ' + response.data.attributes.allocated_resources.memory + 'MB/' + response.data.attributes.memory + 'MB]' - const diskmega = '[Disk: ' + response.data.attributes.allocated_resources.disk + 'MB/' + response.data.attributes.disk + 'MB]' - const ramgiga = '[Ram: ' + Math.floor(response.data.attributes.allocated_resources.memory / 1000) + 'GB/' + Math.floor(response.data.attributes.memory / 1000) + 'GB]' - const diskgiga = '[Disk: ' + Math.floor(response.data.attributes.allocated_resources.disk / 1000) + 'GB/' + Math.floor(response.data.attributes.disk / 1000) + 'GB]' - if (unit === 'mb') { - disk = diskmega - ram = rammega - } - if (unit === 'gb') { - disk = diskgiga - ram = ramgiga - } - if (unit === 'percent') { - disk = diskpercent - ram = rampercent - } - - let status = '**' + data.name + '**: ' + statusonline - - nodetable.set(data.nameid, { - ram: ram, - disk: disk, - status: status, - servers: servers, - location: loc, - port: port, - mode: mode - }) - }).catch(err => { - let status = '**' + data.name + '**: ' + statusonline - let servers = '[Servers: N/A]' - let loc = '[Location: N/A]' - let port = '[Allocations: N/A]' - let ram = '[Ram: N/A]' - let disk = '[Disk: N/A]' - - console.log(chalk.cyan('[PteroStats Checker] [Node Resource] ') + chalk.red(data.name + ' node resource is down, make sure you put right id or vaild node id!')) - if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] [Node Resource] ') + chalk.red(err)) - - nodetable.set(data.nameid, { - ram: ram, - disk: disk, - status: status, - servers: servers, - location: loc, - port: port, - mode: false - }) - }) - + }).then(ser => { + let res = ser.data.meta.pagination.total + db.set('serverCount', res) }).catch((err) => { - console.log(chalk.cyan('[PteroStats Checker] [Node Status]') + chalk.red(data.name + ' is down!')) - if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] [Node Status] ') + err) - axios(api + '/application/nodes/' + data.nodeid + '?include=servers,location,allocations', { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + adminapikey - } - }).then(response => { - - let ram = 'temp' - let disk = 'temp' - - const mode = response.data.attributes.maintenance_mode - const loc = '[Locations: ' + response.data.attributes.relationships.location.attributes.short + ']' - const port = '[Allocations: ' + response.data.attributes.relationships.allocations.data.length + ']' - const servers = '[Servers: ' + response.data.attributes.relationships.servers.data.length + ']' - const rampercent = '[Ram: ' + Math.floor(response.data.attributes.allocated_resources.memory / response.data.attributes.memory * 100) + '%/100%]' - const diskpercent = '[Disk: ' + Math.floor(response.data.attributes.allocated_resources.disk / response.data.attributes.disk * 100) + '%/100%]' - const rammega = '[Ram: ' + response.data.attributes.allocated_resources.memory + 'MB/' + response.data.attributes.memory + 'MB]' - const diskmega = '[Disk: ' + response.data.attributes.allocated_resources.disk + 'MB/' + response.data.attributes.disk + 'MB]' - const ramgiga = '[Ram: ' + Math.floor(response.data.attributes.allocated_resources.memory / 1000) + 'GB/' + Math.floor(response.data.attributes.memory / 1000) + 'GB]' - const diskgiga = '[Disk: ' + Math.floor(response.data.attributes.allocated_resources.disk / 1000) + 'GB/' + Math.floor(response.data.attributes.disk / 1000) + 'GB]' - if (unit === 'mb') { - disk = diskmega - ram = rammega - } - if (unit === 'gb') { - disk = diskgiga - ram = ramgiga - } - if (unit === 'percent') { - disk = diskpercent - ram = rampercent - } - - let status = '**' + data.name + '**: ' + statusoffline - - nodetable.set(data.nameid, { - ram: ram, - disk: disk, - status: status, - servers: servers, - location: loc, - port: port, - mode: mode - }) - - }).catch(err => { - let status = '**' + data.name + '**: ' + statusoffline - let servers = '[Servers: N/A]' - let port = '[Allocations: N/A]' - let loc = '[Location: N/A]' - let ram = '[Ram: N/A]' - let disk = '[Disk: N/A]' - - console.log(chalk.cyan('[PteroStats Checker] [Node Resource] ') + chalk.red(data.name + ' node resource is down, make sure you put right id or vaild node id!')) - if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] [Node Resource] ') + chalk.red(err)) - - nodetable.set(data.nameid, { - ram: ram, - disk: disk, - status: status, - servers: servers, - location: loc, - port: port, - mode: false - }) - }) + db.set('serverCount', 'N/A') + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down')) + if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) }) - let stats = nodetable.get(data.nameid) - let msgStats = '' - if (!stats) msgStats = '**' + data.name + '**: ' + checking - if (stats) { - let statsname = stats.status + axios(api + '/application/users', { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + adminapikey + } + }).then(usr => { + let res = usr.data.meta.pagination.total + db.set('userCount', res) + }).catch((err) => { + db.set('userCount', 'N/A') + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down!')) + if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) + }) - if (stats.mode === true) statsname = stats.status + " [Maintance]" + let userCount = db.get('userCount') + let serverCount = db.get('serverCount') - if (resource === true) statsname = statsname + '\n```\n' + stats.ram + '\n' + stats.disk - if (serverloc === true) statsname = statsname + '\n' + stats.location - if (serverport === true) statsname = statsname + '\n' + stats.port - if (serverres === true) statsname = statsname + '\n' + stats.servers - if (resource === false) statsname = statsname + '\n' + if (userCount === null) userCount = checking + if (serverCount === null) serverCount = checking - if (resource === true) msgStats = statsname + '```\n' + if (userCount !== 'N/A') db.set('panel', '**Panel**: ' + statusonline) + if (userCount === 'N/A') { + db.set('panel', '**Panel**: ' + statusoffline) + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('panel is down!')) + } + if (userCount === checking) db.set('panel', '**Panel**: ' + checking) + let panel = db.get('panel') + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount + + if (panel === null) panel = '**Panel**: ' + checking + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount + + let nodes + list.forEach((d) => { + if (!nodes) return nodes = d + nodes = nodes + d + }) + + let nodeCount = '[Total ' + list.length + ']' + + if (debug === true) console.log(chalk.magenta('[PteroStats Debug] ') + chalk.blue(nodes)) + if (nodes === undefined) { + nodes = checking + ' Please wait ' + time + ' seconds' + console.log(chalk.cyan(['[PteroStats Checker] ']) + chalk.yellow(checking + ' Please wait ' + time + ' seconds')) } - if (debug === true) console.log(chalk.magenta('[PteroStats Debug] ') + chalk.blue(msgStats)) - list.push(msgStats) - }) - - axios(api + '/application/servers', { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + adminapikey + let embedfooter = 'Updated every ' + time + ' seconds' + if (enablef === true) embedfooter = 'Updated every ' + time + ' seconds | ' + footer + let embed = new MessageEmbed() + .setTitle(title) + .setColor(color) + .addField('Panel Stats', panel) + .setFooter(embedfooter) + .setThumbnail(client.user.avatarURL()) + if (enablets === true) { + embed.setTimestamp() } - }).then(response => { - let res = response.data.meta.pagination.total - db.set('serverCount', res) - }).catch(err => { - db.set('serverCount', 'N/A') - console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down')) - if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) - }) - - axios(api + '/application/users', { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + adminapikey + if (enabledesc === true) { + embed.setDescription(desc + '\n**Nodes Stats' + nodeCount + '**\n' + nodes) + } else { + embed.setDescription('\n**Nodes Stats' + nodeCount + '**\n' + nodes) } - }).then(response => { - let res = response.data.meta.pagination.total - db.set('userCount', res) - }).catch(err => { - db.set('userCount', 'N/A') - console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down!')) - if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) + + ch.send(embed).then(msg => { msg.delete({ timeout: time + '000' }) }) + + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Posted Stats')) + if (panel !== null) console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Stats Updated')) + console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Updating Stats in ' + time + ' Seconds')) + + }).catch((err) => { + console.log(chalk.magenta('[PteroStats Debug] ') + chalk.red(err) + chalk.cyan(' Need Support? https://discord.gg/zv6maQRah3')) }) - - let userCount = db.get('userCount') - let serverCount = db.get('serverCount') - - if (userCount === null) userCount = checking - if (serverCount === null) serverCount = checking - - if (userCount !== 'N/A') db.set('panel', '**Panel**: ' + statusonline) - if (userCount === 'N/A') { - db.set('panel', '**Panel**: ' + statusoffline) - console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('panel is down!')) - } - if (userCount === checking) db.set('panel', '**Panel**: ' + checking) - let panel = db.get('panel') + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount - - if (panel === null) panel = '**Panel**: ' + checking + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount - - let nodes - list.forEach((d) => { - if (!nodes) return nodes = d - nodes = nodes + d - }) - let nodeCount = '[Total ' + list.length + ']' - - if (nodes === undefined) nodes = checking + 'Please wait ' + time + 'seconds' - - let embedfooter = 'Updated every ' + time + ' seconds' - if (enablef === true) embedfooter = 'Updated every ' + time + ' seconds | ' + footer - let embed = new MessageEmbed() - .setTitle(title) - .setColor(color) - .addField('Panel Stats', panel) - .setFooter(embedfooter) - .setThumbnail(client.user.avatarURL()) - if (enablets === true) { - embed.setTimestamp() - } - if (enabledesc === true) { - embed.setDescription(desc + '\n**Nodes Stats' + nodeCount + '**\n' + nodes) - } else { - embed.setDescription('\n**Nodes Stats' + nodeCount + '**\n' + nodes) - } - - ch.send(embed).then(msg => { msg.delete({ timeout: time + '000' }) }) - - console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Posted Stats')) - if (panel !== null) console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Stats Updated')) - console.log(chalk.cyan('[PteroStats Checker] ') + chalk.green('Updating Stats in ' + time + ' Seconds')) }, time + '000') } From 241e1006b9364139675ed6762093ca6df6341e6a Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:31:12 +0700 Subject: [PATCH 2/9] Update config.yml --- config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/config.yml b/config.yml index 0aa9bb8..2c8a473 100644 --- a/config.yml +++ b/config.yml @@ -15,7 +15,6 @@ refreshtime: 60 # Time when the embed edited/refreshed (MUST BE A SECONDS) (RECO # Panel Info's panel: url: 'HOST PANEL LINK' # Put panel url here. Example: https://panel.purenodes.net - clientkey: 'CLIENT APIKEY' # Put Client ApiKey here. check https://your.host.url/account/api (your.host.url is an example link)to get the Client Apikey adminkey: 'ADMIN APIKEY' # Put Admin Apikey here. check https://your.host.url/admin/api (your.host.url is an example link) to get the Admin ApiKey # Embed Configuration From e7bb8573de745519609ba40fe879848298738564 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:31:56 +0700 Subject: [PATCH 3/9] Update index.js --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index d672abe..4cf5d39 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ const client = new Client() const yaml = require('js-yaml') const config = yaml.load(fs.readFileSync('./config.yml', 'utf8')) client.config = config -client.nodelist = require('./nodes.js') fs.readdir('./events/', (err, files) => { if (err) return console.error(err) From d54f8cf236bdf6df793902736355f082b17a1794 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:35:46 +0700 Subject: [PATCH 4/9] Delete nodes.js --- nodes.js | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 nodes.js diff --git a/nodes.js b/nodes.js deleted file mode 100644 index c952a33..0000000 --- a/nodes.js +++ /dev/null @@ -1,23 +0,0 @@ -let nodelist = [ - { - id: 'Server ID', - name: 'Example Server 1', - nameid: 'Node1', - nodeid: '1' - }, - { - id: 'Server ID', - name: 'Example Server 2', - nameid: 'Node2', - nodeid: '2' - }, - //Add more code like bellow to the nodeslist array after comma and before ']' if you want to add more nodes - //{ - // id: 'Server ID', - // name: 'Example Server 3', - // nameid: 'Node3', - // nodeid: '1' - //}, -] - -module.exports = nodelist; From 96eea93d49fd2bde162ac2145cff29f659b927b1 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:36:11 +0700 Subject: [PATCH 5/9] Update ready.js --- events/ready.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/ready.js b/events/ready.js index 7a299d5..67b433a 100644 --- a/events/ready.js +++ b/events/ready.js @@ -61,7 +61,7 @@ module.exports = client => { console.log(chalk.red('=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')) console.log(chalk.green('Name: ') + chalk.cyan('PteroStats')) - console.log(chalk.green('Version: ') + chalk.cyan('Stable v1.4.0')) + console.log(chalk.green('Version: ') + chalk.cyan('Stable pre-v1.5.0')) console.log(chalk.green('Refresh Time: ') + chalk.cyan(time + ' Seconds')) console.log(chalk.green('Bot Status: ') + chalk.cyan('Online')) console.log(chalk.green('Support: ') + chalk.cyan('https://discord.gg/zv6maQRah3')) From ec836b75346422f34f8cebd1b5d40b9fc1566f72 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:36:34 +0700 Subject: [PATCH 6/9] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 65c4074..498bad0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pterostats", - "version": "v1.4.0", + "version": "v1.5.0", "description": "PteroStats is a bot designed to check Panel, Nodes, and Databases status and post it to your discord server", "license": "Apache-2.0", "repository": "HirziDevs/PteroStats", From 7e308f21c4a77f0d808a9722a38cb4ae916666a6 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:37:59 +0700 Subject: [PATCH 7/9] Update README.md --- README.md | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f4fa333..f605659 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ PteroStats is still **under development** and we welcome contributions. ### How it works? -PteroStats checks [pterodactyl](https://pterodactyl.io) server(s) [resource api](https://dashflo.net/docs/api/pterodactyl/v1/#req_a8875d2840c64cbdb40e9bdb6cba4f75) with [axios](https://www.npmjs.com/package/axios) to get server resource, if the api didn't reply that mean the node of the server is getting [wings/daemon](https://pterodactyl.io/wings/1.0/installing.html) down and mark the node as offline +PteroStats checks [pterodactyl](https://pterodactyl.io) nodes wings with [axios](https://www.npmjs.com/package/axios) to get nodes wings status, if the api didn't reply that mean the node is having [wings/daemon](https://pterodactyl.io/wings/1.0/installing.html) down and mark the node as offline ### Screenshot @@ -27,29 +27,11 @@ PteroStats checks [pterodactyl](https://pterodactyl.io) server(s) [resource api] ## Installation -- `Create server for each nodes at your pterodactyl panel and copy the server id` -- `Go to your node list at admin panel, the go to the node you want to get id, and then look the web link, the last number after nodes/ is your node id` -- `Paste the server id and node id at nodelist array` [nodes.js](https://github.com/HirziDevs/PteroStats/blob/main/nodes.js) - `fill in the required informations in the config.yml file` - `Run npm install in the root directory of the bot files` - `Run node index.js and you are done` -- `To add more nodes go to this link` [This Link](https://github.com/HirziDevs/PteroStats###adding-more-nodes) -### Getting ServerID - -- `Go to your pterodactyl panel` -- `And then select server you want to use` -- `Go to settings tab` -- `Scroll, go to debug information and you will find server id` -- `Copy the first word like on this image` -![img](https://media.discordapp.net/attachments/626755594526916629/864446387387367424/20210713_165459.jpg) - -### Getting NodeID - -- `Go to your location page at your pterodactyl admin panel` -- `Look at before your nodes name` -- `The nodes id will be there like on this image` -![img](https://media.discordapp.net/attachments/586738538448420881/866623684121591838/Screenshot_2021-07-19-17-12-42-90.jpg) +if you need help contact me on discord `Hirzi#8701` or join [our discord server here](https://discord.gg/zv6maQRah3) ### Setuping Config @@ -72,7 +54,6 @@ refreshtime: 60 # Time when the embed edited/refreshed (MUST BE A SECONDS) (RECO # Panel Info's panel: url: 'HOST PANEL LINK' # Put panel url here. Example: https://panel.purenodes.net - clientkey: 'CLIENT APIKEY' # Put Client ApiKey here. check https://your.host.url/account/api (your.host.url is an example link)to get the Client Apikey adminkey: 'ADMIN APIKEY' # Put Admin Apikey here. check https://your.host.url/admin/api (your.host.url is an example link) to get the Admin ApiKey # Embed Configuration @@ -106,35 +87,9 @@ debug: false # Enable and Disable debug log to console debugaxios: false #Enable and Disable axios error logs ``` -### Adding more nodes - -Add more items like bellow per each node to `nodelist` array at [nodes.js](https://github.com/HirziDevs/PteroStats/blob/main/nodes.js) -``` -{ - id: "Server ID", - name: "**Example Server**", - nameid: "Node1", - nodeid: "1" -}, -``` - -if you need help contact me on discord `Hirzi#8701` or join [our discord server here](https://discord.gg/zv6maQRah3) - ## Other ### FAQ -Q: The node is online but the bot said offline - -A: Make sure the serverid is correct and the server is not on installation progress - -- - -Q: Do the server must be online? - -A: No, the bot can still checks server while it online or offline - -- - Q: Can i use pterodactyl v0.7? A: No, the pterodactyl v0.7 is not supported From 0a17908c7e4aa05f5fb4e52024fd30826c708c8d Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:55:10 +0700 Subject: [PATCH 8/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f605659..46124a1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# THIS BUILD HASN'T BEEN TESTED WITH NODE THAT WINGS DOWN + # PteroStats ![GitHub](https://img.shields.io/github/package-json/v/HirziDevs/PteroStats?style=flat-square) From c8df400a8ad26f1f776a63a2623bfd5925bea8f5 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Wed, 21 Jul 2021 07:20:28 +0700 Subject: [PATCH 9/9] Update ready.js --- events/ready.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/events/ready.js b/events/ready.js index 67b433a..fed6075 100644 --- a/events/ready.js +++ b/events/ready.js @@ -5,7 +5,8 @@ module.exports = client => { const { MessageEmbed } = require('discord.js') const axios = require('axios') const db = require('quick.db') - const nodetable = new db.table('nodetable') + const nodetable = new db.table('node') + const paneltable = new db.table('panel') const chalk = require('chalk') const config = client.config @@ -66,6 +67,11 @@ module.exports = client => { console.log(chalk.green('Bot Status: ') + chalk.cyan('Online')) console.log(chalk.green('Support: ') + chalk.cyan('https://discord.gg/zv6maQRah3')) console.log(chalk.red('=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')) + console.log(chalk.red('You are using dev build, something not wanted might be happen!')) + + if(paneltable.get('URL') === null) console.log(chalk.cyan('It seems you are using our bot for first time, thank you for choosing our bot, if you need help you can join our support server!')) + if(paneltable.get('URL') !== api) console.log(chalk.cyan('Panel url changed, please allow the bot to check the nodes status for ' + time + ' seconds')) + paneltable.set('URL',api) setInterval(() => { if (isNaN(time)) return console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red(time + ' is not a number!')) @@ -173,14 +179,14 @@ module.exports = client => { let stats = nodetable.get('node' + id) let msgStats = '' - if (!stats) msgStats = '**' + nodes.attributes.name + '**: ' + checking + if (stats === null) msgStats = '**' + nodes.attributes.name + '**: ' + checking if (stats) { let statsname = '**' + nodes.attributes.name + '**: ' if (stats.status === true) statsname = statsname + statusonline if (stats.status === false) statsname = statsname + statusoffline - if (stats.mode === true) statsname = stats.status + " [Maintance]" + if (stats.mode === true) statsname = statsname + ' [Maintance]' if (resource === true) statsname = statsname + '\n```\n' + stats.ram + '\n' + stats.disk if (serverloc === true) statsname = statsname + '\n' + stats.location @@ -204,9 +210,9 @@ module.exports = client => { } }).then(ser => { let res = ser.data.meta.pagination.total - db.set('serverCount', res) + paneltable.set('serverCount', res) }).catch((err) => { - db.set('serverCount', 'N/A') + paneltable.set('serverCount', 'N/A') console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down')) if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) }) @@ -220,26 +226,26 @@ module.exports = client => { } }).then(usr => { let res = usr.data.meta.pagination.total - db.set('userCount', res) + paneltable.set('userCount', res) }).catch((err) => { - db.set('userCount', 'N/A') + paneltable.set('userCount', 'N/A') console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('Panel is down!')) if (debugerror === true) console.log(chalk.magenta('[PteroStats Debug] ') + err) }) - let userCount = db.get('userCount') - let serverCount = db.get('serverCount') + let userCount = paneltable.get('userCount') + let serverCount = paneltable.get('serverCount') if (userCount === null) userCount = checking if (serverCount === null) serverCount = checking - if (userCount !== 'N/A') db.set('panel', '**Panel**: ' + statusonline) + if (userCount !== 'N/A') paneltable.set('panel', '**Panel**: ' + statusonline) if (userCount === 'N/A') { - db.set('panel', '**Panel**: ' + statusoffline) + paneltable.set('panel', '**Panel**: ' + statusoffline) console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('panel is down!')) } - if (userCount === checking) db.set('panel', '**Panel**: ' + checking) - let panel = db.get('panel') + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount + if (userCount === checking) paneltable.set('panel', '**Panel**: ' + checking) + let panel = paneltable.get('panel') + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount if (panel === null) panel = '**Panel**: ' + checking + '\n\nUsers: ' + userCount + '\nServers: ' + serverCount @@ -249,6 +255,7 @@ module.exports = client => { nodes = nodes + d }) + console.log(chalk.cyan(['[PteroStats Checker] ']) + chalk.green('Connected to ' + list.length + ' nodes') let nodeCount = '[Total ' + list.length + ']' if (debug === true) console.log(chalk.magenta('[PteroStats Debug] ') + chalk.blue(nodes)) @@ -259,6 +266,7 @@ module.exports = client => { let embedfooter = 'Updated every ' + time + ' seconds' if (enablef === true) embedfooter = 'Updated every ' + time + ' seconds | ' + footer + let embed = new MessageEmbed() .setTitle(title) .setColor(color)