A Discord Bot connected to your Pterodactyl API.
0
fork

Configure Feed

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

fix: axios request token and base url

authored by

cosmeak and committed by
Cosmeak
74a36589 e55d9305

+39 -43
+2 -4
src/commands/Power.js
··· 6 6 .setName("power") 7 7 .setDescription("Provide a way to up or down a server") 8 8 .addStringOption((option) => 9 - option.setName("server-id") 9 + option.setName("identifier") 10 10 .setDescription("Your server identifier") 11 11 .setRequired(true), 12 12 ) ··· 23 23 ), 24 24 async execute(interaction) { 25 25 const state = interaction.options.get("state").value; 26 - const id = interaction.options.get("server-id").value; 27 - 26 + const id = interaction.options.get("identifier").value; 28 27 try { 29 28 await postServerPower(id, state); 30 29 } 31 30 catch (error) { 32 31 return interaction.reply({ content: error, ephemeral: true }); 33 32 } 34 - 35 33 return interaction.reply(`**${state}** request as been sent to the server with success!`); 36 34 }, 37 35 };
+21 -4
src/commands/SendCommand.js
··· 1 1 import { SlashCommandBuilder } from "discord.js"; 2 - // import axios from "axios"; 3 - // import { config } from "dotenv"; 4 - // config(); 2 + import axios from "axios"; 3 + import { config } from "dotenv"; 4 + config(); 5 5 6 6 export default { 7 7 data: new SlashCommandBuilder() 8 8 .setName("send") 9 9 .setDescription("Send a command to your server") 10 10 .addStringOption((option) => 11 - option.setName("server-id") 11 + option.setName("identifier") 12 12 .setDescription("Your server identifier") 13 + .setRequired(true), 14 + ) 15 + .addStringOption((option) => 16 + option.setName("command") 17 + .setDescription("Command you want to send on the server") 13 18 .setRequired(true), 14 19 ), 15 20 async execute(interaction) { 21 + const id = interaction.options.get("identifier").value; 22 + const command = interaction.options.get("command").value; 23 + try { 24 + await axios.post(`/servers/${id}/command`, { 25 + "command": command, 26 + }); 27 + } 28 + catch (error) { 29 + console.log(error); 30 + } 16 31 32 + // TODO: Reply what's return in the server's console in an embed code message 33 + return interaction.reply("Your command has been send to the server successfully"); 17 34 }, 18 35 };
+1 -8
src/commands/Servers.js
··· 8 8 .setName("servers") 9 9 .setDescription("Show information about your servers"), 10 10 async execute(interaction) { 11 - const response = await axios.get(`${process.env.PTERO_HOST}/api/client/`, { 12 - "headers": { 13 - "Accept": "application/json", 14 - "Authorization": `Bearer ${process.env.PTERO_TOKEN}`, 15 - }, 16 - }); 17 - 18 - console.log(response); 11 + const response = await axios.get("/"); 19 12 20 13 let message = ""; 21 14 response.data.data.forEach((server) => {
src/components/.gitkeep

This is a binary file and will not be displayed.

src/data/.gitkeep

This is a binary file and will not be displayed.

+3 -18
src/functions/fetchClientServerInfo.js
··· 1 1 import axios from "axios"; 2 - import { config } from "dotenv"; 3 - config(); 4 2 5 3 export default async (id) => { 6 - const headers = { 7 - "Accept": "application/json", 8 - "Content-Type": "application/json", 9 - "Authorization": `Bearer ${process.env.PTERO_TOKEN}`, 10 - }; 11 - 12 - let response = await axios.get(`${process.env.PTERO_HOST}/api/client/servers/${id}`, { 13 - "headers": headers, 14 - }); 15 - 4 + let response = await axios.get(`/servers/${id}`); 5 + console.log(response); 16 6 const server = response.data.attributes; 17 - 18 - response = await axios.get(`${process.env.PTERO_HOST}/api/client/servers/${id}/resources`, { 19 - "headers": headers, 20 - }); 21 - 7 + response = await axios.get(`/servers/${id}/resources`); 22 8 server.stats = response.data.attributes; 23 - 24 9 return server; 25 10 };
+2 -9
src/functions/postServerPower.js
··· 4 4 5 5 export default async (id, signal) => { 6 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 - }, 7 + await axios.post(`/servers/${id}/power`, { 8 + "signal": signal, 16 9 }); 17 10 } 18 11 catch (error) {
+10
src/main.js
··· 1 1 import { Bot } from "./services/Bot.js"; 2 + import axios from "axios"; 3 + import { config } from "dotenv"; 4 + config(); 2 5 6 + // Define base config for axios 7 + axios.defaults.baseURL = `${process.env.PTERO_HOST}/api/client` ; 8 + axios.defaults.headers.common["Authorization"] = `Bearer ${process.env.PTERO_TOKEN}`; 9 + axios.defaults.headers.common["Accept"] = "application/json"; 10 + axios.defaults.headers.common["Content-Type"] = "application/json"; 11 + 12 + // Generate and launch Bot 3 13 const bot = new Bot(); 4 14 bot.run();