From 277251c15e3aa55dcbacfb6392ffdb91d2f30d92 Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Sun, 19 Jun 2022 14:37:27 +0700 Subject: [PATCH] Some changes --- Indo.md | 15 +++++++++++---- README.md | 15 +++++++++++---- config.yml | 2 +- events/ready.js | 4 ++-- handlers/checkStatus.js | 22 +++++++++++----------- handlers/postStatus.js | 6 +++--- index.js | 7 ++----- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Indo.md b/Indo.md index 4d8911b..dc60b8f 100644 --- a/Indo.md +++ b/Indo.md @@ -11,23 +11,30 @@ PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord ## Instalasi + - [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl) + - [Membuat Discord Bot](#membuat-discord-bot) + - [Menginvite Discord Bot](#menginvite-discord-bot) + - [Mendapatkan Channel ID](#mendapatkan-channel-id) + - [Memulai Bot](#memulai-bot) + - [Mengunakan custom emoji](#mengunakan-custom-emoji) + - [Blacklist Nodes](#blacklist-nodes) ### Mendapatkan apikey dari pterodactyl - Pergi ke `panel admin pterodactyl` dan pergi ke `Application API` - ![Admin Panel](https://usercontent.catto.pictures/hirzi/d5225df9-7395-491b-a214-dcd110b12308.png) + ![Admin Panel](https://usercontent.catto.pictures/hirzi/aabafe57-cbfe-4d7f-9d6d-4a63a7f23d4c.png) - Klik tombol `Create New` - ![Application API Page](https://usercontent.catto.pictures/hirzi/5ac33e25-ac37-416a-99a6-46d860a51645.png) + ![Application API Page](https://usercontent.catto.pictures/hirzi/f916f0c6-0968-4125-8226-ba4daa1de902.png) - Set semua permission ke `read` dan untuk description kamu bisa mengisi apa saja - ![Create Application API](https://usercontent.catto.pictures/hirzi/a0c4a721-e1eb-483f-9a36-0c2aaa213186.png) + ![Create Application API](https://usercontent.catto.pictures/hirzi/3e4575cb-4f52-4bd9-9091-36fda20bedad.png) - Copy apikey-nya. - ![Application API List](https://usercontent.catto.pictures/hirzi/086111e0-0ffa-48ee-8839-801e0c3678cc.png) + ![Application API List](https://usercontent.catto.pictures/hirzi/9142b0b3-0556-4741-840c-6976c3fe3ad4.png) ### Membuat Discord Bot Kalian bisa cek [website ini](https://discordjs.guide/preparations/setting-up-a-bot-application.html) diff --git a/README.md b/README.md index fd6b42c..88d5880 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,30 @@ PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server ## Installation +- [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl) +- [Creating Discord Bot](#creating-discord-bot) +- [Inviting Discord Bot](#inviting-discord-bot) +- [Getting Channel ID](#getting-channel-id) +- [Starting bot](#starting-bot) +- [Using Custom Emoji](#using-custom-emoji) +- [Blacklist Nodes](#blacklist-nodes) ### Getting apikey from pterodactyl - Go to your `pterodactyl admin page` and go to `Application API`. - ![Admin Panel](https://usercontent.catto.pictures/hirzi/d5225df9-7395-491b-a214-dcd110b12308.png) + ![Admin Panel](https://usercontent.catto.pictures/hirzi/aabafe57-cbfe-4d7f-9d6d-4a63a7f23d4c.png) - Click on the `Create New` button - ![Application API Page](https://usercontent.catto.pictures/hirzi/5ac33e25-ac37-416a-99a6-46d860a51645.png) + ![Application API Page](https://usercontent.catto.pictures/hirzi/f916f0c6-0968-4125-8226-ba4daa1de902.png) - Set all options permission to `read` and for description you can put whatever you want - ![Create Application API](https://usercontent.catto.pictures/hirzi/a0c4a721-e1eb-483f-9a36-0c2aaa213186.png) + ![Create Application API](https://usercontent.catto.pictures/hirzi/3e4575cb-4f52-4bd9-9091-36fda20bedad.png) - Copy the apikey. - ![Application API List](https://usercontent.catto.pictures/hirzi/086111e0-0ffa-48ee-8839-801e0c3678cc.png) + ![Application API List](https://usercontent.catto.pictures/hirzi/9142b0b3-0556-4741-840c-6976c3fe3ad4.png) ### Creating Discord Bot Please refer to [this website](https://discordjs.guide/preparations/setting-up-a-bot-application.html) diff --git a/config.yml b/config.yml index e97b2d7..a049ef8 100644 --- a/config.yml +++ b/config.yml @@ -58,8 +58,8 @@ status: # Nodes Resource nodes_resource: - enable: false blacklist: [] # You can add node id to remove the node from status embed (Example: "blacklist: [1]") + enable: false servers: true location: true allocations: true diff --git a/events/ready.js b/events/ready.js index 9f07849..234338e 100644 --- a/events/ready.js +++ b/events/ready.js @@ -4,7 +4,7 @@ const checkStatus = require('../handlers/checkStatus') module.exports = { name: 'ready', once: true, - async execute(client) { + execute(client) { console.log(chalk.cyan('[PteroStats]') + chalk.green(' Bot is up!')) console.log(chalk.cyan('[PteroStats]') + chalk.green(' If you need support you can join our discord server https://discord.gg/zv6maQRah3')) @@ -22,7 +22,7 @@ module.exports = { checkStatus(client) - setInterval(async () => { + setInterval(() => { checkStatus(client) }, client.config.refresh * 1000) } diff --git a/handlers/checkStatus.js b/handlers/checkStatus.js index bc30909..2f2f53e 100644 --- a/handlers/checkStatus.js +++ b/handlers/checkStatus.js @@ -3,7 +3,7 @@ const chalk = require('chalk') const postStatus = require('./postStatus') -module.exports = async function checkStatus(client) { +module.exports = function checkStatus(client) { if (client.config.channel.startsWith('Put')) { console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Channel ID')) @@ -40,7 +40,7 @@ module.exports = async function checkStatus(client) { 'Content-Type': 'application/json', Authorization: 'Bearer ' + client.config.panel.key } - }).then(usr => { + }).then((usr) => { axios(client.config.panel.url + '/api/application/servers', { method: 'GET', headers: { @@ -48,14 +48,14 @@ module.exports = async function checkStatus(client) { 'Content-Type': 'application/json', Authorization: 'Bearer ' + client.config.panel.key } - }).then(async (ser) => { + }).then((ser) => { panel.total_users = usr.data.meta.pagination.total panel.total_servers = ser.data.meta.pagination.total panel.status = true resolve() }) - }).catch(async (err) => { + }).catch((err) => { if (err.response) { if (err.response.status === 403) { console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid apikey')) @@ -79,8 +79,8 @@ module.exports = async function checkStatus(client) { 'Content-Type': 'application/json', Authorization: 'Bearer ' + client.config.panel.key } - }).then(async (res) => { - res.data.data.forEach(async (node, i) => { + }).then((res) => { + res.data.data.forEach((node) => { axios(client.config.panel.url + '/api/application/nodes/' + node.attributes.id + '/configuration', { method: 'GET', headers: { @@ -88,7 +88,7 @@ module.exports = async function checkStatus(client) { 'Content-Type': 'application/json', Authorization: 'Bearer ' + client.config.panel.key } - }).then(async (data) => { + }).then((data) => { const body = { id: node.attributes.id, name: node.attributes.name, @@ -111,9 +111,9 @@ module.exports = async function checkStatus(client) { 'Content-Type': 'application/json', Authorization: 'Bearer ' + data.data.token } - }).then(async (status) => { + }).then((status) => { statsResolve() - }).catch(async (err) => { + }).catch((err) => { body.status = false statsResolve() }) @@ -122,11 +122,11 @@ module.exports = async function checkStatus(client) { nodes.push(body) resolve() }) - }).catch(async (err) => { + }).catch((err) => { resolve() }) }) - }).catch(async (err) => { + }).catch((err) => { resolve() }) }) diff --git a/handlers/postStatus.js b/handlers/postStatus.js index 9853729..c738889 100644 --- a/handlers/postStatus.js +++ b/handlers/postStatus.js @@ -41,7 +41,6 @@ module.exports = async function postStatus(client, panel, nodes) { if (nodes.length !== 0) { nodes.forEach((data, i) => { if (!client.config.nodes_resource.blacklist.includes(data.id)) { - blacklist = blacklist + 1 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) { @@ -73,7 +72,8 @@ module.exports = async function postStatus(client, panel, nodes) { text = text + '\n**' + title.replace(':', ':**') } } else { - if (nodes.length - client.config.nodes_resource.blacklist < 1) text = '\nThere is no nodes to display' + blacklist = blacklist + 1 + if (nodes.length - client.config.nodes_resource.blacklist.length < 1) text = '\nThere is no nodes to display' } if (i + 1 === nodes.length) resolve() @@ -93,7 +93,7 @@ module.exports = async function postStatus(client, panel, nodes) { } }) - stats.then(async () => { + stats.then(() => { embed.setDescription(desc + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text) diff --git a/index.js b/index.js index 499866b..5df5536 100644 --- a/index.js +++ b/index.js @@ -30,23 +30,20 @@ const yaml = require('js-yaml'); const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); -// Load Config const config = yaml.load(fs.readFileSync('./config.yml', 'utf8')); client.config = config -// Read Events Files const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); for (const file of eventFiles) { const event = require(`./events/${file}`); if (event.once) { - client.once(event.name, (client) => event.execute(client)); + client.once(event.name, (...args) => event.execute(...args)); } else { - client.on(event.name, (client) => event.execute(client)); + client.on(event.name, (...args) => event.execute(...args)); } } -// Login to bot if (client.config.token.startsWith('Put')) { console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Discord Bot Token')) process.exit()