Skip to content

Commit

Permalink
possibly fix server delete
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev authored Aug 26, 2023
1 parent 8919307 commit 3c1747c
Showing 1 changed file with 68 additions and 73 deletions.
141 changes: 68 additions & 73 deletions bot/discord/commands/server/delete.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const axios = require("axios");

exports.run = async (client, message, args) => {
// uncomment this line if shit goes wrong.
// if (!message.channel.name.includes('ticket')) return message.reply('this is currently disabled')

if (client.cooldown[message.author.id] == null) {
client.cooldown[message.author.id] = {
nCreate: null,
Expand All @@ -21,12 +18,13 @@ exports.run = async (client, message, args) => {
);
return;
}

client.cooldown[message.author.id].delete = Date.now() + 3 * 1000;
//delete server things

if (!args[1]) {
message.reply("Command format: `" + config.DiscordBot.Prefix + "server delete serveridhere`");
message.reply("Command format: `" + config.DiscordBot.Prefix + "server delete <serverid>`");
} else {
if (args[1].match(/[0-9a-z]+/i) == null) return message.reply("lol only use english characters.");
if (args[1].match(/[0-9a-z]+/i) == null) return message.reply("Please only use English characters.");

args[1] = args[1].replace("https://panel.danbot.host/server/", "").match(/[0-9a-z]+/i)[0];

Expand All @@ -49,78 +47,75 @@ exports.run = async (client, message, args) => {
const preoutput = response.data.attributes.relationships.servers.data;
const output = preoutput.find((srv) => (srv.attributes ? srv.attributes.identifier == args[1] : false));

setTimeout(async () => {
setTimeout(async () => {
if (!output) {
msg.edit("Can't find that server :(");
} else {
if (output.attributes.user === userData.get(message.author.id).consoleID) {
msg.edit(
"Are you sure you want to delete `" +
output.attributes.name.split("@").join("@​") + //uses an invisible character (U+200B) after the @
"`?\nPlease type `confirm` to delete this server. You have 1min until this will expire \n\n**You can not restore the server once it has been deleted and/or its files**"
);
const collector = await message.channel.createMessageCollector(
(m) => m.author.id === message.author.id,
{
time: 60000,
max: 2,
}
);
collector.on("collect", (message) => {
if (message.content === "confirm") {
message.delete();
msg.edit("Working...");
axios({
url:
config.Pterodactyl.hosturl +
"/api/application/servers/" +
output.attributes.id +
"/force",
method: "DELETE",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: "Bearer " + config.Pterodactyl.apikey,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
})
.then((response) => {
msg.edit("Server deleted!");
//console.log(output.attributes.node)
if (!output) {
msg.edit("I cannot find that server.");
} else {
if (output.attributes.user === userData.get(message.author.id).consoleID) {
msg.edit(
"Are you sure you want to delete `" +
output.attributes.name.split("@").join("@​") + // Uses an invisible character (U+200B) after the @
"`?\nPlease type `confirm` to delete this server. You have 1 minute until this prompt will expire.\n\n**You can not restore the server once it has been deleted and/or its !files**"
);
const collector = await message.channel.createMessageCollector(
(m) => m.author.id === message.author.id,
{
time: 60000,
max: 2,
}
);
collector.on("collect", (message) => {
if (message.content === "confirm") {
message.delete();
msg.edit("Working...");
axios({
url:
config.Pterodactyl.hosturl +
"/api/application/servers/" +
output.attributes.id +
"/force",
method: "DELETE",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: "Bearer " + config.Pterodactyl.apikey,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
})
.then((response) => {
msg.edit("Server deleted!");
//console.log(output.attributes.node)

if (
output.attributes.node === 31 ||
output.attributes.node === 33 ||
output.attributes.node === 34 ||
output.attributes.node === 35 ||
output.attributes.node === 39
)
userPrem.set(
message.author.id + ".used",
userPrem.fetch(message.author.id).used - 1
);
if (
output.attributes.node === 31 ||
output.attributes.node === 33 ||
output.attributes.node === 34 ||
output.attributes.node === 35 ||
output.attributes.node === 39
)
userPrem.set(
message.author.id + ".used",
userPrem.fetch(message.author.id).used - 1
);

collector.stop();
})
.catch((err) => {
msg.edit("Error with the node. Please try again later");
collector.stop();
});
} else {
message.delete();
msg.edit("Request cancelled!");
collector.stop();
}
});
})
.catch((err) => {
msg.edit("Error with the node. Please try again later");
collector.stop();
});
} else {
message.reply("You do not own that server. You cant delete it.");
message.delete();
msg.edit("Request cancelled!");
collector.stop();
}
}
}, 500);
}, 1000);
});
});
} else {
message.reply("You do not own that server. You can't delete it.");
}
}
})
.catch(() => message.reply("An error occurred while fetching that server."))
});
}
};

0 comments on commit 3c1747c

Please sign in to comment.