2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
2022-07-29 23:31:08 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Servers extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-07-29 23:31:08 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("servers")
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDescription(client.translate("owner/servers:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("owner/servers:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("owner/servers:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(true),
|
2022-07-29 23:31:08 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: true,
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-01 20:06:09 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
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);
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
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("➡️"),
|
2024-01-08 01:54:03 +05:00
|
|
|
new ButtonBuilder().setCustomId("servers_stop").setStyle(ButtonStyle.Danger).setEmoji("❌"),
|
2023-07-05 00:58:06 +05:00
|
|
|
);
|
2022-08-30 13:04:53 +05:00
|
|
|
|
2022-11-02 21:39:41 +05:00
|
|
|
await interaction.editReply({
|
2022-08-30 13:04:53 +05:00
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
|
|
|
embeds: [embeds[currentPage]],
|
2022-12-15 21:02:38 +05:00
|
|
|
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;
|
2023-07-05 00:58:06 +05:00
|
|
|
const collector = interaction.guild === null ? (await interaction.user.createDM()).createMessageComponentCollector({ filter, idle: 20 * 1000 }) : interaction.channel.createMessageComponentCollector({ filter, idle: 20 * 1000 });
|
2022-08-30 13:04:53 +05:00
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
if (i.isButton()) {
|
|
|
|
if (i.customId === "servers_prev_page") {
|
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
if (currentPage !== 0) {
|
|
|
|
--currentPage;
|
|
|
|
interaction.editReply({
|
2022-08-30 14:26:56 +05:00
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
2022-08-30 13:04:53 +05:00
|
|
|
embeds: [embeds[currentPage]],
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-30 13:04:53 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (i.customId === "servers_next_page") {
|
|
|
|
i.deferUpdate();
|
|
|
|
|
|
|
|
if (currentPage < embeds.length - 1) {
|
|
|
|
currentPage++;
|
|
|
|
interaction.editReply({
|
2022-08-30 14:26:56 +05:00
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
2022-08-30 13:04:53 +05:00
|
|
|
embeds: [embeds[currentPage]],
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-30 13:04:53 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} 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({
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-30 13:04:53 +05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-11-02 21:39:41 +05:00
|
|
|
* @param {Array} servers
|
2022-08-30 13:04:53 +05:00
|
|
|
* @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) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const current = servers
|
|
|
|
.sort((a, b) => b.memberCount - a.memberCount)
|
|
|
|
.map(g => g)
|
|
|
|
.slice(i, k);
|
2022-08-30 13:04:53 +05:00
|
|
|
let j = i;
|
|
|
|
k += 10;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const info = current
|
|
|
|
.map(
|
|
|
|
server =>
|
|
|
|
`${++j}. ${server.name} | ${server.memberCount} ${interaction.client.functions.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
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = interaction.client.embed({
|
|
|
|
title: interaction.translate("owner/servers:SERVERS_LIST"),
|
2024-04-04 11:50:59 +05:00
|
|
|
description: info,
|
2024-02-06 21:45:53 +05:00
|
|
|
});
|
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Servers;
|