mirror of
https://github.com/HirziDevs/PteroStats
synced 2026-01-09 23:47:52 +00:00
v1.1.7
This commit is contained in:
232
events/ready.js
232
events/ready.js
@@ -1,43 +1,42 @@
|
||||
module.exports = client => {
|
||||
let nodelist = client.nodelist
|
||||
//nodelist was moved to index.js file
|
||||
|
||||
const { MessageEmbed } = require("discord.js");
|
||||
const axios = require("axios");
|
||||
const db = require("quick.db");
|
||||
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 footer = config.footer
|
||||
let checking = config.mcheck
|
||||
let adminapikey = config.adminapikey;
|
||||
let hostname = config.hostname;
|
||||
let time = config.time
|
||||
|
||||
setInterval(() => {
|
||||
client.user.setActivity(hostname + " Panel Stats", { type: "WATCHING" });
|
||||
}, 10000);
|
||||
let nodelist = client.nodelist
|
||||
//nodelist was moved to index.js file
|
||||
|
||||
console.log(chalk.red("=+=+=+=+=+=+=+=+=+=+=+="));
|
||||
console.log(chalk.greem("Name: PteroStats"));
|
||||
console.log(chalk.green("Version: Alpha"));
|
||||
console.log(chalk.green("Stats will update every " + time + " Seconds"));
|
||||
console.log(chalk.green("Bot is online"));
|
||||
console.log(chalk.red("=+=+=+=+=+=+=+=+=+=+=+="));
|
||||
console.log(chalk.blue("If you need help contact me at discord ") + chalk.green("https://discord.gg/9Z7zpdwATZ"))
|
||||
|
||||
//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"))
|
||||
const { MessageEmbed } = require("discord.js");
|
||||
const axios = require("axios");
|
||||
const db = require("quick.db");
|
||||
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 footer = config.footer;
|
||||
let enablets = config.enabletimestamp;
|
||||
let checking = config.mcheck;
|
||||
let adminapikey = config.adminapikey;
|
||||
let hostname = config.hostname;
|
||||
let time = config.time;
|
||||
|
||||
client.user.setActivity(hostname + " Panel Stats", { type: "WATCHING" });
|
||||
|
||||
console.log(chalk.red("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="));
|
||||
console.log(chalk.green("Name: ") + chalk.blue("PteroStats"));
|
||||
console.log(chalk.green("Version: ") + chalk.blue("Stable v1.1.7"));
|
||||
console.log(chalk.green("Refresh Time: ") + chalk.blue(time + " Seconds"));
|
||||
console.log(chalk.green("Bot Status: ") + chalk.blue("Online"));
|
||||
console.log(chalk.green("Support Server: ") + chalk.blue("https://discord.gg/9Z7zpdwATZ"));
|
||||
console.log(chalk.red("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="));
|
||||
|
||||
//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",
|
||||
@@ -47,88 +46,93 @@ module.exports = client => {
|
||||
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!"))
|
||||
});
|
||||
|
||||
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'
|
||||
if(msgStats === "null\n") msgStats = data.name + ":" + mcheck
|
||||
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"))
|
||||
});
|
||||
|
||||
//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!"))
|
||||
//Panel Status Checker
|
||||
//ServerList
|
||||
axios(`${hosturl}/api/application/servers`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${adminapikey}`
|
||||
}
|
||||
if(userCount === checking) db.set("panel", `**Panel**: ${checking}`);
|
||||
let panel = `${db.get("panel")}\n\nUsers: ${userCount}\nServers: ${serverCount}`;
|
||||
}).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"))
|
||||
});
|
||||
|
||||
//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!"))
|
||||
});
|
||||
|
||||
if (panel === null) panel = `**Panel**: checking status\n\nUsers: ${userCount}\nServers: ${serverCount}`;
|
||||
let nodes
|
||||
list.forEach((message) => {
|
||||
if(!nodes) return nodes = message
|
||||
nodes = nodes + message
|
||||
})
|
||||
let nodemessage = `__**Nodes Stats**__\n${nodes}\n\n__**Panel Stats**__\n${panel}`;
|
||||
let userCount = db.get("userCount")
|
||||
let serverCount = db.get("serverCount")
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(hostname + " Stats")
|
||||
.setColor(config.embedcolor)
|
||||
.setDescription(nodemessage)
|
||||
.setTimestamp()
|
||||
.setFooter("Updated every " + time + " seconds | " + footer)
|
||||
.setThumbnail(client.user.avatarURL());
|
||||
|
||||
ch.send(embed).then(msg => {msg.delete({ timeout: time + "000" });});
|
||||
//embed
|
||||
if (userCount === null) userCount = checking;
|
||||
if (serverCount === null) serverCount = checking;
|
||||
|
||||
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");
|
||||
};
|
||||
|
||||
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) return nodes = message
|
||||
nodes = nodes + message
|
||||
})
|
||||
let nodeCount = '[Nodes ' + list.length + ']'
|
||||
|
||||
let nodemessage = '__**Nodes Stats ' + nodeCount + '**__\n' + nodes + '\n\n__**Panel Stats**__\n' + panel;
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(hostname + " Stats")
|
||||
.setColor(config.embedcolor)
|
||||
.setDescription(nodemessage)
|
||||
.setTimestamp()
|
||||
.setFooter("Updated every " + time + " seconds | " + footer)
|
||||
.setThumbnail(client.user.avatarURL());
|
||||
if(enablets === "yes") {
|
||||
embed.setTimestamp()
|
||||
}
|
||||
|
||||
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");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user