Skip to content

Commit

Permalink
Update list.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev authored Aug 26, 2023
1 parent b329384 commit ba11d33
Showing 1 changed file with 52 additions and 56 deletions.
108 changes: 52 additions & 56 deletions bot/discord/commands/server/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,65 @@ const axios = require("axios");
const Discord = require("discord.js");

exports.run = async (client, message, args) => {
try {
let userID = message.author.id;
let userID = message.author.id;

// Allow developers to lookup a user's server list
if (message.member.roles.cache.find((r) => r.id === "898041747597295667") || message.author.id === "853158265466257448") userID = args[1] || message.author.id;
// Allow developers to lookup a user's server list
if (message.member.roles.cache.find((r) => r.id === "898041747597295667") || message.author.id === "853158265466257448") userID = args[1] || message.author.id;

const userAccount = userData.get(userID);
const userAccount = userData.get(userID);

if (userAccount == null || userAccount.consoleID == null) {
message.reply(
"You do not have an panel account linked to your Discord account.\n" +
"If you have not made an account yet please check out `" +
config.DiscordBot.Prefix +
"user new` to create an account \nIf you already have an account link it using `" +
config.DiscordBot.Prefix +
"user link`"
);
return;
}

// List servers
var arr = [];
if (userAccount == null || userAccount.consoleID == null) {
message.reply(
"You do not have an panel account linked to your Discord account.\n" +
"If you have not made an account yet please check out `" +
config.DiscordBot.Prefix +
"user new` to create an account.\nIf you already have an account link it using `" +
config.DiscordBot.Prefix +
"user link`"
);
return;
}

axios({
url: `https://panel.danbot.host/api/application/users/${userAccount.consoleID}?include=servers`,
method: "GET",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: `Bearer ${config.Pterodactyl.apikey}`,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
}).then((response) => {
const preoutput = response.data.attributes.relationships.servers.data;
arr.push(...preoutput);
// List servers
var arr = [];

const donoNodes = [34, 31, 33, 35, 39];
axios({
url: `https://panel.danbot.host/api/application/users/${userAccount.consoleID}?include=servers`,
method: "GET",
followRedirect: true,
maxRedirects: 5,
headers: {
Authorization: `Bearer ${config.Pterodactyl.apikey}`,
"Content-Type": "application/json",
Accept: "Application/vnd.pterodactyl.v1+json",
},
}).then((response) => {
const preoutput = response.data.attributes.relationships.servers.data;
arr.push(...preoutput);

const clean = arr.map((server) => {
const emoji = donoNodes.includes(server.attributes.node) ? ":money_with_wings:" : ":free:";
const donoNodes = [34, 31, 33, 35, 39];

return `${emoji} **${server.attributes.name}** (\`${server.attributes.identifier}\`)`;
});
const clean = arr.map((server) => {
const emoji = donoNodes.includes(server.attributes.node) ? ":money_with_wings:" : ":free:";

if (clean.length == 0) {
message.reply("You do not have any servers.");
} else if (clean.length > 70) {
message.reply("You have too many servers to display!");
} else if (clean.length > 20) {
const serverListEmbed = new Discord.MessageEmbed()
.setTitle("Server List (shortened)")
.setDescription(arr.map((i) => `\`${i.attributes.identifier}\``).join("\n"));
message.reply(serverListEmbed);
} else {
const serverListEmbed = new Discord.MessageEmbed()
.setTitle("Server List")
.setDescription(clean);
message.reply(serverListEmbed);
}
return `${emoji} **${server.attributes.name}** (\`${server.attributes.identifier}\`)`;
});
} catch (error) {
console.log(error);
message.channel.send(`\`\`\`${error.message}\`\`\``);
}

if (clean.length == 0) {
message.reply("You do not have any servers.");
} else if (clean.length > 70) {
message.reply("You have too many servers to display!");
} else if (clean.length > 20) {
const serverListEmbed = new Discord.MessageEmbed()
.setTitle("Server List (shortened)")
.setDescription(arr.map((i) => `\`${i.attributes.identifier}\``).join("\n"));
message.reply(serverListEmbed);
} else {
const serverListEmbed = new Discord.MessageEmbed()
.setTitle("Server List")
.setDescription(clean);
message.reply(serverListEmbed);
}
})
.catch(() => message.reply("An error occurred while loading servers."));
};

0 comments on commit ba11d33

Please sign in to comment.