mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-17 04:26:00 +00:00
update 3.0.5
This commit is contained in:
@ -35,20 +35,11 @@ module.exports = {
|
||||
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
|
||||
return lmsg.edit(client.messages.playlistAdded);
|
||||
} else {
|
||||
try {
|
||||
var video = await youtube.getVideo(url);
|
||||
} catch (error) {
|
||||
search(searchString, function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) {
|
||||
msg.channel.send(client.messages.noResults);
|
||||
} else {
|
||||
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
|
||||
search(searchString, function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
|
||||
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
@ -1,71 +0,0 @@
|
||||
const YouTube = require("simple-youtube-api");
|
||||
const he = require('he');
|
||||
|
||||
module.exports = {
|
||||
name: 'search',
|
||||
alias: 'sr',
|
||||
usage: '<search word(s)>',
|
||||
description: 'Search the top 10 queryes and choose one.',
|
||||
onlyDev: false,
|
||||
permission: 'none',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const youtube = new YouTube(client.config.api_key);
|
||||
const searchString = args.slice(1).join(" ");
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!queue) {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
|
||||
} else {
|
||||
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
}
|
||||
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
||||
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
||||
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
|
||||
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
|
||||
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
const playlist = await youtube.getPlaylist(url);
|
||||
const videos = await playlist.getVideos();
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id);
|
||||
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
|
||||
}
|
||||
let message;
|
||||
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
|
||||
return lmsg.edit(message);
|
||||
} else {
|
||||
try {
|
||||
var video = await youtube.getVideo(url);
|
||||
} catch (error) {
|
||||
try {
|
||||
var videos = await youtube.searchVideos(searchString, 10);
|
||||
let index = 0;
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(client.messages.songSelection)
|
||||
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
|
||||
.setFooter(client.messages.provideANumber)
|
||||
.setColor(client.config.embedColor)
|
||||
msg.channel.send(embed);
|
||||
try {
|
||||
var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, {
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return msg.channel.send(client.messages.cancellingVideoSelection);
|
||||
}
|
||||
const videoIndex = parseInt(response.first().content);
|
||||
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return msg.channel.send(client.messages.noResults);
|
||||
}
|
||||
}
|
||||
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
|
||||
}
|
||||
}
|
||||
};
|
51
src/commands/search.ts
Normal file
51
src/commands/search.ts
Normal file
@ -0,0 +1,51 @@
|
||||
const yts = require('yt-search');
|
||||
const he = require('he');
|
||||
|
||||
module.exports = {
|
||||
name: 'search',
|
||||
alias: 'sr',
|
||||
usage: '<search word(s)>',
|
||||
description: 'Search the top 10 queryes and choose one.',
|
||||
onlyDev: false,
|
||||
permission: 'none',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const searchString = args.slice(1).join(" ");
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!queue) {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
|
||||
} else {
|
||||
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
}
|
||||
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
||||
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
||||
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
|
||||
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
|
||||
yts(searchString, async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
|
||||
const videos = res.videos.slice(0, 10);
|
||||
let index = 0;
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(client.messages.songSelection)
|
||||
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
|
||||
.setFooter(client.messages.provideANumber)
|
||||
.setColor(client.config.embedColor)
|
||||
msg.channel.send(embed);
|
||||
try {
|
||||
var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, {
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return msg.channel.send(client.messages.cancellingVideoSelection);
|
||||
}
|
||||
const videoIndex = parseInt(response.first().content) - 1;
|
||||
return client.funcs.handleVideo(videos[videoIndex], msg, voiceChannel, client, false);
|
||||
})
|
||||
}
|
||||
};
|
@ -10,7 +10,8 @@ module.exports = {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``);
|
||||
const point = parseInt(args[1] - 1);
|
||||
let point = parseInt(args[1]);
|
||||
point = point - 1;
|
||||
if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
|
||||
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs);
|
||||
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);
|
Reference in New Issue
Block a user