2019-10-31 18:29:26 +00:00
|
|
|
const YouTube = require("simple-youtube-api");
|
|
|
|
const he = require('he');
|
2024-02-09 09:53:30 +00:00
|
|
|
const { EmbedBuilder } = require("discord.js");
|
2019-10-31 18:29:26 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'add',
|
2024-02-09 09:53:30 +00:00
|
|
|
async execute(message, args, client, prefix) {
|
2019-10-31 18:29:26 +00:00
|
|
|
if (client.global.db.playlists[message.guild.id].saved) {
|
|
|
|
const serverQueue = client.queue.get(message.guild.id);
|
2024-02-09 09:53:30 +00:00
|
|
|
const youtube = new YouTube(client.config.youtube_api_key);
|
2019-10-31 18:29:26 +00:00
|
|
|
const searchString = args.slice(2).join(" ");
|
|
|
|
const url = args[2] ? args[2].replace(/<(.+)>/g, "$1") : "";
|
|
|
|
if (!args[2]) return message.channel.send(':x: You need to use a link or search for a song!');
|
|
|
|
try {
|
|
|
|
var video = await youtube.getVideo(url);
|
|
|
|
} catch (error) {
|
|
|
|
try {
|
|
|
|
var videos = await youtube.searchVideos(searchString, 10);
|
|
|
|
let index = 0;
|
2024-02-09 09:53:30 +00:00
|
|
|
const embed = new EmbedBuilder()
|
2019-10-31 18:29:26 +00:00
|
|
|
.setTitle("__Song Selection__")
|
|
|
|
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
|
2024-02-09 09:53:30 +00:00
|
|
|
.setFooter({ text: "Please provide a number ranging from 1-10 to select one of the search results." })
|
2019-10-31 18:29:26 +00:00
|
|
|
.setColor("#b50002")
|
2024-02-09 09:53:30 +00:00
|
|
|
message.channel.send({ embeds: [embed] });
|
2019-10-31 18:29:26 +00:00
|
|
|
try {
|
2024-02-09 09:53:30 +00:00
|
|
|
var response = await message.channel.awaitMessages({
|
|
|
|
filter: message2 => message2.content > 0 && message2.content < 11,
|
|
|
|
max: 1,
|
2019-10-31 18:29:26 +00:00
|
|
|
time: 10000,
|
|
|
|
errors: ['time']
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
return message.channel.send(':x: Cancelling video selection');
|
|
|
|
}
|
|
|
|
const videoIndex = parseInt(response.first().content);
|
|
|
|
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
return message.channel.send(':x: I could not obtain any search results!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let song = {
|
|
|
|
id: video.id,
|
2024-02-09 09:53:30 +00:00
|
|
|
title: video.title,
|
2019-10-31 18:29:26 +00:00
|
|
|
url: `https://www.youtube.com/watch?v=${video.id}`
|
|
|
|
}
|
|
|
|
client.global.db.playlists[message.guild.id].songs.push(song);
|
|
|
|
message.channel.send(`:white_check_mark: ${song.title} added to the playlist!`);
|
|
|
|
} else return message.channel.send(':x: There is no playlist saved! Start by using the save option!');
|
|
|
|
}
|
2024-02-09 09:53:30 +00:00
|
|
|
};
|