2023-11-04 16:56:10 +05:00
|
|
|
const { ContextMenuCommandBuilder, ApplicationCommandType, PermissionsBitField } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class PlayContext extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-11-04 16:56:10 +05:00
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
command: new ContextMenuCommandBuilder()
|
|
|
|
.setName("Add to Queue")
|
|
|
|
.setType(ApplicationCommandType.Message)
|
|
|
|
.setDMPermission(false),
|
|
|
|
dirname: __dirname,
|
|
|
|
ownerOnly: false,
|
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-11-04 16:56:10 +05:00
|
|
|
* @param {import("discord.js").MessageContextMenuCommandInteraction} interaction
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply();
|
|
|
|
|
2023-11-20 20:14:15 +05:00
|
|
|
const links = interaction.targetMessage.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g);
|
|
|
|
if (!links) return interaction.error("music/play:NO_LINK", null, { edit: true });
|
|
|
|
|
|
|
|
const query = links[0],
|
2023-11-04 16:56:10 +05:00
|
|
|
voice = interaction.member.voice.channel;
|
|
|
|
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
|
|
|
|
|
|
|
|
const perms = voice.permissionsFor(client.user);
|
|
|
|
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.error("music/play:VOICE_CHANNEL_CONNECT", null, { edit: true });
|
|
|
|
|
|
|
|
const searchResult = await client.player.search(query, {
|
|
|
|
requestedBy: interaction.user,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!searchResult.hasTracks()) return interaction.error("music/play:NO_RESULT", { query }, { edit: true });
|
|
|
|
else {
|
|
|
|
const { queue } = await client.player.play(interaction.member.voice.channel, searchResult, {
|
|
|
|
nodeOptions: {
|
2024-02-02 20:49:55 +05:00
|
|
|
metadata: interaction,
|
2023-11-04 16:56:10 +05:00
|
|
|
},
|
|
|
|
selfDeaf: true,
|
|
|
|
leaveOnEnd: false,
|
|
|
|
leaveOnStop: true,
|
|
|
|
skipOnNoStream: true,
|
|
|
|
maxSize: 200,
|
|
|
|
maxHistorySize: 50,
|
|
|
|
});
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
if (client.player.nodes.get(interaction.guildId).currentTrack.url === query && query.match(/&t=[[0-9]+/g) !== null) {
|
|
|
|
const time = query.match(/&t=[[0-9]+/g)[0].split("=")[1];
|
|
|
|
|
|
|
|
queue.node.seek(time * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PlayContext;
|