2022-08-30 13:04:53 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
2022-07-29 23:31:08 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Servers extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("servers")
|
|
|
|
.setDescription(client.translate("owner/servers:DESCRIPTION")),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
|
|
|
guildOnly: true,
|
|
|
|
ownerOnly: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
2022-08-01 20:06:09 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-07-29 23:31:08 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
2022-08-30 13:04:53 +05:00
|
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
|
|
|
|
let currentPage = 0;
|
|
|
|
const embeds = generateServersEmbeds(interaction, client.guilds.cache);
|
|
|
|
|
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("servers_prev_page")
|
|
|
|
.setStyle(ButtonStyle.Primary)
|
|
|
|
.setEmoji("⬅️"),
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("servers_next_page")
|
|
|
|
.setStyle(ButtonStyle.Primary)
|
|
|
|
.setEmoji("➡️"),
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("servers_jump_page")
|
|
|
|
.setStyle(ButtonStyle.Secondary)
|
|
|
|
.setEmoji("↗️"),
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("servers_stop")
|
|
|
|
.setStyle(ButtonStyle.Danger)
|
|
|
|
.setEmoji("⏹️"),
|
|
|
|
);
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row]
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
const filter = i => i.user.id === interaction.user.id;
|
|
|
|
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (20 * 1000) });
|
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
if (i.isButton()) {
|
|
|
|
if (i.customId === "servers_prev_page") {
|
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
if (currentPage !== 0) {
|
|
|
|
--currentPage;
|
|
|
|
interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (i.customId === "servers_next_page") {
|
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
if (currentPage < embeds.length - 1) {
|
|
|
|
currentPage++;
|
|
|
|
interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (i.customId === "servers_jump_page") {
|
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
const msg = await interaction.followUp({
|
|
|
|
content: interaction.translate("music/queue:PAGE_TO_JUMP", {
|
|
|
|
length: embeds.length
|
|
|
|
}),
|
|
|
|
fetchReply: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const filter = res => {
|
|
|
|
return res.author.id === interaction.user.id && !isNaN(res.content);
|
|
|
|
};
|
|
|
|
|
|
|
|
interaction.channel.awaitMessages({ filter, max: 1, time: (10 * 1000) }).then(collected => {
|
|
|
|
if (embeds[collected.first().content - 1]) {
|
|
|
|
currentPage = collected.first().content - 1;
|
|
|
|
interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row]
|
|
|
|
});
|
|
|
|
|
|
|
|
if (collected.first().deletable) collected.first().delete();
|
|
|
|
if (msg.deletable) msg.delete();
|
|
|
|
} else {
|
|
|
|
if (collected.first().deletable) collected.first().delete();
|
|
|
|
if (msg.deletable) msg.delete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (i.customId === "servers_stop") {
|
|
|
|
i.deferUpdate();
|
|
|
|
collector.stop();
|
|
|
|
}
|
2022-07-29 23:31:08 +05:00
|
|
|
}
|
2022-08-30 13:04:53 +05:00
|
|
|
});
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
collector.on("end", () => {
|
|
|
|
row.components.forEach(component => {
|
|
|
|
component.setDisabled(true);
|
|
|
|
});
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
return interaction.editReply({
|
|
|
|
components: [row]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
* @param {*} servers
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
function generateServersEmbeds(interaction, servers) {
|
|
|
|
const embeds = [];
|
|
|
|
let k = 10;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
for (let i = 0; i < servers.size; i += 10) {
|
|
|
|
const current = servers.map(g => g).slice(i, k).sort((a, b) => b.memberCount - a.memberCount);
|
|
|
|
let j = i;
|
|
|
|
k += 10;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
const info = current.map(server => `${++j}. ${server.name} | ${server.memberCount} ${interaction.client.getNoun(server.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`).join("\n");
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(interaction.client.config.embed.color)
|
|
|
|
.setFooter({
|
|
|
|
text: interaction.client.config.embed.footer
|
|
|
|
})
|
|
|
|
.setTitle(interaction.translate("owner/servers:SERVERS_LIST"))
|
|
|
|
.setDescription(info)
|
|
|
|
.setTimestamp();
|
|
|
|
embeds.push(embed);
|
2022-07-29 23:31:08 +05:00
|
|
|
}
|
2022-08-30 13:04:53 +05:00
|
|
|
|
|
|
|
return embeds;
|
2022-07-29 23:31:08 +05:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
// `${interaction.translate("common:SERVERS")}: ${interaction.client.guilds.cache.size}\n\n` +
|
|
|
|
// interaction.client.guilds.cache
|
|
|
|
// .sort((a, b) => b.memberCount - a.memberCount)
|
|
|
|
// .map(g => g)
|
|
|
|
// .map((g, i) => `${i + 1}. ${g.name} | ${g.memberCount} ${interaction.client.getNoun(g.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`)
|
|
|
|
// .slice(i, k)
|
|
|
|
// .join("\n")
|
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
module.exports = Servers;
|