2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
2023-02-12 14:33:43 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Boosters extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2023-02-12 14:33:43 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("boosters")
|
|
|
|
.setDescription(client.translate("general/boosters:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("general/boosters:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("general/boosters:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2023-02-12 14:33:43 +05:00
|
|
|
.setDMPermission(false),
|
|
|
|
dirname: __dirname,
|
|
|
|
ownerOnly: false,
|
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2023-02-12 14:33:43 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-02-12 14:33:43 +05:00
|
|
|
*/
|
2023-10-31 22:24:40 +05:00
|
|
|
async onLoad(client) {
|
|
|
|
client.on("interactionCreate", async interaction => {
|
|
|
|
if (!interaction.isButton()) return;
|
2023-02-12 14:33:43 +05:00
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
if (interaction.customId.startsWith("boosters_")) {
|
2024-02-09 23:26:57 +05:00
|
|
|
interaction.data = [];
|
2024-05-24 23:11:03 +05:00
|
|
|
interaction.data.guild = await client.getGuildData(interaction.guildId);
|
2024-02-09 23:26:57 +05:00
|
|
|
|
|
|
|
const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince),
|
2024-03-30 12:06:19 +05:00
|
|
|
embeds = generateBoostersEmbeds(interaction, boosters);
|
2023-04-20 11:47:47 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(
|
|
|
|
new ButtonBuilder().setCustomId("boosters_prev_page").setStyle(ButtonStyle.Primary).setEmoji("⬅️"),
|
|
|
|
new ButtonBuilder().setCustomId("boosters_next_page").setStyle(ButtonStyle.Primary).setEmoji("➡️"),
|
|
|
|
new ButtonBuilder().setCustomId("boosters_jump_page").setStyle(ButtonStyle.Secondary).setEmoji("↗️"),
|
2024-01-08 01:54:03 +05:00
|
|
|
new ButtonBuilder().setCustomId("boosters_stop").setStyle(ButtonStyle.Danger).setEmoji("❌"),
|
2023-10-31 22:24:40 +05:00
|
|
|
);
|
2023-02-12 14:33:43 +05:00
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
let currentPage = Number(interaction.message.content.match(/\d+/g)[0]) - 1 ?? 0;
|
2023-02-12 14:33:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
if (interaction.customId === "boosters_prev_page") {
|
|
|
|
await interaction.deferUpdate();
|
2023-02-12 14:33:43 +05:00
|
|
|
|
|
|
|
if (currentPage !== 0) {
|
|
|
|
--currentPage;
|
|
|
|
interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row],
|
|
|
|
});
|
|
|
|
}
|
2023-10-31 22:24:40 +05:00
|
|
|
} else if (interaction.customId === "boosters_next_page") {
|
|
|
|
await interaction.deferUpdate();
|
2023-02-12 14:33:43 +05:00
|
|
|
|
|
|
|
if (currentPage < embeds.length - 1) {
|
|
|
|
currentPage++;
|
|
|
|
interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
|
|
|
embeds: [embeds[currentPage]],
|
|
|
|
components: [row],
|
|
|
|
});
|
|
|
|
}
|
2023-10-31 22:24:40 +05:00
|
|
|
} else if (interaction.customId === "boosters_jump_page") {
|
|
|
|
await interaction.deferUpdate();
|
2023-02-12 14:33:43 +05:00
|
|
|
|
|
|
|
const msg = await interaction.followUp({
|
|
|
|
content: interaction.translate("misc:JUMP_TO_PAGE", {
|
|
|
|
length: embeds.length,
|
|
|
|
}),
|
|
|
|
fetchReply: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const filter = res => {
|
|
|
|
return res.author.id === interaction.user.id && !isNaN(res.content);
|
|
|
|
};
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
interaction.channel.awaitMessages({ filter, max: 1, time: 10 * 1000 }).then(collected => {
|
2023-02-12 14:33:43 +05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2023-10-31 22:24:40 +05:00
|
|
|
} else if (interaction.customId === "boosters_stop") {
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
row.components.forEach(component => {
|
|
|
|
component.setDisabled(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
components: [row],
|
|
|
|
});
|
2023-02-12 14:33:43 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-10-31 22:24:40 +05:00
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-10-31 22:24:40 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
*/
|
2023-12-14 18:58:19 +05:00
|
|
|
async execute(client, interaction) {
|
2023-10-31 22:24:40 +05:00
|
|
|
await interaction.deferReply();
|
|
|
|
|
|
|
|
const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince);
|
|
|
|
if (boosters.size === 0) return interaction.error("general/boosters:NO_BOOSTERS", null, { edit: true });
|
|
|
|
|
2024-07-13 15:43:14 +05:00
|
|
|
const embeds = generateBoostersEmbeds(interaction, boosters);
|
2023-02-12 14:33:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(
|
|
|
|
new ButtonBuilder().setCustomId("boosters_prev_page").setStyle(ButtonStyle.Primary).setEmoji("⬅️"),
|
|
|
|
new ButtonBuilder().setCustomId("boosters_next_page").setStyle(ButtonStyle.Primary).setEmoji("➡️"),
|
|
|
|
new ButtonBuilder().setCustomId("boosters_jump_page").setStyle(ButtonStyle.Secondary).setEmoji("↗️"),
|
2024-01-08 01:54:03 +05:00
|
|
|
new ButtonBuilder().setCustomId("boosters_stop").setStyle(ButtonStyle.Danger).setEmoji("❌"),
|
2023-10-31 22:24:40 +05:00
|
|
|
);
|
2023-02-12 14:33:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
await interaction.editReply({
|
|
|
|
content: `${interaction.translate("common:PAGE")}: **1**/**${embeds.length}**`,
|
|
|
|
embeds: [embeds[0]],
|
|
|
|
components: [row],
|
2023-02-12 14:33:43 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
* @param {Array} boosters
|
|
|
|
* @returns
|
|
|
|
*/
|
2024-03-30 12:06:19 +05:00
|
|
|
function generateBoostersEmbeds(interaction, boosters) {
|
2023-02-12 14:33:43 +05:00
|
|
|
const embeds = [];
|
|
|
|
let k = 10;
|
|
|
|
|
|
|
|
for (let i = 0; i < boosters.size; i += 10) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const current = boosters
|
|
|
|
.sort((a, b) => a.premiumSinceTimestamp - b.premiumSinceTimestamp)
|
|
|
|
.map(g => g)
|
|
|
|
.slice(i, k);
|
2023-02-12 14:33:43 +05:00
|
|
|
let j = i;
|
|
|
|
k += 10;
|
|
|
|
|
2024-07-13 15:43:14 +05:00
|
|
|
const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: <t:${Math.floor(member.premiumSinceTimestamp / 1000)}:f>`).join("\n");
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2024-03-30 12:06:19 +05:00
|
|
|
const embed = interaction.client.embed({
|
2024-02-06 21:45:53 +05:00
|
|
|
title: interaction.translate("general/boosters:BOOSTERS_LIST"),
|
|
|
|
description: info,
|
|
|
|
});
|
2023-02-12 14:33:43 +05:00
|
|
|
|
|
|
|
embeds.push(embed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return embeds;
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Boosters;
|