mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 18:56:00 +00:00
Updated everything
This commit is contained in:
42
funcs/handleVideo.js
Normal file
42
funcs/handleVideo.js
Normal file
@ -0,0 +1,42 @@
|
||||
module.exports = async function (video, message, voiceChannel, client, playlist = false) {
|
||||
const Discord = require('discord.js');
|
||||
let song = {
|
||||
id: video.id,
|
||||
title: Discord.Util.escapeMarkdown(video.title),
|
||||
url: `https://www.youtube.com/watch?v=${video.id}`
|
||||
}
|
||||
const serverQueue = client.queue.get(message.guild.id);
|
||||
if (!serverQueue || restartmusic === true) {
|
||||
const queueConstruct = {
|
||||
textChannel: message.channel,
|
||||
voiceChannel: voiceChannel,
|
||||
connection: null,
|
||||
songs: [],
|
||||
volume: 1,
|
||||
playing: true
|
||||
};
|
||||
queueConstruct.songs.push(song);
|
||||
client.queue.set(message.guild.id, queueConstruct);
|
||||
try {
|
||||
var connection = await voiceChannel.join();
|
||||
queueConstruct.connection = connection;
|
||||
client.funcs.play(message.guild, queueConstruct.songs[0], client);
|
||||
if (restartmusic === true) {
|
||||
const serverQueue = client.queue.get(message.guild.id);
|
||||
song = client.config.songs[0];
|
||||
for (var i = 0; i < client.config.songs.length; i++) {
|
||||
serverQueue.songs.push(client.config.songs[1]);
|
||||
client.config.songs.shift();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
client.queue.delete(message.guild.id);
|
||||
return message.channel.send(`:x: An error occured: ${error}`);
|
||||
}
|
||||
} else {
|
||||
serverQueue.songs.push(song);
|
||||
if (playlist) return undefined;
|
||||
return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
29
funcs/play.js
Normal file
29
funcs/play.js
Normal file
@ -0,0 +1,29 @@
|
||||
module.exports = async function (guild, song, client) {
|
||||
const Discord = require('discord.js');
|
||||
const ytdl = require('ytdl-core');
|
||||
const serverQueue = client.queue.get(guild.id);
|
||||
if (!song) {
|
||||
serverQueue.textChannel.send(':stop_button: Music ended!');
|
||||
serverQueue.voiceChannel.leave();
|
||||
client.queue.delete(guild.id);
|
||||
return;
|
||||
}
|
||||
const dispatcher = serverQueue.connection
|
||||
.playStream(ytdl(song.url, { quality: `highestaudio`, filter: "audioonly" }), { seek: 0 })
|
||||
.on("end", reason => {
|
||||
if (reason === "Stream is not generating quickly enough.")
|
||||
console.log("Song ended");
|
||||
else console.log(reason);
|
||||
serverQueue.songs.shift();
|
||||
client.funcs.play(guild, serverQueue.songs[0], client);
|
||||
});
|
||||
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
|
||||
dispatcher.on("error", error => console.error(error));
|
||||
const data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
|
||||
const totallength = Math.floor(data.length_seconds / 60) + ':' + (data.length_seconds - (Math.floor(data.length_seconds / 60) * 60))
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`:musical_note: Start playing: **${song.title}**`)
|
||||
.setDescription(`Song duration: \`${totallength}\``)
|
||||
.setColor("#b50002")
|
||||
serverQueue.textChannel.send(embed);
|
||||
}
|
6
funcs/setPrefix.js
Normal file
6
funcs/setPrefix.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = async function (newPrefix, guildId) {
|
||||
await client.db.collection('guilds').doc(guildId).set({
|
||||
prefix: newPrefix,
|
||||
}, { merge: true });
|
||||
return 'success';
|
||||
}
|
Reference in New Issue
Block a user