From 6e8e934b222e6c56e6384d691706ae555aac9aa1 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Thu, 8 Jul 2021 18:28:26 +0700 Subject: [PATCH] 1.1.0 Release Now you dont need to add more axios code to add more nodes Remove Databases Stats for now --- events/ready.js | 252 +++++++++++++++++++++++++----------------------- 1 file changed, 130 insertions(+), 122 deletions(-) diff --git a/events/ready.js b/events/ready.js index 57e3685..c6fdd9c 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,133 +1,141 @@ module.exports = client => { - const { MessageEmbed } = require("discord.js"); - const axios = require("axios"); - const db = require("quick.db"); - const ping = require("ping-tcp-js"); - const chalk = require("chalk"); - const config = require("../config.json"); - - setInterval(() => { - client.user.setActivity(`Hosting Nodes`, { type: "WATCHING" }); - }, 10000); - console.log("=+=+=+=+=+=+=+=+=+=+=+="); - console.log("Name: PteroStats"); - console.log("Version: Alpha"); - console.log("=+=+=+=+=+=+=+=+=+=+=+="); - - //PteroStats Checker - setInterval(() => { + let nodelist = [ +{ + id: "Server ID", + name: "**Example Server 1**", + nameid: "Node1" +}, +{ + id: "Server ID", + name: "**Example Server 2**", + nameid: "Node2" +}, +] + + const { MessageEmbed } = require("discord.js"); + const axios = require("axios"); + const db = require("quick.db"); + const ping = require("ping-tcp-js"); + const chalk = require("chalk"); + const config = require("../config.json"); let hosturl = config.panelurl; let apikey = config.clientapikey; let ch = client.channels.cache.find(cn => cn.id === config.channel); let statusonline = config.monline; let statusoffline = config.moffline; + let checking = config.mcheck let adminapikey = config.adminapikey; let hostname = config.hostname; - - let id1 = "Server ID"; - let name1 = "**Node Name**"; - - let dbip1 = "Database Ip"; - let dbport1 = "Database Port"; - let dbname1 = "**DB Name**"; - - //Node Status Checker - axios(`${hosturl}/api/client/servers/${id1}/resources`, { - method: "GET", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${apikey}` - } - }) - .then(response => { - db.set("mn1", `${name1}: ${statusonline}`); - }) - .catch(err => { - db.set("mn1", `${name1}: ${statusoffline}`); - }); - - //Database Status Checker - ping - .ping(dbip1, dbport1) - .then(() => { - db.set("db1", `${dbname1}: ${statusonline}`); - }) - .catch(err => { - db.set("db1", `${dbname1}: ${statusoffline}`); - }); - - //Panel Status Checker - axios(`${hosturl}/api/application/servers`, { - method: "GET", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${adminapikey}` - } - }) - .then(response => { - let res = response.data.meta.pagination.total; - db.set("serverCount", res); - }) - .catch(err => { - db.set("serverCount", "N/A"); - }); - axios(`${hosturl}/api/application/users`, { - method: "GET", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Bearer ${adminapikey}` - } - }) - .then(response => { - let res = response.data.meta.pagination.total; - db.set("userCount", res); - }) - .catch(err => { - db.set("userCount", "N/A"); - }); - let userCount = db.get("userCount") - let serverCount = db.get("serverCount") - - if(userCount !== "N/A") db.set("panel", `**Panel**: ${statusonline}`); - if(userCount === "N/A") db.set("panel", `**Panel**: ${statusoffline}`); - - - //Embed Message - let mn1 = db.get("mn1"); - if (mn1 === null) mn1 = `${name1}: checking status`; - - let db1 = db.get("db1"); - if (db1 === null) db1 = `${dbname1}: checking status`; - + let time = config.time - let panel = `${db.get("panel")}\n\nUsers: ${userCount}\nServers: ${serverCount}`; - if (panel === null) panel = `**Panel**: checking status\n\nUsers: ${userCount}\nServers: ${serverCount}`; + setInterval(() => { + client.user.setActivity(hostname + `Panel Stats`, { type: "WATCHING" }); + }, 10000); - let nodemessage = `__**Nodes Stats**__\n${mn1}\n\n__**DataBases Stats**__\n${db1}\n\n__**Panel Stats**__\n${panel}`; - let embed = new MessageEmbed() - .setTitle(`${hostname} Uptime`) - .setColor(config.embedcolor) - .setDescription(nodemessage) - .setTimestamp() - .setFooter("Updated every 1 minutes | By Hirzi#8701") - .setThumbnail(client.user.avatarURL()); + console.log("=+=+=+=+=+=+=+=+=+=+=+="); + console.log("Name: PteroStats"); + console.log("Version: Alpha"); + console.log("=+=+=+=+=+=+=+=+=+=+=+="); + + //PteroStats Checker + setInterval(() => { + if(isNaN(time)) return console.log(chalk.blue("[PteroStats Checker] ") + chalk.red(time + "is not a number!")) + + //Node Status Checker + let list = [] + nodelist.forEach(data => { + if(data.id === "Server ID") return console.log(chalk.blue("[PteroStats Checker] ") + chalk.red("You need to use a valid server")) + let id = data.id.replace(/\,/g) + axios(`${hosturl}/api/client/servers/${data.id}/resources`, { + method: "GET", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Bearer ${apikey}` + } + }).then((response) => { + db.set(data.nameid, `${data.name}: ${statusonline}`); + }).catch(() => { + db.set(data.nameid, `${data.name}: ${statusoffline}`); + console.log(chalk.blue("[PteroStats Checker] ") + chalk.red(data.name + " is down!")) + }); + + let msgStats = db.get(data.nameid) + '\n' + list.push(msgStats) + }) + + //Panel Status Checker + //ServerList + axios(`${hosturl}/api/application/servers`, { + method: "GET", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Bearer ${adminapikey}` + } + }).then(response => { + let res = response.data.meta.pagination.total; + db.set("serverCount", res); + }).catch(err => { + db.set("serverCount", "N/A"); + console.log(chalk.blue("[PteroStats Checker] ") + chalk.red("Panel is down")) + }); - ch.send(embed).then(msg => { - msg.delete({ timeout: 60000 }); - }); - console.log( - chalk.blue("[PteroStats Nodes Checker] ") + chalk.green("Posted Stats") - ); - if (panel !== null) - console.log( - chalk.blue("[PteroStats Nodes Checker] ") + chalk.green("Stats Updated") - ); - console.log( - chalk.blue("[PteroStats Checker] ") + - chalk.green("Updating Stats in 60 Seconds") - ); - }, 60000); -}; + //Userlist + axios(`${hosturl}/api/application/users`, { + method: "GET", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Bearer ${adminapikey}` + } + }).then(response => { + let res = response.data.meta.pagination.total; + db.set("userCount", res); + }).catch(err => { + db.set("userCount", "N/A"); + console.log(chalk.blue("[PteroStats Checker] ") + chalk.red("Panel is down!")) + }); + + let userCount = db.get("userCount") + let serverCount = db.get("serverCount") + + //embed + 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.blue("[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 status\n\nUsers: ${userCount}\nServers: ${serverCount}`; + let nodes + list.forEach((message) => { + if(!nodes) nodes = message + nodes = nodes + message + }) + let nodemessage = `__**Nodes Stats**__\n${nodes}\n\n__**Panel Stats**__\n${panel}`; + + let embed = new MessageEmbed() + .setTitle(`${hostname} Uptime`) + .setColor(config.embedcolor) + .setDescription(nodemessage) + .setTimestamp() + .setFooter("Updated every 1 minutes | By Hirzi#8701") + .setThumbnail(client.user.avatarURL()); + + ch.send(embed).then(msg => {msg.delete({ timeout: time + "000" });}); + + console.log(chalk.blue("[PteroStats Checker] ") + chalk.green("Posted Stats")); + if (panel !== null) + console.log(chalk.blue("[PteroStats Checker] ") + chalk.green("Stats Updated") + ); + console.log(chalk.blue("[PteroStats Checker] ") +chalk.green("Updating Stats in " + time + " Seconds")); + }, time + "000"); + }; +