mirror of
https://github.com/musix-org/musix-oss
synced 2024-11-10 05:10:17 +00:00
Added commands to playlist
This commit is contained in:
parent
55c3ff293b
commit
f2d105d5e2
@ -1,3 +1,6 @@
|
|||||||
|
const YouTube = require("simple-youtube-api");
|
||||||
|
const he = require('he');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'playlist',
|
name: 'playlist',
|
||||||
usage: '[option]',
|
usage: '[option]',
|
||||||
@ -14,14 +17,29 @@ module.exports = {
|
|||||||
if (client.global.db.guilds[message.guild.id].premium) {
|
if (client.global.db.guilds[message.guild.id].premium) {
|
||||||
if (args[1] === 'play') {
|
if (args[1] === 'play') {
|
||||||
const voiceChannel = message.member.voiceChannel;
|
const voiceChannel = message.member.voiceChannel;
|
||||||
|
const permissions = voiceChannel.permissionsFor(message.client.user);
|
||||||
|
if (!permissions.has('CONNECT')) {
|
||||||
|
return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
|
||||||
|
}
|
||||||
|
if (!permissions.has('SPEAK')) {
|
||||||
|
return message.channel.send(':x: I cannot speak in your voice channel, make sure I have the proper permissions!');
|
||||||
|
}
|
||||||
|
let songs;
|
||||||
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
|
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
|
||||||
|
if (args[2]) {
|
||||||
|
if (client.global.db.guilds[args[2]].premium && client.global.db.playlists[args[2]].saved) {
|
||||||
|
songs = client.global.db.playlists[args[2]].songs;
|
||||||
|
} else return message.channel.send(':x: There is no queue saved for this guild!')
|
||||||
|
} else {
|
||||||
|
songs = client.global.db.playlists[message.guild.id].songs;
|
||||||
|
}
|
||||||
if (client.global.db.playlists[message.guild.id].saved) {
|
if (client.global.db.playlists[message.guild.id].saved) {
|
||||||
if (!serverQueue) {
|
if (!serverQueue) {
|
||||||
const construct = {
|
const construct = {
|
||||||
textChannel: message.channel,
|
textChannel: message.channel,
|
||||||
voiceChannel: message.member.voiceChannel,
|
voiceChannel: message.member.voiceChannel,
|
||||||
connection: null,
|
connection: null,
|
||||||
songs: [...client.global.db.playlists[message.guild.id].songs],
|
songs: [...songs],
|
||||||
volume: client.global.db.guilds[message.guild.id].defaultVolume,
|
volume: client.global.db.guilds[message.guild.id].defaultVolume,
|
||||||
playing: true,
|
playing: true,
|
||||||
looping: false
|
looping: false
|
||||||
@ -50,12 +68,54 @@ module.exports = {
|
|||||||
saved: true,
|
saved: true,
|
||||||
};
|
};
|
||||||
message.channel.send(":white_check_mark: Queue saved!");
|
message.channel.send(":white_check_mark: Queue saved!");
|
||||||
|
} else if (args[1] === 'add') {
|
||||||
|
const youtube = new YouTube(client.config.apikey);
|
||||||
|
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;
|
||||||
|
const embed = new Discord.RichEmbed()
|
||||||
|
.setTitle("__Song Selection__")
|
||||||
|
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
|
||||||
|
.setFooter("Please provide a number ranging from 1-10 to select one of the search results.")
|
||||||
|
.setColor("#b50002")
|
||||||
|
message.channel.send(embed);
|
||||||
|
try {
|
||||||
|
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
|
||||||
|
maxMatches: 1,
|
||||||
|
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,
|
||||||
|
title: Discord.Util.escapeMarkdown(video.title),
|
||||||
|
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 {
|
} else {
|
||||||
const embed = new Discord.RichEmbed()
|
const embed = new Discord.RichEmbed()
|
||||||
.setTitle('Options for playlist!')
|
.setTitle('Options for playlist!')
|
||||||
.addField('play', 'Play the guild specific queue.', true)
|
.addField('play', 'Play the guild specific queue.', true)
|
||||||
.addField('save', 'Save the currently playing queue.', true)
|
.addField('save', 'Save the currently playing queue.', true)
|
||||||
.setFooter(`how to use: ${prefix}playlist <Option>`)
|
.addField('add', 'Add songs to the playlist. Like song selection', true)
|
||||||
|
.setFooter(`how to use: ${prefix}playlist <Option> <Optional option>`)
|
||||||
.setAuthor(client.user.username, client.user.displayAvatarURL)
|
.setAuthor(client.user.username, client.user.displayAvatarURL)
|
||||||
.setColor('#b50002')
|
.setColor('#b50002')
|
||||||
return message.channel.send(embed);
|
return message.channel.send(embed);
|
||||||
|
@ -24,7 +24,7 @@ module.exports = {
|
|||||||
djrole: null
|
djrole: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let prefix = client.global.db.guilds[message.guild.id].prefix;
|
let prefix = "-"//client.global.db.guilds[message.guild.id].prefix;
|
||||||
const args = message.content.slice(prefix.length).split(' ');
|
const args = message.content.slice(prefix.length).split(' ');
|
||||||
if (message.mentions.users.first()) {
|
if (message.mentions.users.first()) {
|
||||||
if (message.mentions.users.first().id === '607266889537945605' && args[1] === 'help') return client.commands.get('help').execute(message, args, client, Discord, prefix, client);
|
if (message.mentions.users.first().id === '607266889537945605' && args[1] === 'help') return client.commands.get('help').execute(message, args, client, Discord, prefix, client);
|
||||||
|
2
index.js
2
index.js
@ -34,7 +34,7 @@ client.funcs.msToTime = require('./funcs/msToTime.js');
|
|||||||
client.funcs.dbget = require('./funcs/dbget.js');
|
client.funcs.dbget = require('./funcs/dbget.js');
|
||||||
|
|
||||||
client.config = {
|
client.config = {
|
||||||
token: process.env.TOKEN,
|
token: process.env.TESTTOKEN,
|
||||||
apikey: process.env.API_KEY,
|
apikey: process.env.API_KEY,
|
||||||
prefix: '>',
|
prefix: '>',
|
||||||
test: 'success',
|
test: 'success',
|
||||||
|
Loading…
Reference in New Issue
Block a user