Anri Kennel
2770bd15bb
Closes #9 via [discord-player](https://github.com/Androz2091/discord-player/) Co-authored-by: Mylloon <kennel.anri@tutanota.com> Reviewed-on: #62
72 lines
2 KiB
TypeScript
72 lines
2 KiB
TypeScript
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
|
|
const queue = client.player.queues.get(interaction.guildId ?? "");
|
|
|
|
const embed = new EmbedBuilder();
|
|
const rows = [];
|
|
if (queue) {
|
|
// Create the embed
|
|
embedListQueue(client, embed, queue.tracks, page, interaction.locale);
|
|
|
|
// 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,
|
|
};
|
|
},
|
|
};
|