A Discord Bot connected to your Pterodactyl API.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat!: refactor some code and rename all commands for better comprehension

authored by

cosmeak and committed by
Cosmeak
cc189c9d 0324767f

+215 -99
+19
.github/workflows/ci.dev.yml
··· 1 + name: Node.js CI 2 + on: 3 + pull_request: 4 + branches: [ develop ] 5 + push: 6 + branches: [ develop ] 7 + jobs: 8 + lint: 9 + runs-on: ubuntu-latest 10 + steps: 11 + - uses: actions/checkout@v2 12 + - name: Setup Node.js 13 + uses: actions/setup-node@v2 14 + with: 15 + node-version: 18.9.1 16 + - name: Intall Dependencies 17 + run: npm install 18 + - name: Execute lint 19 + run: npm run lint
+17
.github/workflows/ci.prod.yml
··· 1 + name: Node.js CI 2 + on: 3 + pull_request: 4 + branches: [ main ] 5 + jobs: 6 + lint: 7 + runs-on: ubuntu-latest 8 + steps: 9 + - uses: actions/checkout@v2 10 + - name: Setup Node.js 11 + uses: actions/setup-node@v2 12 + with: 13 + node-version: 18.9.1 14 + - name: Intall Dependencies 15 + run: npm install 16 + - name: Execute lint 17 + run: npm run lint
bin/command.refresh.js

This is a binary file and will not be displayed.

