mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 15:46:00 +00:00
big update
This commit is contained in:
22
Struct/funcs/dbget.js
Normal file
22
Struct/funcs/dbget.js
Normal 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;
|
||||
}
|
||||
};
|
16
Struct/funcs/exe.js
Normal file
16
Struct/funcs/exe.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = function (message, args, client, Discord, prefix, command) {
|
||||
const permissions = message.channel.permissionsFor(message.client.user);
|
||||
if (!permissions.has('EMBED_LINKS')) return message.channel.send(':x: I cannot send embeds (Embed links), make sure I have the proper permissions!');
|
||||
try {
|
||||
command.uses++;
|
||||
command.execute(message, args, client, Discord, prefix);
|
||||
} catch (error) {
|
||||
message.reply(`:x: there was an error trying to execute that command! Please contact support with \`${prefix}bug\`!`);
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`Musix ${error.toString()}`)
|
||||
.setDescription(error.stack.replace(/at /g, '**at **'))
|
||||
.setColor('#b50002');
|
||||
client.fetchUser(client.config.devId).then(user => user.send(embed)).catch(console.error);
|
||||
client.channels.get(client.config.debug_channel).send(embed);
|
||||
}
|
||||
};
|
48
Struct/funcs/handleVideo.js
Normal file
48
Struct/funcs/handleVideo.js
Normal file
@ -0,0 +1,48 @@
|
||||
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}`,
|
||||
author: message.author
|
||||
}
|
||||
const serverQueue = client.queue.get(message.guild.id);
|
||||
if (client.global.db.guilds[message.guild.id].defaultVolume === undefined) {
|
||||
client.global.db.guilds[message.guild.id] = {
|
||||
prefix: client.global.db.guilds[message.guild.id].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: client.global.db.guilds[message.guild.id].defaultVolume,
|
||||
playing: false,
|
||||
paused: false,
|
||||
looping: false,
|
||||
votes: 0,
|
||||
voters: [],
|
||||
votesNeeded: null
|
||||
};
|
||||
construct.songs.push(song);
|
||||
client.queue.set(message.guild.id, construct);
|
||||
try {
|
||||
var connection = await voiceChannel.join();
|
||||
construct.connection = connection;
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0, true);
|
||||
} catch (error) {
|
||||
client.queue.delete(message.guild.id);
|
||||
client.channels.get(client.config.debug_channel).send("Error with connecting to voice channel: " + error);
|
||||
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;
|
||||
}
|
11
Struct/funcs/msToTime.js
Normal file
11
Struct/funcs/msToTime.js
Normal 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}`;
|
||||
}
|
40
Struct/funcs/play.js
Normal file
40
Struct/funcs/play.js
Normal file
@ -0,0 +1,40 @@
|
||||
module.exports = async function (guild, song, client, message, seek, play) {
|
||||
const Discord = require('discord.js');
|
||||
const ytdl = require('ytdl-core');
|
||||
const serverQueue = client.queue.get(guild.id);
|
||||
if (!song) {
|
||||
console.log('No song')
|
||||
serverQueue.voiceChannel.leave();
|
||||
client.queue.delete(guild.id);
|
||||
return;
|
||||
}
|
||||
const dispatcher = serverQueue.connection
|
||||
.playStream(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 })
|
||||
.on("end", reason => {
|
||||
if (reason === "Stream is not generating quickly enough.") {
|
||||
console.log("Song ended");
|
||||
} else if (reason === "seek") {
|
||||
return;
|
||||
} else {
|
||||
console.log(reason);
|
||||
}
|
||||
serverQueue.playing = false;
|
||||
if (serverQueue.looping) {
|
||||
serverQueue.songs.push(serverQueue.songs[0]);
|
||||
}
|
||||
serverQueue.songs.shift();
|
||||
client.funcs.play(guild, serverQueue.songs[0], client, message);
|
||||
});
|
||||
dispatcher.setVolume(serverQueue.volume / 10);
|
||||
dispatcher.on("error", error => console.error(error));
|
||||
if (client.global.db.guilds[guild.id].startPlaying || play) {
|
||||
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: \`${client.funcs.msToTime(songtime)}\``)
|
||||
.setColor("#b50002")
|
||||
serverQueue.textChannel.send(embed);
|
||||
}
|
||||
serverQueue.playing = true;
|
||||
}
|
Reference in New Issue
Block a user