2023-11-04 16:56:10 +05:00
|
|
|
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require("discord.js"),
|
2023-03-24 00:09:26 +05:00
|
|
|
|
{ QueueRepeatMode } = require("discord-player");
|
2022-08-02 17:18:47 +05:00
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
|
|
class Nowplaying extends BaseCommand {
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
|
* @param {import("../base/Client")} client
|
2022-08-02 17:18:47 +05:00
|
|
|
|
*/
|
|
|
|
|
constructor(client) {
|
|
|
|
|
super({
|
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
|
.setName("nowplaying")
|
2022-10-13 00:05:36 +05:00
|
|
|
|
.setDescription(client.translate("music/nowplaying:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
|
uk: client.translate("music/nowplaying:DESCRIPTION", null, "uk-UA"),
|
|
|
|
|
ru: client.translate("music/nowplaying:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
|
.setDMPermission(false),
|
2022-08-02 17:18:47 +05:00
|
|
|
|
aliases: [],
|
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
|
ownerOnly: false,
|
2022-08-02 17:18:47 +05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-02 17:18:47 +05:00
|
|
|
|
*/
|
2023-11-04 16:56:10 +05:00
|
|
|
|
async onLoad(client) {
|
|
|
|
|
client.on("interactionCreate", async interaction => {
|
|
|
|
|
if (!interaction.isButton()) return;
|
|
|
|
|
|
|
|
|
|
if (interaction.customId.startsWith("nowp_")) {
|
|
|
|
|
const voice = interaction.member.voice.channel;
|
|
|
|
|
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL");
|
|
|
|
|
|
|
|
|
|
const queue = client.player.nodes.get(interaction.guildId);
|
|
|
|
|
if (!queue) return interaction.error("music/play:NOT_PLAYING");
|
|
|
|
|
|
|
|
|
|
const row1 = new ActionRowBuilder().addComponents(
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_prev_track").setStyle(ButtonStyle.Primary).setEmoji("⬅️"),
|
2023-11-04 23:52:05 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_stop").setStyle(ButtonStyle.Danger).setEmoji("⏹️"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_add_track").setStyle(ButtonStyle.Success).setEmoji("▶️"),
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_next_track").setStyle(ButtonStyle.Primary).setEmoji("➡️"),
|
2023-11-04 23:52:05 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_loop").setStyle(ButtonStyle.Secondary).setEmoji("🔁"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const row2 = new ActionRowBuilder().addComponents(
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_queue").setStyle(ButtonStyle.Secondary).setEmoji("ℹ️"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (interaction.customId === "nowp_prev_track") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
|
|
if (queue.history.isEmpty()) return interaction.followUp({ content: interaction.translate("music/back:NO_PREV_SONG", null, "error"), ephemeral: true });
|
|
|
|
|
|
|
|
|
|
queue.history.back();
|
|
|
|
|
|
2023-11-04 23:06:51 +05:00
|
|
|
|
await interaction.followUp({ content: interaction.translate("music/back:SUCCESS"), ephemeral: true });
|
2023-11-04 16:56:10 +05:00
|
|
|
|
|
|
|
|
|
const embed = await updateEmbed(interaction, queue);
|
|
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
});
|
|
|
|
|
} else if (interaction.customId === "nowp_loop") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
|
|
const selectMenu = new StringSelectMenuBuilder()
|
|
|
|
|
.setCustomId("nowp_select")
|
|
|
|
|
.setPlaceholder(interaction.translate("common:NOTHING_SELECTED"))
|
|
|
|
|
.addOptions(
|
|
|
|
|
new StringSelectMenuOptionBuilder()
|
|
|
|
|
.setLabel(interaction.translate("music/loop:AUTOPLAY"))
|
|
|
|
|
.setValue("3"),
|
|
|
|
|
new StringSelectMenuOptionBuilder()
|
|
|
|
|
.setLabel(interaction.translate("music/loop:QUEUE"))
|
|
|
|
|
.setValue("2"),
|
|
|
|
|
new StringSelectMenuOptionBuilder()
|
|
|
|
|
.setLabel(interaction.translate("music/loop:TRACK"))
|
|
|
|
|
.setValue("1"),
|
|
|
|
|
new StringSelectMenuOptionBuilder()
|
|
|
|
|
.setLabel(interaction.translate("music/loop:DISABLE"))
|
|
|
|
|
.setValue("0"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const selectRow = new ActionRowBuilder().addComponents(selectMenu),
|
|
|
|
|
msg = await interaction.followUp({
|
|
|
|
|
components: [selectRow],
|
|
|
|
|
ephemeral: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filter = i => i.user.id === interaction.user.id,
|
|
|
|
|
collected = await msg.awaitMessageComponent({ filter, time: 10 * 1000 }),
|
2023-11-05 00:06:19 +05:00
|
|
|
|
mode = collected.values[0] === "3" ? QueueRepeatMode.AUTOPLAY : collected.values[0] === "2" ? QueueRepeatMode.QUEUE : collected.values[0] === "1" ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF,
|
2023-11-04 16:56:10 +05:00
|
|
|
|
translated = {
|
2023-11-05 00:06:19 +05:00
|
|
|
|
"3": interaction.translate("music/loop:AUTOPLAY_ENABLED"),
|
|
|
|
|
"2": interaction.translate("music/loop:QUEUE_ENABLED"),
|
|
|
|
|
"1": interaction.translate("music/loop:TRACK_ENABLED"),
|
2023-11-04 23:06:51 +05:00
|
|
|
|
"0": interaction.translate("music/loop:LOOP_DISABLED"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await collected.deferUpdate();
|
|
|
|
|
|
|
|
|
|
queue.setRepeatMode(mode);
|
|
|
|
|
|
2023-11-05 00:06:19 +05:00
|
|
|
|
await interaction.followUp({ content: translated[collected.values[0]] });
|
2023-11-04 16:56:10 +05:00
|
|
|
|
|
|
|
|
|
const embed = await updateEmbed(interaction, queue);
|
|
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
});
|
|
|
|
|
} else if (interaction.customId === "nowp_add_track") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
|
|
await interaction.followUp({
|
|
|
|
|
content: interaction.translate("music/nowplaying:LINK"),
|
|
|
|
|
ephemeral: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filter = m => m.author.id === interaction.user.id && m.content.startsWith("http"),
|
|
|
|
|
collected = (await interaction.channel.awaitMessages({ filter, time: 10 * 1000, max: 1 })).first(),
|
|
|
|
|
query = collected.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g)[0],
|
|
|
|
|
searchResult = await client.player.search(query, {
|
|
|
|
|
requestedBy: interaction.user,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!searchResult.hasTracks()) return interaction.error("music/play:NO_RESULT", { query: query }, { edit: true });
|
|
|
|
|
else queue.addTrack(searchResult);
|
|
|
|
|
|
|
|
|
|
if (collected.deletable) collected.delete();
|
|
|
|
|
|
|
|
|
|
await interaction.followUp({
|
|
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
|
songName: searchResult.hasPlaylist() ? searchResult.playlist.title : searchResult.tracks[0].title,
|
2023-11-04 23:06:51 +05:00
|
|
|
|
}),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const embed = await updateEmbed(interaction, queue);
|
|
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
});
|
|
|
|
|
} else if (interaction.customId === "nowp_next_track") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
|
|
queue.node.skip();
|
|
|
|
|
|
2023-11-04 23:06:51 +05:00
|
|
|
|
await interaction.followUp({ content: interaction.translate("music/skip:SUCCESS"), ephemeral: true });
|
2023-11-04 16:56:10 +05:00
|
|
|
|
|
|
|
|
|
const embed = await updateEmbed(interaction, queue);
|
|
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
});
|
|
|
|
|
} else if (interaction.customId === "nowp_queue") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
|
|
|
|
client.commands.get("queue").execute(client, interaction);
|
|
|
|
|
} else if (interaction.customId === "nowp_stop") {
|
|
|
|
|
await interaction.deferUpdate();
|
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
|
queue.delete();
|
|
|
|
|
await interaction.followUp({ content: interaction.translate("music/stop:SUCCESS") });
|
|
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
|
row1.components.forEach(component => {
|
|
|
|
|
component.setDisabled(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
row2.components.forEach(component => {
|
|
|
|
|
component.setDisabled(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
|
components: [row1, row2],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-02 17:18:47 +05:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-02 17:18:47 +05:00
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
|
* @param {Object} data
|
2022-08-02 17:18:47 +05:00
|
|
|
|
*/
|
2023-11-04 16:56:10 +05:00
|
|
|
|
async execute(client, interaction) {
|
2022-08-03 20:57:54 +05:00
|
|
|
|
await interaction.deferReply();
|
2022-09-13 22:19:51 +05:00
|
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
|
const queue = client.player.nodes.get(interaction.guildId);
|
2022-09-13 22:19:51 +05:00
|
|
|
|
if (!queue) return interaction.error("music/play:NOT_PLAYING", null, { edit: true });
|
2023-11-04 16:56:10 +05:00
|
|
|
|
|
|
|
|
|
const row1 = new ActionRowBuilder().addComponents(
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_prev_track").setStyle(ButtonStyle.Primary).setEmoji("⬅️"),
|
2023-11-04 23:52:05 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_stop").setStyle(ButtonStyle.Danger).setEmoji("⏹️"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_add_track").setStyle(ButtonStyle.Success).setEmoji("▶️"),
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_next_track").setStyle(ButtonStyle.Primary).setEmoji("➡️"),
|
2023-11-04 23:52:05 +05:00
|
|
|
|
new ButtonBuilder().setCustomId("nowp_loop").setStyle(ButtonStyle.Secondary).setEmoji("🔁"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const row2 = new ActionRowBuilder().addComponents(
|
|
|
|
|
new ButtonBuilder().setCustomId("nowp_queue").setStyle(ButtonStyle.Secondary).setEmoji("ℹ️"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const embed = await updateEmbed(interaction, queue);
|
2022-08-02 17:18:47 +05:00
|
|
|
|
|
2023-11-21 01:19:46 +05:00
|
|
|
|
const message = await interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
|
embeds: [embed],
|
2023-11-04 16:56:10 +05:00
|
|
|
|
components: [row1, row2],
|
2022-08-02 17:18:47 +05:00
|
|
|
|
});
|
2023-11-21 01:19:46 +05:00
|
|
|
|
|
|
|
|
|
const i = setInterval(async function () {
|
|
|
|
|
if (message && message.editable && queue.isPlaying()) {
|
|
|
|
|
const e = await updateEmbed(interaction, queue);
|
|
|
|
|
|
|
|
|
|
message.edit({
|
|
|
|
|
embeds: [e],
|
|
|
|
|
components: [row1, row2],
|
|
|
|
|
});
|
|
|
|
|
} else clearInterval(i);
|
|
|
|
|
}, 2 * 60 * 1000);
|
2022-08-02 17:18:47 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
|
* @param {import("discord-player").GuildQueue} queue
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
async function updateEmbed(interaction, queue) {
|
|
|
|
|
const progressBar = queue.node.createProgressBar(),
|
|
|
|
|
track = queue.currentTrack,
|
|
|
|
|
data = await interaction.client.guildsData.findOne({ id: interaction.guildId }),
|
2023-11-05 00:06:19 +05:00
|
|
|
|
mode = queue.repeatMode === QueueRepeatMode.AUTOPLAY ? "3" : queue.repeatMode === QueueRepeatMode.QUEUE ? "2" : queue.repeatMode === QueueRepeatMode.TRACK ? "1" : "0",
|
2023-11-04 16:56:10 +05:00
|
|
|
|
translated = {
|
2023-11-24 01:12:54 +05:00
|
|
|
|
"3": interaction.translate("music/loop:AUTOPLAY"),
|
|
|
|
|
"2": interaction.translate("music/loop:QUEUE"),
|
|
|
|
|
"1": interaction.translate("music/loop:TRACK"),
|
2023-11-04 16:56:10 +05:00
|
|
|
|
"0": interaction.translate("common:DISABLED"),
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-05 00:06:19 +05:00
|
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
|
.setAuthor({
|
|
|
|
|
name: interaction.translate("music/nowplaying:CURRENTLY_PLAYING"),
|
|
|
|
|
})
|
|
|
|
|
.setThumbnail(track.thumbnail)
|
|
|
|
|
.addFields([
|
|
|
|
|
{
|
|
|
|
|
name: interaction.translate("music/nowplaying:T_TITLE"),
|
|
|
|
|
value: `[${track.title}](${track.url})`,
|
|
|
|
|
inline: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: interaction.translate("music/nowplaying:T_AUTHOR"),
|
|
|
|
|
value: track.author || interaction.translate("common:UNKNOWN"),
|
|
|
|
|
inline: true,
|
|
|
|
|
},
|
|
|
|
|
{ name: "\u200B", value: "\u200B", inline: true },
|
|
|
|
|
{
|
|
|
|
|
name: interaction.translate("common:VIEWS"),
|
|
|
|
|
value: track.raw.live ? "Live" : new Intl.NumberFormat(interaction.client.languages.find(language => language.name === data.language).moment, { notation: "standard" }).format(track.raw.views),
|
|
|
|
|
inline: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: interaction.translate("music/queue:ADDED"),
|
|
|
|
|
value: track.requestedBy.toString(),
|
|
|
|
|
inline: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: interaction.translate("music/nowplaying:T_DURATION"),
|
|
|
|
|
value: progressBar,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "\u200b",
|
2023-11-05 00:06:19 +05:00
|
|
|
|
value: `${interaction.translate("music/nowplaying:REPEAT")}: \`${translated[mode]}\``,
|
2023-11-04 16:56:10 +05:00
|
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
.setColor(interaction.client.config.embed.color)
|
|
|
|
|
.setFooter(interaction.client.config.embed.footer)
|
|
|
|
|
.setTimestamp();
|
|
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
|
module.exports = Nowplaying;
|