mirror of
https://github.com/HirziDevs/PteroStats
synced 2026-01-07 14:05:46 +00:00
Some changes
This commit is contained in:
15
Indo.md
15
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`
|
||||
|
||||

|
||||

|
||||
|
||||
- Klik tombol `Create New`
|
||||
|
||||

|
||||

|
||||
|
||||
- Set semua permission ke `read` dan untuk description kamu bisa mengisi apa saja
|
||||
|
||||

|
||||

|
||||
|
||||
- Copy apikey-nya.
|
||||
|
||||

|
||||

|
||||
|
||||
### Membuat Discord Bot
|
||||
Kalian bisa cek [website ini](https://discordjs.guide/preparations/setting-up-a-bot-application.html)
|
||||
|
||||
15
README.md
15
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`.
|
||||
|
||||

|
||||

|
||||
|
||||
- Click on the `Create New` button
|
||||
|
||||

|
||||

|
||||
|
||||
- Set all options permission to `read` and for description you can put whatever you want
|
||||
|
||||

|
||||

|
||||
|
||||
- Copy the apikey.
|
||||
|
||||

|
||||

|
||||
|
||||
### Creating Discord Bot
|
||||
Please refer to [this website](https://discordjs.guide/preparations/setting-up-a-bot-application.html)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
7
index.js
7
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()
|
||||
|
||||
Reference in New Issue
Block a user