1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-07-07 13:50:49 +00:00

Chore update 3.7

This commit is contained in:
MatteZ02
2020-06-30 20:43:00 +03:00
parent 0e25ac5752
commit 2353262322
18 changed files with 384 additions and 129 deletions

View File

@ -1,3 +1,7 @@
const similarSongs = require("similar-songs");
const ytdl = require("ytdl-core");
const Discord = require("discord.js");
module.exports = {
async execute(client, guild) {
const queue = client.queue.get(guild.id);
@ -17,8 +21,50 @@ module.exports = {
if (queue.endReason !== "replay") {
if (queue.endReason === "previous") queue.songs.unshift(queue.prevSongs.pop())
if (queue.endReason !== "previous") queue.prevSongs.push(queue.songs.shift());
if (client.global.db.guilds[guild.id].playSimilar && !queue.songs[0] && queue.endReason !== "stop") {
const prevSongs = queue.prevSongs.filter(song => song.type == "spotify");
if (prevSongs.length >= 0) return findSimilar(client, queue, prevSongs, guild);
}
}
}
client.funcs.play(guild, queue.songs[0], client, 0, true);
},
};
};
function findSimilar(client, queue, prevSongs, guild) {
let retries = 0;
const query = prevSongs[Math.floor(Math.random() * Math.floor(prevSongs.length))];
if (!query) return client.funcs.play(guild, queue.songs[0], client, 0, true);
similarSongs.find({
title: query.track.name,
artist: query.track.artists[0].name,
limit: 10,
lastfmAPIKey: client.config.lastfm_api_key,
lastfmAPISecret: client.config.lastfm_secret,
youtubeAPIKey: client.config.api_key,
},
async function (err, songs) {
if (err) return queue.textChannel.send(err.message);
if (songs[0]) {
const random = Math.floor(Math.random() * Math.floor(songs.length))
const songInfo = await ytdl.getInfo(`https://www.youtube.com/watch?v=${songs[random].youtubeId}`);
queue.songs.push({
title: Discord.Util.escapeMarkdown(songInfo.videoDetails.title),
url: `https://www.youtube.com/watch?v=${songs[random].youtubeId}`,
author: {},
type: "ytdl",
info: songInfo.videoDetails
});
client.funcs.play(guild, queue.songs[0], client, 0, true);
} else {
if (prevSongs.length > 4 && retries < 6) {
findSimilar(client, queue, prevSongs, guild);
retries++;
return;
}
queue.textChannel.send(client.messages.noSimilarResults);
client.funcs.play(guild, queue.songs[0], client, 0, true);
}
}
);
}