From 3d0512c3323ecf079101104c7ecf3c94d265e298 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:35:26 +0700 Subject: [PATCH] Add TB Unit and other thing --- config.yml | 4 ++-- events/ready.js | 4 ++-- handlers/checkStatus.js | 11 ++++------- handlers/postStatus.js | 9 +++++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config.yml b/config.yml index 0382d39..fe1759b 100644 --- a/config.yml +++ b/config.yml @@ -21,7 +21,7 @@ panel: # set to false if you want to disable option message: content: false - image: false # If you enable image on message it upload the image first before sending or editing message and it will delay stats + attachment: false # If you enable attachment on message it upload the attachment first before sending or editing message and it will delay the stats embed: title: 'PteroStats' @@ -67,7 +67,7 @@ nodes_resource: servers: true location: true allocations: true - unit: 'gb' # You can use "gb", "mb", or "percent" + unit: 'gb' # You can use "gb", "mb", "tb", or "percent" # Panel Users and Servers panel_resource: diff --git a/events/ready.js b/events/ready.js index c486380..5f0f683 100644 --- a/events/ready.js +++ b/events/ready.js @@ -10,8 +10,8 @@ module.exports = { if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers')) - if (client.config.bot_status.enable) { - if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase())) { + if (client.config.bot_status.enable && client.config.bot_status.text.length > 0) { + if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase() || client.config.bot_status.type.length < 1 )) { console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Status Type!, Can be "WATCHING", "PLAYING", "LISTENING", or "COMPETING"')) } else { client.user.setActivity(client.config.bot_status.text, { type: client.config.bot_status.type.toUpperCase() }) diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js index 0222e34..48e2ded 100644 --- a/handlers/checkStatus.js +++ b/handlers/checkStatus.js @@ -104,7 +104,6 @@ module.exports = function checkStatus(client) { } const stats = new Promise((statsResolve, statsReject) => { - let done = false axios(node.attributes.scheme + '://' + node.attributes.fqdn + ':' + node.attributes.daemon_listen + '/api/servers', { method: 'GET', headers: { @@ -113,16 +112,14 @@ module.exports = function checkStatus(client) { Authorization: 'Bearer ' + data.data.token } }).then((status) => { - done = true - statsResolve() + return statsResolve() }).catch((err) => { body.status = false - done = true - statsResolve() + return statsResolve() }) setTimeout(() => { - if (!done) body.status = false - statsResolve() + body.status = false + return statsResolve() }, 1000) }) stats.then(() => { diff --git a/handlers/postStatus.js b/handlers/postStatus.js index 87a8a51..1cbe00a 100644 --- a/handlers/postStatus.js +++ b/handlers/postStatus.js @@ -6,7 +6,7 @@ module.exports = async function postStatus(client, panel, nodes) { if (!client.config.nodes_resource) client.config.nodes_resource = client.config.resource if (!client.config.nodes_resource.blacklist) client.config.nodes_resource.blacklist = [] if (!Array.isArray(client.config.nodes_resource.blacklist) && Number.isInteger(client.config.nodes_resource.blacklist)) client.config.nodes_resource.blacklist = [client.config.nodes_resource.blacklist] - if (!['mb', 'gb', 'percent'].includes(client.config.nodes_resource.unit.toLowerCase())) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! Invalid Unit at nodes config')) + if (!client.config.message.attachment) client.config.message.attachment = client.config.message.image if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Err! This bot is not on any discord servers')) @@ -31,7 +31,7 @@ module.exports = async function postStatus(client, panel, nodes) { const files = [] if (client.config.message.content) content = client.config.message.content - if (client.config.message.image) files.push(new MessageAttachment(client.config.message.image)) + if (client.config.message.attachment) files.push(new MessageAttachment(client.config.message.attachment)) if (client.config.embed.title) embed.setTitle(client.config.embed.title) if (client.config.embed.description) desc = client.config.embed.description + '\n' @@ -50,6 +50,11 @@ module.exports = async function postStatus(client, panel, nodes) { const title = data.name + ': ' + String(data.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) let description = '```' switch (client.config.nodes_resource.unit.toLowerCase()) { + case 'tb': + description = description + + '\nMemory : ' + Math.floor(data.memory_min / 1000000).toLocaleString() + ' TB / ' + Math.floor(data.memory_max / 1000000).toLocaleString() + ' TB' + + '\nDisk : ' + Math.floor(data.disk_min / 1000000).toLocaleString() + ' TB / ' + Math.floor(data.disk_max / 1000000).toLocaleString() + ' TB' + break; case 'gb': description = description + '\nMemory : ' + Math.floor(data.memory_min / 1000).toLocaleString() + ' GB / ' + Math.floor(data.memory_max / 1000).toLocaleString() + ' GB' +