Huge sound player overhaul using Lavalink, added boom, removed prunejuice, boat, and bus, re-encoded audio files with ffmpeg

This commit is contained in:
TheEssem 2020-06-27 12:18:26 -05:00
parent 56faea8d59
commit 0cc80da8b6
41 changed files with 107 additions and 56 deletions

View file

@ -1,27 +1,47 @@
const client = require("./client.js");
const logger = require("./logger.js");
const fetch = require("node-fetch");
const { Manager } = require("@lavacord/eris");
module.exports = async (sound, message) => {
const nodes = [
{ id: "1", host: "localhost", port: 2333, password: process.env.LAVAPASS }
];
let manager;
exports.connect = async () => {
manager = new Manager(client, nodes, {
user: client.user.id
});
const { length } = await manager.connect();
logger.log(`Successfully connected to ${length} Lavalink node(s).`);
manager.on("error", (error, node) => {
logger.error(`An error occurred on Lavalink node ${node}: ${error}`);
});
};
exports.play = async (sound, message) => {
if (message.member.voiceState.channelID) {
if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I can't join this voice channel!`);
const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID);
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I don't have permission to join this voice channel!`);
const connection = await voiceChannel.join({
opusOnly: true
const node = manager.idealNodes[0];
const { tracks } = await fetch(`http://${node.host}:${node.port}/loadtracks?identifier=${sound}`, { headers: { Authorization: node.password } }).then(res => res.json());
const connection = await manager.join({
guild: voiceChannel.guild.id,
channel: voiceChannel.id,
node: node.id
});
if (connection.playing) return client.createMessage(message.channel.id, `${message.author.mention}, I'm already playing a sound!`);
const playingMessage = await client.createMessage(message.channel.id, "🔊 Playing sound...");
if (connection.playing) {
connection.stopPlaying();
}
connection.play(sound);
await connection.play(tracks[0].track);
connection.on("error", (error) => {
voiceChannel.leave();
manager.leave(voiceChannel.guild.id);
playingMessage.delete();
logger.error(error);
});
connection.once("end", () => {
voiceChannel.leave();
connection.once("end", (data) => {
if (data.reason === "REPLACED") return;
manager.leave(voiceChannel.guild.id);
playingMessage.delete();
});
} else {