+2
logs/.gitignore
··· 1 + * 2 + !.gitignore
+10
src/commands/Backups.js
··· 1 + import { SlashCommandBuilder } from "discord.js"; 2 + 3 + export default { 4 + data: new SlashCommandBuilder() 5 + .setName("backups") 6 + .setDescription("Show all your backups"), 7 + async execute(interaction) { 8 + 9 + }, 10 + };
-33
src/commands/ClientServerDetails.js
··· 1 - import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; 2 - import fecthClientServerInfo from "../functions/fetchClientServerInfo.js"; 3 - import capitalizeFirstLetter from "../functions/capitalizeFirstLetter.js"; 4 - import bytesToSize from "../functions/bytesToSize.js"; 5 - 6 - export default { 7 - data: new SlashCommandBuilder() 8 - .setName("client-server-details") 9 - .setDescription("Give all know details about the given server") 10 - .addStringOption((option) => 11 - option.setName("server-id") 12 - .setDescription("Your server identifier") 13 - .setRequired(true), 14 - ), 15 - async execute(interaction) { 16 - const server = await fecthClientServerInfo(interaction.options.get("server-id").value); 17 - const embed = new EmbedBuilder() 18 - .setTitle(server.name) 19 - .setDescription(server.description ? server.description : "No description...") 20 - .addFields( 21 - { name: "Identifier", value: server.identifier, inline: true }, 22 - { name: "Status", value: capitalizeFirstLetter(server.stats.current_state), inline: true }, 23 - { name: "CPU", value: server.stats.resources.cpu_absolute ? `${server.stats.resources.cpu_absolute}%` : "Offline", inline: true }, 24 - { name: "Memory", value: server.stats.resources.memory_bytes ? bytesToSize(server.stats.resources.memory_bytes) : "Offline", inline: true }, 25 - { name: "Disk", value: server.stats.resources.disk_bytes ? bytesToSize(server.stats.resources.disk_bytes) : "Offline", inline: true }, 26 - { name: "Uptime", value: server.stats.resources.uptime ? server.stats.resources.uptime : "Offline", inline: true }, 27 - ) 28 - .setColor("Blurple") 29 - .setTimestamp(); 30 - 31 - return interaction.reply({ embeds: [embed] }); 32 - }, 33 - };
+2 -2
src/commands/ClientServerList.js src/commands/Servers.js
··· 5 5 6 6 export default { 7 7 data: new SlashCommandBuilder() 8 - .setName("client-server-list") 9 - .setDescription("List all servers"), 8 + .setName("servers") 9 + .setDescription("Show information about your servers"), 10 10 async execute(interaction) { 11 11 const response = await axios.get(`${process.env.PTERO_HOST}/api/client/`, { 12 12 "headers": {
-51
src/commands/ClientServerPower.js
··· 1 - import { SlashCommandBuilder } from "discord.js"; 2 - import fecthClientServerInfo from "../functions/fetchClientServerInfo.js"; 3 - import axios from "axios"; 4 - import { config } from "dotenv"; 5 - config(); 6 - 7 - export default { 8 - data: new SlashCommandBuilder() 9 - .setName("client-server-power") 10 - .setDescription("Provide a way to up or down a server") 11 - .addStringOption((option) => 12 - option.setName("server-id") 13 - .setDescription("Your server identifier") 14 - .setRequired(true), 15 - ) 16 - .addStringOption((option) => 17 - option.setName("state") 18 - .setDescription("Choose a state for your server") 19 - .setChoices( 20 - { name: "start", value: "start" }, 21 - { name: "stop", value: "stop" }, 22 - { name: "restart", value: "restart" }, 23 - { name: "kill", value: "kill" }, 24 - ) 25 - .setRequired(true), 26 - ), 27 - async execute(interaction) { 28 - const state = interaction.options.get("state").value; 29 - const id = interaction.options.get("server-id").value; 30 - const server = await fecthClientServerInfo(id); 31 - 32 - try { 33 - await axios.post(`${process.env.PTERO_HOST}/api/client/servers/${id}/power`, { 34 - "headers": { 35 - "Accept": "application/json", 36 - "Content-Type": "application/json", 37 - "Authorization": `Bearer ${process.env.PTERO_TOKEN}`, 38 - }, 39 - "body": { 40 - "signal": state, 41 - }, 42 - }); 43 - } 44 - catch (error) { 45 - console.error(error.response.data.errors); 46 - return interaction.reply("An error occurred with your request..."); 47 - } 48 - 49 - return interaction.reply(`The **${state}** state has been sent to the server **${server.name}**`); 50 - }, 51 - };
src/commands/ClientServerSendCommand.js bin/command.delete.js
+27
src/commands/CreateBackup.js
··· 1 + import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; 2 + import fecthClientServerInfo from "../functions/fetchClientServerInfo.js"; 3 + // import axios from "axios"; 4 + // import { config } from "dotenv"; 5 + // config(); 6 + 7 + export default { 8 + data: new SlashCommandBuilder() 9 + .setName("create-backup") 10 + .setDescription("Create a new backup for a server") 11 + .addStringOption((option) => 12 + option.setName("server-id") 13 + .setDescription("Your server identifier") 14 + .setRequired(true), 15 + ), 16 + async execute(interaction) { 17 + const serverId = interaction.options.get("server-id").value; 18 + const server = await fecthClientServerInfo(serverId); 19 + const embed = new EmbedBuilder() 20 + .setTitle(`Server: ${server.name}`) 21 + .setDescription("New embed for a serve") 22 + .setColor("Blurple") 23 + .setTimestamp(); 24 + 25 + return interaction.reply({ embeds: [embed] }); 26 + }, 27 + };
+10
src/commands/Help.js
··· 1 + import { SlashCommandBuilder } from "discord.js"; 2 + 3 + export default { 4 + data: new SlashCommandBuilder() 5 + .setName("help") 6 + .setDescription("Show all available commands"), 7 + async execute(interaction) { 8 + 9 + }, 10 + };
+37
src/commands/Power.js
··· 1 + import { SlashCommandBuilder } from "discord.js"; 2 + import postServerPower from "../functions/postServerPower.js"; 3 + 4 + export default { 5 + data: new SlashCommandBuilder() 6 + .setName("power") 7 + .setDescription("Provide a way to up or down a server") 8 + .addStringOption((option) => 9 + option.setName("server-id") 10 + .setDescription("Your server identifier") 11 + .setRequired(true), 12 + ) 13 + .addStringOption((option) => 14 + option.setName("state") 15 + .setDescription("Choose a state for your server") 16 + .setChoices( 17 + { name: "start", value: "start" }, 18 + { name: "stop", value: "stop" }, 19 + { name: "restart", value: "restart" }, 20 + { name: "kill", value: "kill" }, 21 + ) 22 + .setRequired(true), 23 + ), 24 + async execute(interaction) { 25 + const state = interaction.options.get("state").value; 26 + const id = interaction.options.get("server-id").value; 27 + 28 + try { 29 + await postServerPower(id, state); 30 + } 31 + catch (error) { 32 + return interaction.reply({ content: error, ephemeral: true }); 33 + } 34 + 35 + return interaction.reply(`**${state}** request as been sent to the server with success!`); 36 + }, 37 + };
+10
src/commands/Safemode.js
··· 1 + import { SlashCommandBuilder } from "discord.js"; 2 + 3 + export default { 4 + data: new SlashCommandBuilder() 5 + .setName("safemode") 6 + .setDescription("Turn servers into safemode - Kill/Stop and backup servers"), 7 + async execute(interaction) { 8 + 9 + }, 10 + };
+18
src/commands/SendCommand.js
··· 1 + import { SlashCommandBuilder } from "discord.js"; 2 + // import axios from "axios"; 3 + // import { config } from "dotenv"; 4 + // config(); 5 + 6 + export default { 7 + data: new SlashCommandBuilder() 8 + .setName("send") 9 + .setDescription("Send a command to your server") 10 + .addStringOption((option) => 11 + option.setName("server-id") 12 + .setDescription("Your server identifier") 13 + .setRequired(true), 14 + ), 15 + async execute(interaction) { 16 + 17 + }, 18 + };
+33
src/commands/Server.js
··· 1 + import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; 2 + import fecthClientServerInfo from "../functions/fetchClientServerInfo.js"; 3 + import capitalizeFirstLetter from "../functions/capitalizeFirstLetter.js"; 4 + import bytesToSize from "../functions/bytesToSize.js"; 5 + import convertMilliseconds from "../functions/convertMilliseconds.js"; 6 + 7 + export default { 8 + data: new SlashCommandBuilder() 9 + .setName("server") 10 + .setDescription("Show informations about a server and control it") 11 + .addStringOption((option) => 12 + option.setName("server-id") 13 + .setDescription("Your server identifier") 14 + .setRequired(true), 15 + ), 16 + async execute(interaction) { 17 + const server = await fecthClientServerInfo(interaction.options.get("server-id").value); 18 + const embed = new EmbedBuilder() 19 + .setTitle(`${server.name} • ${server.identifier}`) 20 + .setDescription(server.description ? server.description : "No description...") 21 + .addFields( 22 + { name: "Status", value: (server.stats.current_state === "offline" ? "🔴 " : (server.stats.current_state === "running" ? "🟢 " : "🟠 ")) + capitalizeFirstLetter(server.stats.current_state), inline: true }, 23 + { name: "CPU", value: `${server.stats.resources.cpu_absolute}%`, inline: true }, 24 + { name: "Memory", value: bytesToSize(server.stats.resources.memory_bytes), inline: true }, 25 + { name: "Disk", value: bytesToSize(server.stats.resources.disk_bytes), inline: true }, 26 + { name: "Uptime", value: convertMilliseconds(server.stats.resources.uptime), inline: true }, 27 + ) 28 + .setColor(server.stats.current_state === "offline" ? "Red" : (server.stats.current_state === "running" ? "Green" : "Orange")) 29 + .setTimestamp(); 30 + 31 + return interaction.reply({ embeds: [embed] }); 32 + }, 33 + };
+10
src/functions/convertMilliseconds.js
··· 1 + export default (ms) => { 2 + const days = Math.floor(ms / (24 * 60 * 60 * 1000)); 3 + const daysms = ms % (24 * 60 * 60 * 1000); 4 + const hours = Math.floor(daysms / (60 * 60 * 1000)); 5 + const hoursms = ms % (60 * 60 * 1000); 6 + const minutes = Math.floor(hoursms / (60 * 1000)); 7 + const minutesms = ms % (60 * 1000); 8 + const secondes = Math.floor(minutesms / 1000); 9 + return `${days}days ${hours}h ${minutes}min ${secondes}s`; 10 + };
+20 -13
src/functions/postServerPower.js
··· 1 - const axios = require("axios"); 2 - require("dotenv").config(); 1 + import axios from "axios"; 2 + import { config } from "dotenv"; 3 + config(); 3 4 4 - module.exports = async (id, signal) => { 5 - return await axios.post(`${process.env.PTERO_HOST}/api/client/servers/${id}/power`, { 6 - "headers": { 7 - "Accept": "application/json", 8 - "Content-Type": "application/json", 9 - "Authorization": `Bearer ${process.env.PTERO_TOKEN}`, 10 - }, 11 - "body": { 12 - "signal": signal, 13 - }, 14 - }); 5 + export default async (id, signal) => { 6 + try { 7 + await axios.post(`${process.env.PTERO_HOST}/api/client/servers/${id}/power`, { 8 + "headers": { 9 + "Accept": "application/json", 10 + "Content-Type": "application/json", 11 + "Authorization": `Bearer ${process.env.PTERO_TOKEN}`, 12 + }, 13 + "body": { 14 + "signal": signal, 15 + }, 16 + }); 17 + } 18 + catch (error) { 19 + console.log(error.request.data.errors); 20 + throw "An error occured with the request to your API..."; 21 + } 15 22 };