mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-21 12:44:58 +05:00
add pagination to delete buttons in reminds
This commit is contained in:
parent
05f49331e0
commit
8050abbabc
3 changed files with 43 additions and 29 deletions
|
@ -46,22 +46,14 @@ class Reminds extends BaseCommand {
|
|||
|
||||
let currentPage = Number(interaction.message.content.match(/\d+/g)[0]) - 1 ?? 0;
|
||||
|
||||
const row2 = new ActionRowBuilder();
|
||||
|
||||
for (const key in reminds) {
|
||||
row2.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`reminds_delete_${key}`)
|
||||
.setLabel(interaction.translate("general/reminds:DELETE", { pos: parseInt(key) + 1 }))
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
);
|
||||
}
|
||||
|
||||
if (interaction.customId === "reminds_prev_page") {
|
||||
await interaction.deferUpdate();
|
||||
|
||||
if (currentPage !== 0) {
|
||||
--currentPage;
|
||||
|
||||
const row2 = new ActionRowBuilder().addComponents(embeds[currentPage].data._buttons);
|
||||
|
||||
interaction.editReply({
|
||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||
embeds: [embeds[currentPage]],
|
||||
|
@ -73,6 +65,9 @@ class Reminds extends BaseCommand {
|
|||
|
||||
if (currentPage < embeds.length - 1) {
|
||||
currentPage++;
|
||||
|
||||
const row2 = new ActionRowBuilder().addComponents(embeds[currentPage].data._buttons);
|
||||
|
||||
interaction.editReply({
|
||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||
embeds: [embeds[currentPage]],
|
||||
|
@ -96,6 +91,9 @@ class Reminds extends BaseCommand {
|
|||
interaction.channel.awaitMessages({ filter, max: 1, time: 10 * 1000 }).then(collected => {
|
||||
if (embeds[collected.first().content - 1]) {
|
||||
currentPage = collected.first().content - 1;
|
||||
|
||||
const row2 = new ActionRowBuilder().addComponents(embeds[currentPage].data._buttons);
|
||||
|
||||
interaction.editReply({
|
||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||
embeds: [embeds[currentPage]],
|
||||
|
@ -118,20 +116,32 @@ class Reminds extends BaseCommand {
|
|||
});
|
||||
|
||||
return interaction.editReply({
|
||||
components: [row, row2],
|
||||
components: [row],
|
||||
});
|
||||
} else if (interaction.customId.startsWith("reminds_delete_")) {
|
||||
await interaction.deferUpdate();
|
||||
|
||||
const id = parseInt(interaction.customId.split("_")[2]);
|
||||
const remindToDelete = reminds[id];
|
||||
const remindToDelete = reminds[id - 1];
|
||||
|
||||
interaction.data.user.reminds = reminds.filter(r => r.sendAt !== remindToDelete.sendAt);
|
||||
|
||||
await interaction.data.user.save();
|
||||
|
||||
const embeds = generateRemindsEmbeds(interaction, interaction.data.user.reminds);
|
||||
|
||||
embeds.length <= 5 ? currentPage = 0 : currentPage;
|
||||
|
||||
const row2 = new ActionRowBuilder().addComponents(embeds[currentPage].data._buttons);
|
||||
|
||||
await interaction.editReply({
|
||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||
embeds: [embeds[currentPage]],
|
||||
components: [row, row2],
|
||||
});
|
||||
|
||||
return interaction.followUp({
|
||||
content: `${client.customEmojis.success} | ${interaction.translate("general/reminds:DELETED", { pos: id + 1 })}`,
|
||||
content: `${client.customEmojis.success} | ${interaction.translate("general/reminds:DELETED", { pos: id })}`,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
@ -158,21 +168,12 @@ class Reminds extends BaseCommand {
|
|||
new ButtonBuilder().setCustomId("reminds_stop").setStyle(ButtonStyle.Danger).setEmoji("❌"),
|
||||
);
|
||||
|
||||
const row2 = new ActionRowBuilder();
|
||||
|
||||
for (const key in reminds) {
|
||||
row2.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`reminds_delete_${key}`)
|
||||
.setLabel(interaction.translate("general/reminds:DELETE", { pos: parseInt(key) + 1 }))
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
);
|
||||
}
|
||||
const buttonsRow = new ActionRowBuilder().addComponents(embeds[0].data._buttons);
|
||||
|
||||
await interaction.editReply({
|
||||
content: `${interaction.translate("common:PAGE")}: **1**/**${embeds.length}**`,
|
||||
embeds: [embeds[0]],
|
||||
components: [row, row2],
|
||||
components: [row, buttonsRow],
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
@ -203,9 +204,21 @@ function generateRemindsEmbeds(interaction, reminds) {
|
|||
description: info,
|
||||
});
|
||||
|
||||
embed.data._buttons = [];
|
||||
|
||||
for (const key in current) {
|
||||
embed.data._buttons.push(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`reminds_delete_${parseInt(key) + i + 1}`)
|
||||
.setLabel(interaction.translate("general/reminds:DELETE", { pos: parseInt(key) + i + 1 }))
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
);
|
||||
}
|
||||
|
||||
embeds.push(embed);
|
||||
}
|
||||
|
||||
|
||||
return embeds;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ class CommandHandler extends BaseEvent {
|
|||
|
||||
if (interaction.type !== InteractionType.ApplicationCommand && !interaction.isCommand()) return;
|
||||
|
||||
if (command?.dirname.includes("IAT") && interaction.guildId !== "1039187019957555252") return interaction.reply({ content: "IAT Only", ephemeral: true });
|
||||
if (command?.dirname.includes("IAT") && interaction.guildId !== "1039187019957555252") return interaction.reply({ content: "IAT only", ephemeral: true });
|
||||
if (command?.dirname.includes("beatrun") && interaction.guildId !== "1113394230002454560") return interaction.reply({ content: "Beatrun.ru only", ephemeral: true });
|
||||
if (command.ownerOnly && interaction.user.id !== client.config.owner.id) return interaction.error("misc:OWNER_ONLY", null, { ephemeral: true });
|
||||
|
||||
if (!interaction.data.user.achievements.firstCommand.achieved) {
|
||||
|
|
6
index.js
6
index.js
|
@ -19,10 +19,10 @@ const client = new Client({
|
|||
})();
|
||||
|
||||
client
|
||||
.on("disconnect", () => client.logger.warn("Bot is disconnecting..."))
|
||||
.on("disconnect", () => client.logger.warn("Bot disconnected."))
|
||||
.on("reconnecting", () => client.logger.warn("Bot reconnecting..."))
|
||||
.on("warn", warn => console.log(warn))
|
||||
.on("error", e => console.log(e));
|
||||
.on("warn", console.log)
|
||||
.on("error", console.log);
|
||||
|
||||
process
|
||||
.on("unhandledRejection", e => console.log(e))
|
||||
|
|
Loading…
Reference in a new issue