initial commit
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "command",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("command")
|
||||
.setDescription("Send command to the server console")
|
||||
.addStringOption(option => option
|
||||
.setName("command")
|
||||
.setDescription("The action to perform on a user")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setRequired(true)
|
||||
.setName("server_identifier")
|
||||
.setDescription("The server to perform the action on")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
let command = interactionObject.options.getString("command")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}/command`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body": JSON.stringify({
|
||||
"command": `${command}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
// console.log(response);
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
description: `Server has received the command \`${command}\``
|
||||
}]
|
||||
}
|
||||
switch(response.status){
|
||||
case 204:
|
||||
// change nothing
|
||||
break;
|
||||
case 404:
|
||||
message.embeds[0].description = `You do not seem to have permissions to perform this action on the specified server`
|
||||
break
|
||||
case 502:
|
||||
message.embeds[0].description = `The server must be running in order for the command to be passed to it`
|
||||
break
|
||||
default:
|
||||
message.embeds[0].description = `Unknown error, please try again\nIf the issue persists, contact your server administrator\nResponse Code : ${response.status}`
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "power",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("power")
|
||||
.setDescription("Send power options to the server")
|
||||
.addStringOption(option => option
|
||||
.setName("action")
|
||||
.setDescription("The action to perform on the server")
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'start', value: 'start' },
|
||||
{ name: 'restart', value: 'restart'},
|
||||
{ name: 'stop', value: 'stop' },
|
||||
{ name: 'kill', value: 'kill' }
|
||||
)
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setRequired(true)
|
||||
.setName("server_identifier")
|
||||
.setDescription("The server to perform the action on")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let action = interactionObject.options.getString("action")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
switch(action){
|
||||
case "start":
|
||||
case "restart":
|
||||
case "stop":
|
||||
case "kill":
|
||||
break;
|
||||
|
||||
default:
|
||||
interactionObject.editReply("You somehow managed to supply an invalid power option, please dont try to break this system, thanks")
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}/power`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body": JSON.stringify({
|
||||
"signal": `${action}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
// console.log(response);
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
description: `Server has received \`${action}\` power option`
|
||||
}]
|
||||
}
|
||||
switch(response.status){
|
||||
case 204:
|
||||
// message.embeds[0].title
|
||||
break;
|
||||
case 404:
|
||||
message.embeds[0].description = `You do not seem to have permissions to perform this action on the specified server`
|
||||
break
|
||||
default:
|
||||
message.embeds[0].description = `Unknown error, please try again\nIf the issue persists, contact your server administrator\nResponse Code : ${response.status}`
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
const { config } = require('process');
|
||||
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "register",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("register")
|
||||
.setDescription("Register an account on the local pterodactyl web panel")
|
||||
.addStringOption(option => option
|
||||
.setName("username")
|
||||
.setDescription("The username for your account (needed if no client key is supplied)")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("client_key")
|
||||
.setDescription("If you already have an account, create a client key, and add that one here to link your account")
|
||||
),
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
|
||||
var username = interactionObject.options.getString("username")
|
||||
var client_key = interactionObject.options.getString("client_key")
|
||||
var firstname = interactionObject.options.getString("firstname")
|
||||
var lastname = interactionObject.options.getString("lastname")
|
||||
|
||||
var password = hashids.encode(Math.floor(Math.random() * 1000000))
|
||||
|
||||
var ephemeral = true
|
||||
if(client_key != null){
|
||||
ephemeral = true
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
|
||||
if(!config.panel.allowRegistration){
|
||||
return;
|
||||
}
|
||||
|
||||
// This part triggers only when the client key is present, and is the only part that will trigger in that case
|
||||
// It will request the user's data based on the presented key, and then append that data to the account in the database or create one if none should be found
|
||||
if(client_key != null){
|
||||
if(client_key.length != 48){
|
||||
interactionObject.editReply("Incorrect Client Key size")
|
||||
return
|
||||
}
|
||||
fetch(`${config.panel.url}/api/client/account`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${client_key}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
if(response.errors){
|
||||
switch(response.errors[0].status){
|
||||
case "500":
|
||||
interactionObject.editReply("Server Error")
|
||||
break;
|
||||
}
|
||||
return
|
||||
}
|
||||
commands.get("queryCommand").function("INSERT INTO tbl_users (idUser,dtDiscordID,dtKey) VALUES (?,?,?) ON DUPLICATE KEY UPDATE dtKey = ?",[response.attributes.id,interactionObject.user.id,client_key,client_key]).then(result => {
|
||||
if(!result){
|
||||
interactionObject.editReply(`There was an error trying to write the user to the database \nMake sure that the bot was set up correctly`)
|
||||
return
|
||||
}
|
||||
interactionObject.editReply(`User ${response.attributes.username} linked`)
|
||||
})
|
||||
console.log(response);
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
|
||||
if(client_key != null)
|
||||
return
|
||||
|
||||
if(username == null){
|
||||
interactionObject.editReply("You need to supply a valid username or a client key if you already have an account")
|
||||
return}
|
||||
|
||||
if(!config.panel.allowRegistration){
|
||||
interactionObject.editReply("Registering new account has been disabled by the administrator")
|
||||
return
|
||||
}
|
||||
|
||||
fetch(`${config.panel.url}/api/application/users`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${config.panel.applicationKey}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body":JSON.stringify({
|
||||
"email": `${interactionObject.user.id}@goodanimemes.com`,
|
||||
"username": `${username}`,
|
||||
"first_name": `${firstname}`,
|
||||
"last_name": `${lastname}`,
|
||||
"password": `${password}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
console.log(response);
|
||||
if(response.errors){
|
||||
switch(response.errors[0].status){
|
||||
case "500":
|
||||
interactionObject.editReply("Server Error")
|
||||
break;
|
||||
case "422":
|
||||
interactionObject.editReply(response.errors[0].detail)
|
||||
break;
|
||||
}
|
||||
return
|
||||
}
|
||||
commands.get("queryCommand").function("INSERT INTO tbl_users (idUser,dtDiscordID) VALUES (?,?)",[response.attributes.id,interactionObject.user.id]).then(result => {
|
||||
if(!result){
|
||||
interactionObject.editReply(`There was an error trying to write the user to the database \nMake sure that the bot was set up correctly`)
|
||||
return
|
||||
}
|
||||
interactionObject.editReply(`User ${response.attributes.username} created`)
|
||||
|
||||
|
||||
|
||||
|
||||
interactionObject.user.send(
|
||||
`${config.panel.url}\n
|
||||
The password for your account __${username}__ is __${password}__\n\n
|
||||
Now you can log into your account and go to your profile settings\n
|
||||
Go to \`API Credentials\` and create a new key\n
|
||||
Then go back to the server and use the register command again, this time using the \`client_key\` parameter with the key you just created
|
||||
This message will get deleted in 2 minutes`
|
||||
).then(dm => {
|
||||
setTimeout(() => {
|
||||
dm.delete()
|
||||
}, 120000);
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "list_servers",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("list_servers")
|
||||
.setDescription("List my servers")
|
||||
.addStringOption(option => option
|
||||
.setName("server_identifier")
|
||||
.setDescription("To get details on a server, you need to supply the server's identifier (ex : )")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
if(serverid != undefined){
|
||||
if(serverid.length != 8){
|
||||
interactionObject.editReply("The server id you supplied is incorrect")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
|
||||
var response2 = await fetch(`${config.panel.url}/api/client/servers/${serverid}/resources`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
|
||||
var response2 = await response2.json()
|
||||
var resources = response2.attributes.resources
|
||||
|
||||
var serverStatus
|
||||
switch(response2.attributes.current_state){
|
||||
case "running": serverStatus = "Running 🟢"; break;
|
||||
case "starting": serverStatus = "Starting 🟡"; break;
|
||||
case "offline": serverStatus = "Offline 🔴"; break;
|
||||
default: serverStatus = "Unknown ⚫"; break;
|
||||
}
|
||||
|
||||
var attributes = response.attributes
|
||||
var limits = response.attributes.limits
|
||||
var fields = [
|
||||
{
|
||||
"name": `Attributes`,
|
||||
"value": `\`Status : ${serverStatus}\`\n\`Node : ${attributes.node}\`\n\`Is Owner : ${attributes.server_owner}\`\n\`Suspended : ${attributes.is_suspended}\`\n`,
|
||||
},
|
||||
{
|
||||
"name": `Limits`,
|
||||
"value": `\`CPU : ${Math.round(resources.cpu_absolute * 10) / 10}/${limits.cpu}%\`\n\`RAM : ${Math.round(resources.memory_bytes / 100000) / 10}/${limits.memory}MB\`\n\`DISK : ${Math.round(resources.disk_bytes / 100000) / 10}/${limits.disk}MB\`\n`,
|
||||
},
|
||||
]
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
title: `${response.attributes.name}`,
|
||||
fields:fields
|
||||
}]
|
||||
}
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
if(serverid != undefined)
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
// console.log(response);
|
||||
// console.log(response.data[0].attributes);
|
||||
|
||||
|
||||
var message = ""
|
||||
if(response.data.length == 0){
|
||||
interactionObject.editReply(`You currently dont have any servers connected to your account`)
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < response.data.length; i++) {
|
||||
// if(response.data[i].attributes.user == 9)
|
||||
// console.log(response.data[i].attributes.name);
|
||||
message += `\`${response.data[i].attributes.identifier}\` : ${response.data[i].attributes.name}\n`
|
||||
}
|
||||
if(message.length <= 4000){
|
||||
interactionObject.editReply(message)
|
||||
}else{
|
||||
interactionObject.editReply(message.slice(0,3999))
|
||||
}
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user