1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 06:43:17 +00:00
musix-oss/src/struct/funcs/handleVideo.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-04 05:26:33 +00:00
const Discord = require("discord.js");
const ytdl = require("ytdl-core");
2020-04-13 10:57:39 +00:00
module.exports = async function (
2020-04-19 17:00:16 +00:00
resource,
2020-04-13 10:57:39 +00:00
msg,
voiceChannel,
client,
2020-04-19 17:00:16 +00:00
playlist,
2020-06-30 17:43:00 +00:00
type,
spotifyTrackData
2020-04-13 10:57:39 +00:00
) {
2020-06-17 13:38:43 +00:00
const songInfo = await ytdl.getInfo(resource).catch(err => console.log(err));
2020-04-13 10:57:39 +00:00
const song = {
2020-06-04 10:11:14 +00:00
title: Discord.Util.escapeMarkdown(songInfo.videoDetails.title),
2020-06-17 13:38:43 +00:00
url: resource,
2020-04-13 10:57:39 +00:00
author: msg.author,
2020-04-19 17:00:16 +00:00
type: type,
2020-06-30 17:43:00 +00:00
info: songInfo.videoDetails,
track: spotifyTrackData
2020-04-13 10:57:39 +00:00
};
2020-03-03 20:24:41 +00:00
2020-04-13 10:57:39 +00:00
const queue = client.queue.get(msg.guild.id);
2020-03-03 20:24:41 +00:00
2020-04-13 10:57:39 +00:00
if (queue) {
queue.songs.push(song);
2020-04-14 09:54:53 +00:00
queue.textChannel = msg.channel;
2020-04-13 10:57:39 +00:00
if (playlist) return;
let message;
message = client.messages.songAdded.replace("%TITLE%", song.title);
return msg.channel.send(message);
}
2020-02-05 20:02:53 +00:00
2020-04-13 11:30:20 +00:00
const construct = {
2020-04-19 17:00:16 +00:00
textChannel: msg.channel,
voiceChannel: voiceChannel,
2020-04-13 11:30:20 +00:00
connection: null,
songs: [],
2020-04-29 11:41:16 +00:00
prevSongs: [],
2020-04-19 17:00:16 +00:00
volume: client.global.db.guilds[msg.guild.id].defaultVolume,
bass: client.global.db.guilds[msg.guild.id].bass,
2020-07-18 19:33:09 +00:00
nightCore: false,
2020-04-13 11:30:20 +00:00
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
endReason: null,
2020-06-04 14:46:43 +00:00
exists: true
2020-04-13 11:30:20 +00:00
};
2020-03-04 20:27:14 +00:00
2020-04-13 10:57:39 +00:00
construct.songs.push(song);
2020-03-04 20:27:14 +00:00
2020-04-13 10:57:39 +00:00
client.queue.set(msg.guild.id, construct);
2020-02-05 20:02:53 +00:00
2020-04-13 10:57:39 +00:00
try {
const connection = await voiceChannel.join();
construct.connection = connection;
require("../../events/connectionEvents/handler")(client, connection);
2020-04-13 10:57:39 +00:00
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
console.log(error);
2020-06-08 10:41:49 +00:00
return msg.channel.send(client.messages.error + error);
2020-04-13 10:57:39 +00:00
}
return;
};