2023-03-11 20:36:25 +01:00
|
|
|
import { useQueue } from "discord-player";
|
2023-02-12 01:11:07 +01:00
|
|
|
import {
|
|
|
|
ActionRowBuilder,
|
|
|
|
ButtonBuilder,
|
|
|
|
ButtonStyle,
|
|
|
|
Client,
|
|
|
|
EmbedBuilder,
|
|
|
|
MessageComponentInteraction,
|
|
|
|
} from "discord.js";
|
|
|
|
import { v4 as uuidv4 } from "uuid";
|
|
|
|
import { getLocale } from "../../utils/locales";
|
|
|
|
import { getFilename } from "../../utils/misc";
|
|
|
|
import { embedListQueue } from "../../utils/music";
|
|
|
|
import { collect } from "../loader";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: {
|
|
|
|
name: getFilename(__filename),
|
|
|
|
},
|
|
|
|
interaction: async (interaction: MessageComponentInteraction, client: Client) => {
|
|
|
|
const loc = getLocale(client, interaction.locale);
|
|
|
|
const embed_desc = interaction.message.embeds.at(0)?.author?.name as string;
|
|
|
|
|
|
|
|
// Retrieve Pages
|
|
|
|
const pageMax = Number(/(\d+)(?!.*\d)/gm.exec(embed_desc)?.[0]);
|
|
|
|
let page = Number(/(?!• \s+)\d(?=\/)/gm.exec(embed_desc)?.[0]);
|
|
|
|
if (page + 1 > pageMax) {
|
|
|
|
page = 1;
|
|
|
|
} else {
|
|
|
|
page++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get queue
|
2023-03-11 20:36:25 +01:00
|
|
|
const queue = useQueue(interaction.guildId ?? "");
|
2023-02-12 01:11:07 +01:00
|
|
|
|
|
|
|
const embed = new EmbedBuilder();
|
|
|
|
const rows = [];
|
|
|
|
if (queue) {
|
|
|
|
// Create the embed
|
2023-02-17 23:06:18 +01:00
|
|
|
embedListQueue(client, embed, queue, page, interaction.locale);
|
2023-02-12 01:11:07 +01:00
|
|
|
|
|
|
|
// Create buttons
|
|
|
|
const idPrec = "queueList-prec_" + uuidv4();
|
|
|
|
const idNext = "queueList-next_" + uuidv4();
|
|
|
|
rows.push(
|
|
|
|
new ActionRowBuilder<ButtonBuilder>()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId(idPrec)
|
|
|
|
.setLabel(loc.get("c_queue8"))
|
|
|
|
.setStyle(ButtonStyle.Primary)
|
|
|
|
)
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId(idNext)
|
|
|
|
.setLabel(loc.get("c_queue9"))
|
|
|
|
.setStyle(ButtonStyle.Primary)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Buttons interactions
|
|
|
|
collect(client, interaction, idPrec);
|
|
|
|
collect(client, interaction, idNext);
|
|
|
|
} else {
|
|
|
|
// In case queue doesn't exists
|
|
|
|
embed.setDescription(loc.get("c_queue2"));
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
embeds: [embed],
|
|
|
|
components: rows,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|