mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-15 17:45:59 +00:00
Fix code to work on this decade 1/x
This commit is contained in:
22
funcs/dbget.js
Normal file
22
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;
|
||||
}
|
||||
};
|
13
funcs/exe.js
Normal file
13
funcs/exe.js
Normal file
@ -0,0 +1,13 @@
|
||||
const { EmbedBuilder, PermissionFlagsBits } = require("discord.js");
|
||||
|
||||
module.exports = function (message, args, client, prefix, command) {
|
||||
const permissions = message.channel.permissionsFor(message.client.user);
|
||||
if (!permissions.has(PermissionFlagsBits.EmbedLinks)) 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, prefix);
|
||||
} catch (error) {
|
||||
message.reply(`:x: there was an error trying to execute that command!`);
|
||||
console.log(error);
|
||||
}
|
||||
};
|
53
funcs/handleVideo.js
Normal file
53
funcs/handleVideo.js
Normal file
@ -0,0 +1,53 @@
|
||||
const { createAudioPlayer, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require("@discordjs/voice");
|
||||
|
||||
module.exports = async function (video, message, voiceChannel, client, playlist = false) {
|
||||
let song = {
|
||||
id: video.id,
|
||||
title: video.title,
|
||||
url: `https://www.youtube.com/watch?v=${video.id}`,
|
||||
author: message.author
|
||||
}
|
||||
const serverQueue = client.queue.get(message.guild.id);
|
||||
if (!serverQueue) {
|
||||
const construct = {
|
||||
textChannel: message.channel,
|
||||
voiceChannel: voiceChannel,
|
||||
connection: null,
|
||||
audioPlayer: createAudioPlayer({
|
||||
behaviors: {
|
||||
noSubscriber: NoSubscriberBehavior.Play,
|
||||
}
|
||||
}),
|
||||
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 {
|
||||
const connection =
|
||||
getVoiceConnection(voiceChannel.guild.id) ??
|
||||
joinVoiceChannel({
|
||||
channelId: voiceChannel.id,
|
||||
guildId: voiceChannel.guild.id,
|
||||
adapterCreator: voiceChannel.guild.voiceAdapterCreator
|
||||
});
|
||||
construct.connection = connection;
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0, true);
|
||||
} catch (error) {
|
||||
client.queue.delete(message.guild.id);
|
||||
console.log("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
funcs/msToTime.js
Normal file
11
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}`;
|
||||
}
|
48
funcs/play.js
Normal file
48
funcs/play.js
Normal file
@ -0,0 +1,48 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { AudioPlayerStatus, createAudioResource } = require('@discordjs/voice');
|
||||
const ytdl = require('ytdl-core');
|
||||
|
||||
module.exports = async function (guild, song, client, message, seek, play) {
|
||||
const serverQueue = client.queue.get(guild.id);
|
||||
if (!song) {
|
||||
serverQueue.connection.destroy();
|
||||
client.queue.delete(guild.id);
|
||||
return;
|
||||
}
|
||||
|
||||
serverQueue.audioPlayer
|
||||
.on(AudioPlayerStatus.Idle, () => {
|
||||
serverQueue.playing = false;
|
||||
serverQueue.audioPlayer.removeAllListeners();
|
||||
if (serverQueue.looping) {
|
||||
serverQueue.songs.push(serverQueue.songs[0]);
|
||||
}
|
||||
serverQueue.songs.shift();
|
||||
client.funcs.play(guild, serverQueue.songs[0], client, message);
|
||||
})
|
||||
.on('error', (error) => {
|
||||
console.error(error)
|
||||
});
|
||||
|
||||
const audioResource = createAudioResource(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }),{
|
||||
inlineVolume: true
|
||||
});
|
||||
|
||||
audioResource.volume.setVolume(serverQueue.volume / 100);
|
||||
|
||||
serverQueue.audioPlayer.play(audioResource);
|
||||
serverQueue.audioResource = audioResource;
|
||||
serverQueue.connection.subscribe(serverQueue.audioPlayer);
|
||||
|
||||
/*.playStream(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 })*/
|
||||
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 EmbedBuilder()
|
||||
.setTitle(`:musical_note: Start playing: **${song.title}**`)
|
||||
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
|
||||
.setColor("#b50002")
|
||||
serverQueue.textChannel.send({ embeds: [embed] });
|
||||
}
|
||||
serverQueue.playing = true;
|
||||
}
|
Reference in New Issue
Block a user