1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-16 18:56:00 +00:00
This commit is contained in:
MatteZ02
2019-10-10 16:43:04 +03:00
parent 6f6ac8a6fa
commit 50b9bed483
9432 changed files with 1988816 additions and 167 deletions

22
funcs/dbget.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = async function (collection, doc, client) {
if (doc) {
let d = await client.db.collection(collection).doc(doc).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
return d.data();
} else {
let d = await client.db.collection(collection).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
let finalD = [];
d.forEach(doc => {
finalD.push({
id: doc.id,
d: doc.data(),
});
});
return finalD;
}
};

View File

@ -6,35 +6,38 @@ module.exports = async function (video, message, voiceChannel, client, playlist
url: `https://www.youtube.com/watch?v=${video.id}`
}
const serverQueue = client.queue.get(message.guild.id);
if (!serverQueue || restartmusic === true) {
const queueConstruct = {
if (client.global.db.musix_guilds[message.guild.id].defaultVolume === undefined) {
client.global.db.musix_guilds[message.guild.id] = {
musix_prefix: client.global.db.musix_guilds[message.guild.id].musix_prefix,
defaultVolume: 5,
};
return message.channel.send(':x: `Error:` the default volume is undefined for this server. Please try again after a while.');
}
if (!serverQueue) {
const construct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 1,
playing: true
volume: client.global.db.musix_guilds[message.guild.id].defaultVolume,
playing: true,
looping: false
};
queueConstruct.songs.push(song);
client.queue.set(message.guild.id, queueConstruct);
construct.songs.push(song);
client.queue.set(message.guild.id, construct);
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();
}
}
construct.connection = connection;
client.funcs.play(message.guild, construct.songs[0], client, message, 0);
} catch (error) {
client.queue.delete(message.guild.id);
return message.channel.send(`:x: An error occured: ${error}`);
}
} else {
serverQueue.songs.push(song);
if (serverQueue.looping) {
client.secondaryQueue.push(song);
}
if (playlist) return undefined;
return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);
}

11
funcs/msToTime.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = function msToTime(duration) {
var seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return `${hours}:${minutes}:${seconds}`;
}

View File

@ -1,29 +1,35 @@
module.exports = async function (guild, song, client) {
module.exports = async function (guild, song, client, message, seek) {
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 })
.playStream(ytdl(song.url, { quality: `highestaudio`, filter: "audioonly" }), { seek: seek })
.on("end", reason => {
if (reason === "Stream is not generating quickly enough.")
if (reason === "Stream is not generating quickly enough.") {
console.log("Song ended");
else console.log(reason);
} else if (reason === "seek") {
return;
} else {
console.log(reason);
}
serverQueue.songs.shift();
client.funcs.play(guild, serverQueue.songs[0], client);
if (serverQueue.looping && serverQueue.songs.length === 0) {
serverQueue.songs = [...client.secondaryQueue];
}
client.funcs.play(guild, serverQueue.songs[0], client, message);
});
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
dispatcher.setVolume(serverQueue.volume / 10);
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))
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
let songtime = (data.length_seconds * 1000).toFixed(0);
const embed = new Discord.RichEmbed()
.setTitle(`:musical_note: Start playing: **${song.title}**`)
.setDescription(`Song duration: \`${totallength}\``)
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
.setColor("#b50002")
serverQueue.textChannel.send(embed);
}
}

View File

@ -1,6 +0,0 @@
module.exports = async function (newPrefix, guildId) {
await client.db.collection('guilds').doc(guildId).set({
prefix: newPrefix,
}, { merge: true });
return 'success';
}