1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-13 02:20:18 +00:00
musix-oss/struct/funcs/play.js

35 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-02-05 20:02:53 +00:00
module.exports = async function (guild, song, client, seek, play) {
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
2020-03-15 19:52:36 +00:00
const streamConfig = require("../config/streamConfig.js");
2020-02-05 20:02:53 +00:00
const getThumb = require('video-thumbnail-url');
2020-03-14 16:38:02 +00:00
const queue = client.queue.get(guild.id);
2020-02-05 20:02:53 +00:00
if (!song) {
2020-03-14 16:38:02 +00:00
queue.voiceChannel.leave();
2020-02-05 20:02:53 +00:00
client.queue.delete(guild.id);
return;
}
2020-03-14 16:38:02 +00:00
const dispatcher = queue.connection
2020-03-15 19:52:36 +00:00
.play(await ytdl(song.url, streamConfig.ytdlOptions), streamConfig.options).on("finish", () => {
2020-03-14 16:38:02 +00:00
client.dispatcher.finish(client, queue.endReason, guild);
2020-03-15 19:52:36 +00:00
}).on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
}).on('error', error => {
client.dispatcher.error(client, error, guild);
2020-02-05 20:02:53 +00:00
});
2020-03-14 16:38:02 +00:00
dispatcher.setVolume(queue.volume / 10);
2020-02-05 20:02:53 +00:00
if (client.global.db.guilds[guild.id].startPlaying || play) {
2020-03-14 16:38:02 +00:00
const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
2020-02-05 20:02:53 +00:00
const songtime = (data.length_seconds * 1000).toFixed(0);
2020-03-14 16:38:02 +00:00
const thumbnail = getThumb(queue.songs[0].url);
2020-02-05 20:02:53 +00:00
const embed = new Discord.MessageEmbed()
2020-03-12 11:56:31 +00:00
.setTitle(`${client.messages.startPlaying}**${song.title}**`)
2020-02-10 19:07:09 +00:00
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
2020-02-05 20:02:53 +00:00
.setThumbnail(thumbnail._rejectionHandler0)
2020-02-05 20:26:18 +00:00
.setColor(client.config.embedColor)
2020-03-14 16:38:02 +00:00
queue.textChannel.send(embed);
2020-02-05 20:02:53 +00:00
}
2020-03-14 16:38:02 +00:00
queue.playing = true;
2020-02-05 20:02:53 +00:00
}