From 623d0a611cdbcfaa118fe2d0856fafc1e31773fe Mon Sep 17 00:00:00 2001 From: Hirzi <64255651+HirziDevs@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:21:12 +0000 Subject: [PATCH] Update to discordjs 14 --- Indo.md | 8 +++++++- README.md | 8 +++++++- handlers/postStatus.js | 38 ++++++++++++++++++++------------------ index.js | 28 ++++++++++++++++------------ package.json | 18 +++++++++--------- 5 files changed, 59 insertions(+), 41 deletions(-) diff --git a/Indo.md b/Indo.md index 2f22582..4e3306b 100644 --- a/Indo.md +++ b/Indo.md @@ -11,7 +11,13 @@ PteroStats adalah bot yang dirancang untuk memeriksa status panel pterodactyl dan dikirim ke server discord ## Contoh -Example +- Test Panel + + Example + +- [Calvs Cloud](https://discord.gg/ssCQjhrBJN) + + Calvs Cloud ## Instalasi 1. [Mendapatkan apikey dari pterodactyl](#mendapatkan-apikey-dari-pterodactyl) diff --git a/README.md b/README.md index 5be47c7..6b496aa 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,13 @@ PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server ## Example -Example +- Test Panel + + Example + +- [Calvs Cloud](https://discord.gg/ssCQjhrBJN) + + Calvs Cloud ## Installation 1. [Getting apikey from pterodactyl](#getting-apikey-from-pterodactyl) diff --git a/handlers/postStatus.js b/handlers/postStatus.js index 1cbe00a..369f466 100644 --- a/handlers/postStatus.js +++ b/handlers/postStatus.js @@ -1,4 +1,4 @@ -const { MessageEmbed, Formatters, MessageActionRow, MessageButton, MessageAttachment } = require('discord.js') +const { EmbedBuilder, time, ActionRowBuilder, ButtonBuilder, AttachmentBuilder, ButtonStyle } = require('discord.js') const chalk = require('chalk') module.exports = async function postStatus(client, panel, nodes) { @@ -21,7 +21,7 @@ module.exports = async function postStatus(client, panel, nodes) { messages = null } - const embed = new MessageEmbed() + const embed = new EmbedBuilder() let text = '' let desc = '' @@ -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.attachment) files.push(new MessageAttachment(client.config.message.attachment)) + if (client.config.message.attachment) files.push(new AttachmentBuilder(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' @@ -105,8 +105,9 @@ module.exports = async function postStatus(client, panel, nodes) { }) stats.then(async () => { - const format = await Formatters.time(new Date(Date.now() + client.config.refresh * 1000), 'R') + const format = await time(new Date(Date.now() + client.config.refresh * 1000), 'R') embed.setDescription(desc.replaceAll('{{time}}', format) + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text) + const EmbedFields = [] if (client.config.panel_resource.enable) { let stats = '**Status:** ' + String(panel.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) + '\n\n' @@ -114,53 +115,54 @@ module.exports = async function postStatus(client, panel, nodes) { if (client.config.panel_resource.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n' if (client.config.panel_resource.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`') - embed.addField('Panel Stats', stats) + EmbedFields.push({ name: 'Panel Stats', value: stats }) } - if (client.config.embed.field.enable) embed.addField(client.config.embed.field.title, client.config.embed.field.description.replaceAll('{{time}}', format)) + if (client.config.embed.field.enable) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) }) if (client.config.embed.timestamp) embed.setTimestamp() - + if (EmbedFields.length > 0) embed.addFields(EmbedFields) + const row = [] if (client.config.button.enable) { - const button = new MessageActionRow + const button = new ActionRowBuilder if (client.config.button.btn1.label.length !== 0 && client.config.button.btn1.url.length !== 0) { button.addComponents( - new MessageButton() + new ButtonBuilder() .setLabel(client.config.button.btn1.label) - .setStyle('LINK') + .setStyle(ButtonStyle.Link) .setURL(client.config.button.btn1.url) ) } if (client.config.button.btn2.label.length !== 0 && client.config.button.btn2.url.length !== 0) { button.addComponents( - new MessageButton() + new ButtonBuilder() .setLabel(client.config.button.btn2.label) - .setStyle('LINK') + .setStyle(ButtonStyle.Link) .setURL(client.config.button.btn2.url) ) } if (client.config.button.btn3.label.length !== 0 && client.config.button.btn3.url.length !== 0) { button.addComponents( - new MessageButton() + new ButtonBuilder() .setLabel(client.config.button.btn3.label) - .setStyle('LINK') + .setStyle(ButtonStyle.Link) .setURL(client.config.button.btn3.url) ) } if (client.config.button.btn4.label.length !== 0 && client.config.button.btn4.url.length !== 0) { button.addComponents( - new MessageButton() + new ButtonBuilder() .setLabel(client.config.button.btn4.label) - .setStyle('LINK') + .setStyle(ButtonStyle.Link) .setURL(client.config.button.btn4.url) ) } if (client.config.button.btn5.label.length !== 0 && client.config.button.btn5.url.length !== 0) { button.addComponents( - new MessageButton() + new ButtonBuilder() .setLabel(client.config.button.btn5.label) - .setStyle('LINK') + .setStyle(ButtonStyle.Link) .setURL(client.config.button.btn5.url) ) } diff --git a/index.js b/index.js index 5df5536..b1694be 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,8 @@ if (Number(process.version.split('.')[0]) < 16) { } if (fs.existsSync('./node_modules')) { const check = require('./node_modules/discord.js/package.json') - if (Number(check.version.split('.')[0]) !== 13) { - console.log('Invalid Discord.JS Version!, Please use Discord.JS 13.x') + if (Number(check.version.split('.')[0]) !== 14) { + console.log('Invalid Discord.JS Version!, Please use Discord.JS 14.x') process.exit() } } else { @@ -25,26 +25,30 @@ if (fs.existsSync('./node_modules')) { } } +const path = require('node:path'); const chalk = require('chalk'); const yaml = require('js-yaml'); -const { Client, Intents } = require('discord.js'); -const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); +const { Client, GatewayIntentBits } = require('discord.js'); const config = yaml.load(fs.readFileSync('./config.yml', 'utf8')); client.config = config -const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); +const client = new Client({ intents: [GatewayIntentBits.Guilds] }); + +const eventsPath = path.join(__dirname, 'events'); +const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); for (const file of eventFiles) { - const event = require(`./events/${file}`); - if (event.once) { - client.once(event.name, (...args) => event.execute(...args)); - } else { - client.on(event.name, (...args) => event.execute(...args)); - } + const filePath = path.join(eventsPath, file); + const event = require(filePath); + if (event.once) { + client.once(event.name, (...args) => event.execute(...args)); + } else { + client.on(event.name, (...args) => event.execute(...args)); + } } -if (client.config.token.startsWith('Put')) { +if (client.config.token.startsWith('Put') || client.config.token.length < 1) { console.log(chalk.cyan('[PteroStats]') + chalk.red(' Err! Invalid Discord Bot Token')) process.exit() } diff --git a/package.json b/package.json index 5f0b5ac..90846dd 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,24 @@ { "name": "pterostats", - "version": "v2.0.0", + "version": "v3.0.0", "description": "PteroStats is a bot designed to check Pterodactyl Panel and Nodes status and post it to your discord server", "license": "MIT", "repository": "HirziDevs/PteroStats", "homepage": "https://pterostats.hirzidevs.net", "bugs": { - "email": "hirzidevs@gmail.com", - "url": "https://github.com/HirziDevs/PteroStats" + "email": "hirzidevs@gmail.com", + "url": "https://github.com/HirziDevs/PteroStats" }, "scripts": { - "start": "node index.js" + "start": "node index.js" }, "dependencies": { - "axios": "^0.27.2", - "chalk": "4.1.1", - "discord.js": "^13.8.1", - "js-yaml": "^4.1.0" + "axios": "^0.27.2", + "chalk": "4.1.1", + "discord.js": "^14.6.0", + "js-yaml": "^4.1.0" }, "engines": { - "node": "^16.x" + "node": "^16.x" } } \ No newline at end of file