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")
|
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
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: true,
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
|
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("➡️"),
|
|
|
|
new ButtonBuilder().setCustomId("servers_stop").setStyle(ButtonStyle.Danger).setEmoji("⏹️"),
|
|
|
|
);
|
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
|
|
|
|
2022-08-30 13:04:53 +05:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setTitle(interaction.translate("owner/servers:SERVERS_LIST"))
|
|
|
|
.setDescription(info)
|
2023-08-24 19:00:24 +05:00
|
|
|
.setColor(interaction.client.config.embed.color)
|
|
|
|
.setFooter(interaction.client.config.embed.footer)
|
2022-08-30 13:04:53 +05:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Servers;
|