mirror of
https://github.com/HirziDevs/PteroStats
synced 2026-02-03 19:42:41 +00:00
51
README.md
51
README.md
@@ -1,3 +1,5 @@
|
||||
# THIS BUILD HASN'T BEEN TESTED WITH NODE THAT WINGS DOWN
|
||||
|
||||
# PteroStats
|
||||
|
||||

|
||||
@@ -16,7 +18,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 +29,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`
|
||||

|
||||
|
||||
### 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`
|
||||

|
||||
if you need help contact me on discord `Hirzi#8701` or join [our discord server here](https://discord.gg/zv6maQRah3)
|
||||
|
||||
### Setuping Config
|
||||
|
||||
@@ -72,7 +56,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 +89,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
|
||||
|
||||
@@ -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
|
||||
|
||||
447
events/ready.js
447
events/ready.js
@@ -1,11 +1,14 @@
|
||||
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 nodetable = new db.table('node')
|
||||
const paneltable = new db.table('panel')
|
||||
const chalk = require('chalk')
|
||||
const config = client.config
|
||||
const nodelist = client.nodelist
|
||||
|
||||
let enablecs = config.botstatus.enable
|
||||
let cs = config.botstatus.text
|
||||
@@ -14,7 +17,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
|
||||
@@ -60,269 +62,234 @@ 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/9Z7zpdwATZ'))
|
||||
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!'))
|
||||
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 === 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 = statsname + ' [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
|
||||
paneltable.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
|
||||
})
|
||||
})
|
||||
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)
|
||||
})
|
||||
|
||||
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
|
||||
paneltable.set('userCount', res)
|
||||
}).catch((err) => {
|
||||
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)
|
||||
})
|
||||
|
||||
if (stats.mode === true) statsname = stats.status + " [Maintance]"
|
||||
let userCount = paneltable.get('userCount')
|
||||
let serverCount = paneltable.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') paneltable.set('panel', '**Panel**: ' + statusonline)
|
||||
if (userCount === 'N/A') {
|
||||
paneltable.set('panel', '**Panel**: ' + statusoffline)
|
||||
console.log(chalk.cyan('[PteroStats Checker] ') + chalk.red('panel is down!'))
|
||||
}
|
||||
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
|
||||
|
||||
let nodes
|
||||
list.forEach((d) => {
|
||||
if (!nodes) return nodes = d
|
||||
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))
|
||||
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)
|
||||
})
|
||||
let embedfooter = 'Updated every ' + time + ' seconds'
|
||||
if (enablef === true) embedfooter = 'Updated every ' + time + ' seconds | ' + footer
|
||||
|
||||
axios(api + '/application/servers', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + adminapikey
|
||||
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')
|
||||
}
|
||||
|
||||
1
index.js
1
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)
|
||||
|
||||
23
nodes.js
23
nodes.js
@@ -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;
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user